line follower coding


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    15

    Default line follower coding

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shirleyz View Post
    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...

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    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.

    Code:
    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

  4. #4
    Join Date
    May 2008
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    actually i not so understand this coding that i post?? for line follower, does this code work????

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by shirleyz View Post
    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.

Similar Threads

  1. Replies: 0
    Last Post: - 2nd February 2009, 23:23
  2. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 05:02
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. line follower - IR sensor
    By shirleyz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th May 2008, 12:14
  5. having problems with Hantronix 20x4 lcd
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 22nd December 2005, 12:22

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts