You are on page 1of 5

#include<pic.

h>
#define S1 RC5
#define S2 RB4
#define S3 RC4
#define S4 RB3
#define M11 RB0
#define M12 RB1
#define M21 RD7
#define M22 RD6
void delay()
{
for(unsigned int d=0;d<=20000;d++);
}
void led()
{
RD0=RD1=RC1=RC0=RC2=RC3=1;
delay();
RD0=RD1=RC1=RC0=RC2=RC3=0;
}
void start()
{led();
M11=1; // RIGHT FORWARD
M12=0; //
M21=0;
M22=1;
}
void back()
{
RB0=0; // RIGHT FORWARD
RB1=1; //
RD7=1;
RD6=0;
led();
}
void left()
{
RB0=1; // RIGHT FORWARD
RB1=0; //
RD7=1;
RD6=0;
led();
}
void right()
{
RB0=0; // RIGHT FORWARD
RB1=1; //
RD7=0;
RD6=1;
led();
}
void stop()
{

RB0=0; // RIGHT FORWARD


RB1=0; //
RD7=0;
RD6=0;
led();
}
void main()
{
TRISD=0X00;
TRISC=0x30;
TRISB=0X18;
PORTB=0X00;
PORTD=0X00;
led();
while(1)
{
RD2=1;
while(RD3==1)
{
TXSTA=0x19;
// set the TRASMITER register as data 0x20
RCSTA=0x90;
//set the RECIVER rergister as data 0x90
SPBRG=0X06;
// Set the BAUD RATE 9600
while(RCIF==0);
PORTB=RCREG;
RCIF=0;
if (PORTB=='w')
{
start();
}
if (PORTB=='a')
{
left();
}
if (PORTB=='d')
{
right();
}
if (PORTB=='s')
{
stop();
dly();
back();
}
while(RD3=0);
}
led();

//do nothing till RCIF flag remains 0


//receive data into PORTB from RCREG register

start();
if(S1==0 && S2==0 && S3==0 && S4==0)
{
start();
while(S1==0 && S2==0 && S3==0 && S4==0);
}
if(S1==1 && S2==1 && S3==1 && S4==1)
{
stop();
delay();
back();

delay();
right();
delay();
delay();
delay();
led();
while(S1==1 && S2==1 && S3==1 && S4==1);
}
if(S1==0 && S2==1 && S3==1 && S4==0)
{
stop();
delay();
back();
delay();
right();
delay();
led();
while(S1==0 && S2==1 && S3==1 && S4==0);
}
if(S1==1 && S2==0 && S3==0 && S4==0)
{
right();
delay();
led();
while(S1==1 && S2==0 && S3==0 && S4==0);
}
if(S1==0 && S2==0 && S3==0 && S4==1)
{
left();
delay();
led();
while(S1==0 && S2==0 && S3==0 && S4==1);
}
if(S1==1 && S2==1 && S3==0 && S4==0)
{
stop();
delay();
right();
led();
while(S1==1 && S2==1 && S3==0 && S4==0);
}
if(S1==0 && S2==0 && S3==1 && S4==1)
{
stop();
delay();
left();
led();
while(S1==0 && S2==0 && S3==1 && S4==1);
}
if(S1== 1 && S2==0 && S3==1 && S4==0)
{
stop();
delay();
right();

led();
while(S1==1 && S2==0 && S3==1 && S4==0);
}
if(S1== 0 && S2==1 && S3==0 && S4==1)
{
stop();
delay();
left();
led();
while(S1==0 && S2==1 && S3==0 && S4==1);
}
if(S1==1 && S2==1 && S3==1 && S4==0)
{
stop();
delay();
right();
led();
while(S1==1 && S2==1 && S3==1 && S4==0);
}
if(S1==0 && S2==1 && S3==1 && S4==1)
{
stop();
delay();
left();
led();
while(S1==0 && S2==1 && S3==1 && S4==1);
}
if(S1==1 && S2==0 && S3==0 && S4==1)
{
stop();
delay();
left();
led();
while(S1==1 && S2==0 && S3==0 && S4==1);
}
if(S1==1 && S2==0 && S3==1 && S4==1)
{
stop();
delay();
left();
led();
while(S1==1 && S2==0 && S3==1 && S4==1);
}
if(S1=1 && S2==1 && S3==0 && S4==1)
{
stop();
delay();
left();
led();
while(S1==1 && S2==1 && S3==0 && S4==1);
}
if(S1==0 && S2==0 && S3==1 && S4==0)
{
stop();

delay();
left();
led();
while(S1==0 && S2==0 && S3==1 && S4==0);
}
if(S1==0 && S2==1 && S3==0 && S4==0)
{
stop();
delay();
right();
led();
while(S1==0 && S2==1 && S3==0 && S4==0);
}
}
}

You might also like