#include "IOSTM8S103F3.h" void lightup(); void delay(int count); void main() { //PC5 as LED source in push-pull mode PC_ODR = 0; PC_DDR_DDR5 = 1; PC_CR1_C15 = 1; PD_CR2_C25 = 1; //PD5 as switch in pull-up mode PD_DDR_DDR5 = 0; PD_CR1_C15 = 1; PD_CR2_C25 = 0; while (1) { lightup(); } } void lightup(void) { PC_ODR_bit.ODR5 = !PD_IDR_bit.IDR5; //PC5 reads if Switch PD5 is pressed if(PC_ODR_bit.ODR5==1){ //When Switch PD5 is pressed, LED lights up delay(50); //Keep LED on for a short period of time //Turn off the LED permanently. Even if Switch PD5 is pressed again, LED does NOT light up PC_ODR = 0; PC_DDR_DDR5 = 0; PC_CR1_C15 = 0; PD_CR2_C25 = 0; } } void delay(int count) { volatile int i,j; for (i=0; i