#include <htc.h>
#if defined(WDTE_OFF)
__CONFIG(WDTE_OFF & LVP_OFF);
#elif defined (WDTDIS)
__CONFIG(WDTDIS & LVPDIS);
#endif
int main(void) {
TRISB = 0X00; //PortB as output
TRISD = 0XFF; //PortD as input
PORTB=0;
//0
for(;;)
{
if (PORTD == 0X00)
{ PORTB = 0X00;
}
//1 Slow Turn Right
if (PORTD == 0X01)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//2 Slow Turn Right
if (PORTD == 0X02)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//3 Slow Turn Right
if (PORTD == 0X03)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//4 Slow Turn Left
if (PORTD == 0X04)
{ PORTB = 0X02; //right motor foward
PORTB = 0X03; //left motor reverse
}
//5 Fast Turn Right
if (PORTD == 0X05)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//6 Straight
if (PORTD == 0X06)
{ PORTB = 0X01; //right motor foward
PORTB = 0X03; //left motor foward
}
}
return 0;
}