// Project name : Edge Avoider Robot
// Designed By  : ROBOMART
//                http://www.robomart.com

/* Program for "Robot Avoiding Edge" 
___________________________________________________

Connection settings of Kit

Left Sensor---@------------->P1.0
Right Sensor---@------------->P1.1

RIGHT MOTOR(+)------->P2.0
RIGHT MOTOR(-)------->P2.1
LEFT MOTOR(-)-------->P2.2
LEFT MOTOR(+)-------->P2.3

RESET-------------------------->PIN9
Crystal Ossilator-------------->PIN18 and PIN19
VCC=Regulated 5V
Gnd=Ground(0V)
*/

#include<reg52.h>
#define Time1 150
#define Time2 100

void delay(unsigned int);
sbit left_sensor = P1^0;	//this pin is connected to left sensor
sbit right_sensor = P1^1;   //this pin is connected to right sensor
void main(void)
{
int i;
left_sensor=1;       //make the bit as input pin.
right_sensor=1;      //make the bit as input pin.
P2=0x00;             // make port2 as output port.
while(1)
{
if(left_sensor==1&right_sensor==0)
{
P2=0x06;      // move back
delay(Time1);	  
P2=0x01;	  //left turn
delay(Time2);
   }
if(left_sensor==1&right_sensor==1)
P2=0x09;
if(left_sensor==0&right_sensor==1)
{
P2=0x06;      // move back
delay(Time1);	  
P2=0x08;	  //right turn
delay(Time2);
   }
if(left_sensor==0&right_sensor==0)
{
P2=0x06;      // move back
delay(Time1);	  
P2=0x08;	  //right turn
delay(Time2);
   }
 }
}
void delay(unsigned int time)
{ 
unsigned int i,j;
for(i=0;i<time;i++)
	for(j=0;j<1275;j++);
} 