#include sbit m1a = P1^1;//output 1(O1) sbit m1b = P1^2;//output 2(O2) sbit m2a = P1^3;//output 3(O3) sbit m2b = P1^4;//output 4(O4) void RXDATA(unsigned char);unsigned char RX(void);void MSDELAY(unsigned char);void A();void S();void D();void W(); void Z();void C();void U();void E();void Q(); void main( ) { unsigned char a; SCON=0X50; TMOD=0X20; TH1=-24; TR1=1; PCON=0X40; P1=0X00; while(1) { a=RX(); RXDATA(a); } } void RXDATA(unsigned char a) //Receiving a byte data through serial port { switch(a) { case('A'): A( ); break; case('S'): S( ); break; case('D'): D( ); break; case('W'): W( ); break; case('Q'): Q( ); break; case('E'): E( ); break; case('U'): U( ); break; case('C'): C( ); break; case('Z'): Z(); break; } } void D( ) //Right drifts { unsigned char i; P1=0; m1a=1; for(i=0;i<=9;i++)//PWM for 1/3 duty cycle { m2a=1; MSDELAY(15); m2a=0; MSDELAY(30); } P1=0; } void S( ) //Backward movement { P1=0; m1b=1; m2b=1; } void A() //Left drift { unsigned char i; P1=0; m2a=1; for(i=0;i<=9;i++)//PWM for 1/3 duty cycle { m1a=1; MSDELAY(15); m1a=0; MSDELAY(30); } P1=0; } void W( ) //Forward movement { P1=0; m1a=1; m2a=1; } void U() //Stop { P1=0; } void E() //Sharp forward right turn { P1=0; m1a=1; } void Q( ) //Sharp forward left turn { P1=0; m2a=1; } void Z( ) //Sharp backward right turn { P1=0; m2b=1; } void C() //Sharp backward left turn { P1=0; m1b=1; } unsigned char RX() // Function to receive a data { EMERGENCY: RI=0; while(RI==0); if(SM0==1)//Check for framming error { SM0=0; goto EMERGENCY; } return(SBUF); } void MSDELAY(unsigned char b) //Delay of 3.6Ms { unsigned char i; unsigned int j; for(i=0;i<=b;i++) for(j=0;j<=310;j++); }