How to start? [Line Following Robot with PIC 16F877A]

Markd77

Joined Sep 7, 2009
2,806
Looks like the sensors are on E0, E1, E2. However the circuit shows switches and there should be some kind of optical sensors instead. Maybe easier to start from scratch than trying to copy something badly documented.
 
is it there is easiest programming?i mean im not study the programming with #include..it start with #define..
now my main problem is the programming part..
can anybody help me..i have 3 weeks to complete this robot..
could anybody send or teach me the source code..please...
 

Thread Starter

lkwah86

Joined Mar 9, 2007
22
This is C language for my robot.

Program Code:
#include <16f877a.h> //header file
#fuses hs, noprotect, nowdt, nolvp //configuration
#use delay (clock=20000000) //delay time

#byte portc=7 //Enable port C
#byte portd=8 //Enable port D
#byte porte=9 //Enable port E

void main()
{
set_tris_e(0x07); //set port E as input E0,E1,E2
set_tris_d(0); //set all port D as output
setup_ccp1(ccp_pwm); //enable ccp1
setup_ccp2(ccp_pwm); //enable ccp2
setup_timer_2(t2_div_by_4,100,1); //set timer

//Sensor detect white as 1, detect black as 0. The motors will run according the
//conditions as below.

while(true) //Looping
{
if(!input(pin_E2) && !input(pin_E1) && input(pin_E0)) //Turn Left (001)
{
portd=0x0A; //set port D1, D3 as high (1)
set_pwm1_duty(40); //pwm1 control left motor with pwm of 40
set_pwm2_duty(90); //pwm2 control right motor with pwm of 90
}

if(!input(pin_E2) && input(pin_E1) && input(pin_E0)) //Turn Left 2 (011)
{
portd=0x0A; //set port D1, D3 as high (1)
set_pwm1_duty(40); //pwm1 control left motor with pwm of 40
set_pwm2_duty(90); //pwm1 control right motor with pwm of 90
}

if(input(pin_E2) && !input(pin_E1) && !input(pin_E0)) //Turn Right (100)
{
portd=0x0A; //set port D1, D3 as high (1)
set_pwm1_duty(90); //pwm1 control left motor with pwm of 90
set_pwm2_duty(40); //pwm1 control right motor with pwm of 40
}

if(input(pin_E2) && input(pin_E1) && !input(pin_E0)) //Turn Right 2 (110)
{
portd=0x0A; //set port D1, D3 as high (1)
set_pwm1_duty(90); //pwm1 control left motor with pwm of 90
set_pwm2_duty(40); //pwm1 control right motor with pwm of 40
}

if(!input(pin_E2) && !input(pin_E1) && !input(pin_E0)) //Forward (000)
{
portd=0x0A; //set port D1, D3 as high (1)
set_pwm1_duty(85); //pwm1 control left motor with pwm of 85
set_pwm2_duty(85); //pwm1 control right motor with pwm of 85
}

if(input(pin_E2) && input(pin_E1) && input(pin_E0)) //Backward (111)
{
portd=0x14; //set port D2, D4 as high (1)
set_pwm1_duty(85); //pwm1 control left motor with pwm of 85
set_pwm2_duty(85); //pwm1 control left motor with pwm of 85
}
}
}
 
thanks alot,,
but the program got error when i compile it,,
can u give me the hex file,,and schematic diagram too..im have 2 weeks more..please help me..im very2 needs ur help...
my email is <snip>
 
Last edited by a moderator:
the error is:

J:/zzz.c:2: error: Can't open include file "16f877a.h"
#include <16f877a.h>
J:/zzz.c:3: error: Unknown #directive "fuses"
#fuses hs, noprotect, nowdt, nolvp
J:/zzz.c:4: error: Unknown #directive "use"
#use delay (clock=20000000)
J:/zzz.c:6: error: Unknown #directive "byte"
#byte portc=7
J:/zzz.c:7: error: Unknown #directive "byte"
#byte portd=8
J:/zzz.c:8: error: Unknown #directive "byte"
#byte porte=9
6 errors in preprocessor.

im had try and dont know how to fix it..
 

Thread Starter

lkwah86

Joined Mar 9, 2007
22
u using 16F877a as PIC? u need the header file in ur compiler software...

I attached the header file.
*change the file extension to .h
 

Attachments

Last edited:
Great one mate! i also build one of this about 1 month ago.I have to do everything from the scratch.If i find this article earlier it'll help me lot.Cheer up:D!!
 
can i have all ur circuit diagram....i olready built my circuit,but it doesn't function...really need ur help...the due of this project is diz month
 
My lecturer give us a project to build a line following robot with the PIC 16F877A. And writing the code using C programming. How should I start?
Dude. Please upload every details of your project. I need every diagram.
Scematic ( With complete circuit diagram )
* Sensor
* Motor
* Power Unit
In the preview, you have used 3 IC's but in the Scematic there is only 2 IC's


So plz plz plz upload every source files with Real Pictures of you project.
 
Top