Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

line follower programming problem

Status
Not open for further replies.

r0b0t1c

Newbie level 4
Joined
Jan 28, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
Hi. I'm doing a line following robot.
my problem is, in the simulation (pic as below), the code seems like does not work at all.

123.png

here is my code
#include <htc.h>

#if defined(WDTE_OFF)
__CONFIG(WDTE_OFF & LVP_OFF);
#elif defined (WDTDIS)
__CONFIG(WDTDIS & LVPDIS);
#endif


int main(void) {
TRISB = 0X00; //PortB as output
TRISD = 0XFF; //PortD as input

//0
if (PORTD == 0X00)
{ PORTB = 0X00;
}

//1 Slow Turn Right
if (PORTD == 0X01)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//2 Slow Turn Right
if (PORTD == 0X02)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//3 Slow Turn Right
if (PORTD == 0X03)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//4 Slow Turn Left
if (PORTD == 0X04)
{ PORTB = 0X02; //right motor foward
PORTB = 0X03; //left motor reverse
}

//5 Fast Turn Right
if (PORTD == 0X05)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//6 Straight
if (PORTD == 0X06)
{ PORTB = 0X01; //right motor foward
PORTB = 0X03; //left motor foward
}
return 0;
}

based on my code, when port RD0 or RDO+RD1 or RD0+RD1+RD2, the motor in out1, will run backward and the motor in out3 will run foward, thus the body will rotate to the left.

but in my case, it does not work. can anyone help me to solve this problem?
thx
 

write like this
Code:
#include <htc.h>

#if defined(WDTE_OFF)
__CONFIG(WDTE_OFF & LVP_OFF);
#elif defined (WDTDIS)
__CONFIG(WDTDIS & LVPDIS);
#endif


int main(void) {
TRISB = 0X00; //PortB as output
TRISD = 0XFF; //PortD as input
PORTB=0;
//0
for(;;)
{
if (PORTD == 0X00)
{ PORTB = 0X00;
}

//1 Slow Turn Right
if (PORTD == 0X01)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//2 Slow Turn Right
if (PORTD == 0X02)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//3 Slow Turn Right
if (PORTD == 0X03)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}
//4 Slow Turn Left
if (PORTD == 0X04)
{ PORTB = 0X02; //right motor foward
PORTB = 0X03; //left motor reverse
}

//5 Fast Turn Right
if (PORTD == 0X05)
{ PORTB = 0X01; //right motor reverse
PORTB = 0X04; //left motor foward
}

//6 Straight
if (PORTD == 0X06)
{ PORTB = 0X01; //right motor foward
PORTB = 0X03; //left motor foward
}
}
return 0;
}
you are missing forever loop
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top