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--;
}
}
/***************************************************/