A Simple Program on TRI C for Obstacle avoider Robot

A Simple Program on TRI C for P89V51RD2 Obstacle avoider Robot

#include
#include
#inlcude //We include necessary header files here

#define forward 0x05; //0000 01 01 both motors in forward
#define reverse 0x0a; //0000 10 10 both motors in reverse
#define leftturn 0x06; //0000 01 10 left motor =backwards,
//right motor=forward
#define rightturn 0x09; //0000 10 01 left motor=forward
//right motor=backwards
#define obstleft P1_1
#define obstright P1_2

void main() //Main program begins here
{
P1=0xff; //intialize PORT1 as input(sensors)
P2=0x00; //intialize PORT2 as output(motors)

while(1)
{ //since there is no where to return we put it an infinite loop

if(obstleft==0) //Check if right sensor has detected an obstacle
{
P2=reverse;
DELAY(500); //if detected turn left for some time after reverse
P2=rightturn;
DELAY(200);
}

if(obstright==0) //Check if left sensor has detected as obstacle
{
P2=reverse;
DELAY(500); //if detected turn right for some time after reverse
P2=leftturn;
DELAY(200);
}

else
{
P2=forward; //else go forward
}

}
}

Replies

  • Leo
    Leo
    Hi Deelip, though you posted a program, it is of no use until we have a look on what kinda robot it is and circuit diagram details.

You are reading an archived discussion.

Related Posts

Following are the repeatedly asked Questions: Explain the different computer network functions. What are the differences between packet switching and circuit switching? Explain the OSI reference model with diagram. Compare...
Following are the frequently asked questions in theory and viva of Different University Exams. 1. What is the various applications of computer graphics? 2. Explain about CAD. 3. List the...
Following is the list of the repeatedly asked questions on System Programming. UNIT –I Q-1.1 Draw and explain the general machine structure? Q-1.2 What do you mean by system programming?...
I saw the news in a poster at College about the Robotix Event that is going to be held in IIT in coming January. Following is some information about this...
Recently while reading I came across the work of non-governmental organization called: 'Engineers Without Borders' This organization is based on engineering and is oriented towards international development work. All of...