Motor Test Code: #include #include #include #include //#define prescale0 3 #define begin { #define end } #define t0 20 void initialize(void); unsigned int time0; unsigned char step; //********************************************************** //timer 0 compare ISR interrupt [TIM0_COMP] void timer0_compare(void) begin //Decrement the three times if they are not already zero if (time0 > 0) --time0; end //********************************************************** //Set it all up void initialize(void) begin //set up timer 0 TIMSK=2; //turn on timer 0 cmp match ISR OCR0 = 250; //set the compare re to 250 time ticks //prescalar to 64 and turn on clear-on-match TCCR0=0b00001011; //set up the ports DDRB=0x00; // PORT B- input is bottom nibble, output is top nibble, for pushbuttons PORTB=0xff; DDRC=0xff; // PORT C is an output port for motor control PORTC=0x00; //init the task timer time0=t0; step=0; stepcount=0; //crank up the ISRs #asm sei #endasm end void main(void) begin initialize(); while(1) begin if(time0 == 0) begin time0 = t0; if (~PINB == 0x01) //move motors forwrd begin if (step > 0) step--; else step = 3; end else if (~PINB == 0x02) //move motors backwards begin if (step < 3) step++; else step = 0; end if (step == 0) PORTC = 1+128; if (step == 1) PORTC = 2+64; if (step == 2) PORTC = 4+32; if (step == 3) PORTC = 8+16; end end end