Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Line Follower Robot

Status
Not open for further replies.
Can any one tell me how can I compile this c program of 89c2051 :-



#include d:\mc51\8051io.h
#include d:\mc51\8051reg.h
extern register unsigned char speedleft,speedright;
register unsigned char high,low,flag,time;

main()
{
P1=0x40;
P3=0xff;
high = 80;
low = 30;
flag = 0;
time = 50;
Start();
while(1) {
P3|= 0x0f;
Run();
}
}

Start()
{
char exit,key;
exit =1;
while(exit)
{
key = P1;
if((key & 0x40)==0) exit=0;
}
}

Run()
{
char sensors;
sensors = (P3 &=0x0f);

if((sensors & 0x01)==0) {
TurnRight();
flag = 1; }

else if((sensors & 0x08)==0) {
TurnLeft();
flag = 2; }
else if(sensors == 0x09) {
Forward(high);
flag = 0; }

else if(((sensors==0x0b)||(sensors==0x0d))&&(flag==0))
Forward(low);

}

Forward(char speed)
{
P1=0x64;
speedright = speed+10;
speedleft = speed;
delay(time);
}

TurnRight()
{
P1=0x68;
speedright = low+5;
speedleft = low;
delay(time);
}

TurnLeft()
{
P1=0x54;
speedright = low+5;
speedleft = low;
delay(time);
}

Reverse(char speed)
{
P1=0x58;
speedright = speed;
speedleft = speed+5;
delay(time);
}
 
Detail man! Compile it to run on what? Where did you write it? In an IDE? What MCU, if any, are you going to be ultimately using it for?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top