Line Follower PIC16F877A

Status
Not open for further replies.

Klitzie

New Member
Hey everyone just wanna seek some help, im building a line follower robot using a pic16f877a but my problem is that my hardware doesn't go with the program i make in PIC-LITE using C. I already simulated the program thou Proteus everything works fine but when im load it my PIC then put it to my system my servo motors does not act the way the simulation do. But when im using a PIC16F84 everything works the same as the simulated version.
 
I would suggest you aren't configuring the code correctly for the 877?, are you disabling the analogue inputs?.
 
Nigel Goodwin said:
I would suggest you aren't configuring the code correctly for the 877?, are you disabling the analogue inputs?.

That's exactly what I thought.
Klitzie, your program might run on the simulator even if you did not care of configuring the analog modules of the PIC, but when you test it with real hardware, you might get unexpected results.
Give some details about your circuit and your program. Are you experiencing problems with PORTA or PORTE? You said that the same program runs ok with a PIC16F84, that doesn't have analog features. This again suggests a possible problem with the configuration of the 16F877A.
 
I just initialized ADCON1=7 set all inputs to digital. I will post here our program just try to scan if for probable errors in initializing our port's. This is our config PORTA=Ra0,Ra1,Ra2 are for sensors, PORTB=Rb0,Rb1,Rb2,Rb2 are for Left and Right Servo Motor we are using L2983D for the motor driver by the way:
/*Here is the source code*/
#include<pic.h>

/* BLACK LINE = 1 */
/* WHITE SURFACE = 0*/

#define FORWARD 0x09
#define RIGHT 0x08
#define LEFT 0x01
#define L_SENSOR 0x01
#define C_SENSOR 0x02
#define R_SENSOR 0x04
#define Off 0x00

void mydelay(int x);
void turnLEFT();
void turnRIGHT();
void forward();
void stop();
void main()
{

__CONFIG(0x3D39);
ADCON1= 7;
TRISA = 0x1F;
TRISB = 0x00;
PORTB = Off;

while(1)
{
if((PORTA&L_SENSOR)==L_SENSOR)
{
turnLEFT();
}
else if((PORTA&R_SENSOR)==R_SENSOR)
{
turnRIGHT();
}
else if((PORTA&C_SENSOR)==C_SENSOR)
{
forward();
}
else
{
stop();
}
}

}

void stop()
{
PORTB = Off;
}
void turnLEFT()
{
PORTB = LEFT;
}

void forward()
{
PORTB = FORWARD;
}

void turnRIGHT()
{
PORTB = RIGHT;
}
void mydelay(int x)
{
int y,z;
y=5000;
z=5000;

while(x)
{
while(y)
{
while(z)
{
z--;
}
y--;
}
x--;
}

}
/***************************************************/
 
bananasiong said:
Hi,
What are the configuration bits?
They're set with the __CONFIG() function, they're OK.
And the problem is not with the ADCON1 register like I had supposed.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…