PDA

View Full Version : line follower with 5 sensors



fear_none
06-29-2008, 12:07 PM
Hi..
I have written this C code in Keil UVision.. It seems to work on the simulator but not on the robot i dont understand why...



#include<regx51.h>
#include<stdio.h>

#define forward 0x05; // 0000 01 01
#define right 0x09; // 0000 10 01
#define left 0x06; // 0000 01 10
#define reverse 0x0A; // 0000 10 10
#define linesensor P1

void delay()
{
int i=120;
for(;i>0;i--);
}
void main(void) //main program begins here
{
P1=255; //initialize PORT 1 as input (sensors)
P2=0; //initialize PORT 2 as output (motors)

while (1) //since there is no where to return,
//we put it in an infinite loop
{
switch (P1)
{
case 0x00:P2=forward;
//delay();
P2=forward;
//delay();
break;

case 0x01:P2=forward;
//delay();
P2=left;
//delay();
break;

case 0x02: P2=left;
//delay();
P2=forward;
//delay();
break;

case 0x03: P2=left;
//delay();
P2=forward;
//delay();
break;

case 0x04: P2=forward;
//delay();
P2=forward;
//delay();
break;

case 0x05: P2=left;
//delay();
P2=forward;
//delay();
break;

case 0x06: P2=left;
//delay();
P2=forward;
//delay();
break;

case 0x07: P2=left;
//delay();
P2=left;
//delay();
break;

case 0x08: P2=right;
//delay();
P2=forward;
//delay();
break;

case 0x09: P2=forward;
//delay();
P2=forward;
//delay();
break;

case 0x0A: P2=forward;
//delay();
P2=forward;
//delay();
break;

case 0x0B: P2=left;
delay();
P2=forward;
delay();
break;

case 0x0C: P2=right;
delay();
P2=forward;
//delay();
break;

case 0x0D: P2=right;
//delay();
P2=forward;
delay();
break;

case 0x0E: P2=right;
delay();
P2=forward;
delay();
break;

case 0x0F: P2=left;
delay();
P2=forward;
delay();
break;

case 0x10:P2=forward;
delay();
P2=forward;
delay();
break;

case 0x11: P2=forward;
delay();
P2=forward;
delay();
break;

case 0x12: P2=forward;
delay();
P2=right;
delay();
break;

case 0x13:P2=forward;
delay();
P2=left;
delay();
break;

case 0x14: P2=right;
delay();
P2=forward;
delay();
break;

case 0x15: P2=right;
delay();
P2=forward;
delay();
break;

case 0x16: P2=left;
delay();
P2=forward;
delay();
break;

case 0x17: P2=left;
delay();
P2=forward;
delay();
break;

case 0x18:P2=forward;
delay();
P2=right;
delay();
break;

case 0x19: P2=right;
delay();
P2=forward;
delay();
break;

case 0x1A:P2=right;
delay();
P2=forward;
delay();
break;

case 0x1B: P2=forward;
delay();
P2=forward;
delay();
break;

case 0x1C: P2=right;
delay();
P2=right;
delay();
break;
case 0x1D: P2=right;
delay();
P2=forward;
delay();
break;

case 0x1E:P2=right;
delay();
P2=right;
delay();
break;

case 0x1F:P2=right;
delay();
P2=right;
delay();
break;
}
}
}


Any help would be appreciated...
Ankit

ashish_agarwal123456
06-29-2008, 09:35 PM
are u sure problem is in software and not in hardware...... as u said program is working fine on keil..... then it means problem is in hardware....

also elaborate your problem..... what wrong is happening with your robot??? is it not working at all or is it not working according to program????

it would be better if you include the hardware description amd circuit also....

fear_none
07-01-2008, 09:34 PM
Yes i am sure as a small code in Assembly i wrote to test is working
I am using:
Atmel's:AT89s52
5 IR sensors
a motor driver (all of which are working....)

docel
07-02-2008, 03:06 PM
Check your .Hex file type in Keil.

fear_none
07-05-2008, 01:21 PM
hi

I wanted to ask tht when we convert the .c fileto a .hex file does the frequency we specify matters to the conversion

Also i use at89s52 and dont have an external memory attached .. should i then choose the "Use On-Chip ROM" option(my program is 2KB in size)

The HEX file type is HEX80