// This pgm just blinks D.2 for testing the protoboard. #include #include #include //timeout values for each task #define t1 250 #define begin { #define end } // task subroutines void task1(void); //blink at 2 or 8 Hz void initialize(void); //all the usual mcu stuff volatile unsigned char time1; //timeout counter unsigned char led; //light states //********************************************************** //timer 0 compare ISR ISR (TIMER0_COMP_vect) begin //Decrement the time if they are not already zero if (time1>0) --time1; end //********************************************************** //Entry point and task scheduler loop int main(void) begin initialize(); //main task scheduler loop while(1) begin if (time1==0){time1=t1; task1();} end end //********************************************************** //Task 1 void task1(void) begin //toggle the second bit led = led ^ 0b00000100; PORTD = led; end //********************************************************** //Set it all up void initialize(void) begin //set up the ports DDRD=0b00000100; // PORT D.2 is an ouput //set up timer 0 TIMSK=2; //turn on timer 0 cmp match ISR OCR0 = 249; //set the compare re to 250 time ticks //prescalar to 64 and turn on clear-on-match TCCR0=0b00001011; //init the LED status (all off) led=0xff; //init the task timer time1=t1; //crank up the ISRs sei(); end