____________________________________MAIN_____________________________________________________________ #define F_CPU 1000000UL // standard integrated oscillator #include #include #include #define PORT_ON(port,pin) port |= (1< rightval && (leftval - 7) < rightval) | ((rightval + 7) > leftval && (rightval - 7) < leftval) ){ forward(); }else if (leftval < rightval){ right(); }else if (leftval > rightval){ // decide the way left(); } } ___________________________________________________________move.h___________________________________________________________ #include #include void motor1_f(void); void motor1_b(void); void motor2_f(void); void motor2_b(void); void forward(void); void backward(void); void left(void); void right(void); void turnleft(void); void turnright(void); void stop(void); void motor1_b(void) { PORTD |= _BV(PD0); } void motor1_f(void) { PORTD |= _BV(PD1); } void motor2_b(void) { PORTD |= _BV(PD2); } void motor2_f(void) { PORTD |= _BV(PD3); } void forward(void) { motor1_f(); motor2_f(); _delay_ms(1); PORTD &= ~_BV(PD1); PORTD &= ~_BV(PD3); } void backward(void) { motor1_b(); motor2_b(); _delay_ms(10); PORTD &= ~_BV(PD0); PORTD &= ~_BV(PD2); } void left(void) { motor2_f(); _delay_ms(1); PORTD &= ~_BV(PD3); } void right(void) { motor1_f(); _delay_ms(1); PORTD &= ~_BV(PD1); } void turnleft(void) { motor1_b(); motor2_f(); _delay_ms(10); PORTD &= ~_BV(PD0); PORTD &= ~_BV(PD3); } void turnright(void) { motor1_f(); motor2_b(); _delay_ms(10); PORTD &= ~_BV(PD1); PORTD &= ~_BV(PD2); } void stop(void) { PORTD &= ~_BV(PD0); PORTD &= ~_BV(PD1); PORTD &= ~_BV(PD2); PORTD &= ~_BV(PD3); }