PDA

View Full Version : line follower coding



shirleyz
- 22nd June 2008, 15:04
i'm using pic16f877a for my line follower car. and below is the code: can anyone help me because i dont know the what does the "main loop" means??

define osc 20

'L C R
'0 0 0 MF 0
'0 0 1 TL 1
'0 1 0 MF 2
'0 1 1 TL 3
'1 0 0 TR 4
'1 0 1 MF 5
'1 1 0 TR 6
'1 1 1 SC 7

trisd.7=0 ''LEFT MOTOR''
trisd.6=0 ''RIGHT MOTOR''
trisb.0=1 ''LEFT SENSOR''
trisb.1=1 ''CENTER SENSOR''
trisb.2=1 ''RIGHT SENSOR''
trisb=%11111111

LM var portd.7
RM var portd.6
LS VAR portb.0
CS VAR portb.1
RS VAR portb.2
sensor var byte

main:
sensor=portb&7
branch sensor,[MF,TL,MF,TL,TR,MF,TR,tr]
goto main

MF:
high lm
pauseus 2000
low lm
pauseus 2000
high rm
pauseus 1000
low rm
pauseus 1000
GOTO main

TL:
HIGH LM
PAUSEUS 1000
LOW LM
PAUSEUS 1000
HIGH RM
PAUSEUS 1000
LOW RM
PAUSEUS 1000
GOTO main

TR:
HIGH LM
PAUSEUS 2000
LOW LM
PAUSEUS 2000
HIGH RM
PAUSEUS 2000
LOW RM
PAUSEUS 2000
GOTO main

skimask
- 23rd June 2008, 04:58
i'm using pic16f877a for my line follower car. and below is the code: can anyone help me because i dont know the what does the "main loop" means??
Not understanding the question.
Do you not understand the code?
Do you not understand what main means?
I don't see the term 'main loop' anywhere...

T.Jackson
- 23rd June 2008, 05:42
Shirleyz,

Main Loop simply refers to the entry / starting point of your program. The main loop will iterate through the code inside it, usually an infinite number of times until the PIC is powered down.



main:
sensor=portb&7
branch sensor,[MF,TL,MF,TL,TR,MF,TR,tr]
goto main

MF:
high lm
pauseus 2000
low lm
pauseus 2000
high rm
pauseus 1000
low rm
pauseus 1000
GOTO main

TL:
HIGH LM
PAUSEUS 1000
LOW LM
PAUSEUS 1000
HIGH RM
PAUSEUS 1000
LOW RM
PAUSEUS 1000
GOTO main

TR:
HIGH LM
PAUSEUS 2000
LOW LM
PAUSEUS 2000
HIGH RM
PAUSEUS 2000
LOW RM
PAUSEUS 2000
GOTO main


This is the main loop of your program. The code between main: and GOTO main will be executed over and over again until you tell it otherwise. Without a condition to enable it to jump out it's an infinite loop basically.

Trent Jackson

shirleyz
- 23rd June 2008, 11:56
actually i not so understand this coding that i post?? for line follower, does this code work????

skimask
- 23rd June 2008, 13:33
actually i not so understand this coding that i post?? for line follower, does this code work????

Have you tried it? Does it work? Did you write it or copy/paste it from somewhere?
Not everybody has the same hardware as you do...ok, nobody has the same hardware that you have...and good luck finding somebody to build it since there aren't any schematics posted.