IF..THEN syntax


Closed Thread
Results 1 to 40 of 53

Thread: IF..THEN syntax

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default IF..THEN syntax

    I agree that the version I'm using is old but the program I tried to compile was also more or less 6 years old. anyway im pasting the whole program here for you to inspect. Thanks!


    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    v3 var byte 'Variable for calculation
    s1 var byte 'Variable s1 holds servomotor #1 pulse width info
    s2 VAR word 'variable for random function
    rv var byte 'variable rv holds the range value
    s1 = 150 'initialize steering servomotor facing forward
    rv = 10 'Adjust as needed for operation
    ct var byte 'counter


    start:
    pot portb.2,255,v1
    pot portb.3,255,v2

    'Check bumper switch "Did I hit something?"
    if porta.0 = 0 then avoid 'Hit obstacle go into avoid mode
    'Is it sleepy time?
    if v1 <= 230 then skp 'Is it dark enough to sleep?
    if v2 > 230 then slp 'Yes

    'Is it too bright to see?
    skp:
    if v1 >= 12 then skip2
    if v2 < 12 then avoid

    'Which way do I go?
    skip2:
    if v1 = v2 then straight
    if v1 > v2 then greater
    if v1 < v2 then lesser

    straight:
    pulsout portb.6, s1
    pulsout portb.7, 157
    goto start

    greater:
    v3 = v1 - v2
    if v3 > rv then right
    goto straight

    lesser:
    v3 = v2 - v1
    if v3 > rv then left
    goto straight

    right:
    s1 = s1 + 1
    if s1 > 225 then s1 = 225
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start
    left:
    s1 = s1 - 1
    if s1 < 65 then s1 = 65
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start

    slp:
    pulsout portb.6, s1
    pulsout portb.7, 167
    goto start

    avoid:
    random s2
    s1 = s2 / 256
    if s1 < 65 then s1 = 65
    if s1 > 225 then s1 = 225
    for ct = 1 to 125
    pulsout portb.6, s1
    pulsout portb.7, 177
    pause 18
    next ct

    s1 = 150

    goto start

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I just compiled it here for a 16F877. PBP 2.46

    No errors.
    <br>
    DT

  3. #3
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I just compiled it here for a 16F877. PBP 2.46

    No errors.
    <br>

    I'm compiling it for a 16F84 with PBP 2.3

    That's the only version I have because I can't afford to buy or upgrade.. I hope you understand :-)

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Compiled it for 16F84, still no errors.

    You might consider
    http://www.compilespot.com

    It's a low monthly subscription that will allow you to use the latest compiler version. If you're fast enough, you may only need to pay for 1 month.

    regards,
    DT

  5. #5
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=Darrel Taylor;32729]Compiled it for 16F84, still no errors.

    QUOTE]


    in that case, could you please send me the .HEX file so that I could load it to my PIC micro if that is ok with you?

    P.S. I sent you a PM

    :-D

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It sounds like an easy thing. It's already compiled, just send you the .HEX file.

    But, being Asst_Admin on this forum, if I started compiling things for someone, I'd have 100 people a day that didn't want to buy the compiler, sending me their files.

    That wouldn't be fair to the people that had to pay for their compiler.
    DT

  7. #7
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    well, ok then. then pls suggest any other options if its ok with you. :-)

  8. #8
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scaenix View Post

    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    v3 var byte 'Variable for calculation
    s1 var byte 'Variable s1 holds servomotor #1 pulse width info
    s2 VAR word 'variable for random function
    rv var byte 'variable rv holds the range value
    s1 = 150 'initialize steering servomotor facing forward
    rv = 10 'Adjust as needed for operation
    ct var byte 'counter


    start:
    pot portb.2,255,v1
    pot portb.3,255,v2

    'Check bumper switch "Did I hit something?"
    if porta.0 = 0 then avoid 'Hit obstacle go into avoid mode
    'Is it sleepy time?
    if v1 <= 230 then skp 'Is it dark enough to sleep?
    if v2 > 230 then slp 'Yes

    'Is it too bright to see?
    skp:
    if v1 >= 12 then skip2
    if v2 < 12 then avoid

    'Which way do I go?
    skip2:
    if v1 = v2 then straight
    if v1 > v2 then greater
    if v1 < v2 then lesser

    straight:
    pulsout portb.6, s1
    pulsout portb.7, 157
    goto start

    greater:
    v3 = v1 - v2
    if v3 > rv then right
    goto straight

    lesser:
    v3 = v2 - v1
    if v3 > rv then left
    goto straight

    right:
    s1 = s1 + 1
    if s1 > 225 then s1 = 225
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start
    left:
    s1 = s1 - 1
    if s1 < 65 then s1 = 65
    pulsout portb.6, s1
    pulsout portb.7, 165
    goto start

    slp:
    pulsout portb.6, s1
    pulsout portb.7, 167
    goto start

    avoid:
    random s2
    s1 = s2 / 256
    if s1 < 65 then s1 = 65
    if s1 > 225 then s1 = 225
    for ct = 1 to 125
    pulsout portb.6, s1
    pulsout portb.7, 177
    pause 18
    next ct

    s1 = 150

    goto start

    I've quoted the code I've posted in one of the previous replies. the program is supposed to make the servomotor #1, which is connected to RB7 stop when in total darkness. I'm confused why the motor still continues on turning even if it is supposed to stop. Please anyone enlighten me on this. Thanks very much!
    Last edited by scaenix; - 19th February 2007 at 09:09.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I didn't read the whole thing but here's one fast suggestion for you.

    Pulsout have to return the pin to it's previous state right? but nowhere the initial state have been set. When you turn on a PIC, the state of all pin is hard to predict. add those lines at the top of your code.

    Code:
    PORTB=0    ' Clear all PORTB pin
    TRISB=0     ' Set all PORTB pins to output
    if it doesn't work, you could still place a LOW PORTB.7 after each PULSOUT.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    'Read Cds cell #1 on port b line 1
    'Read Cds cell #2 on port b line 7
    v1 var byte 'Variable v1 holds Cds #1 information
    v2 var byte 'Variable v2 holds Cds #2 information
    .................................................. ..........
    start:
    pot portb.2,255,v1
    pot portb.3,255,v2
    My guess is the values in v1 and v2 are are not as expected. Pot command can be a pain at times. Do you have anyway of sending these values to an LCD to debug?
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  11. #11
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    With the current program, clearing the all PORTB pins and setting them all for output couldn't seem to work since portb.2 and portb.3 are used for storing the Cds values which serve as input. I've tried adding LOW PORTB.7 after each pulsout but it still doesn't work. About the LCD thing, I'll try it when I get to school since that is the only place where the LCD is available. I'll update you when I get the results.

  12. #12
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    hmm..can anyone please tell me what command to send to a servo motor -- a modified one for continuous rotation-- in order for it to stop? Thanks!

  13. #13
    Join Date
    Oct 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Oh well! Howdy! I've finally figured it out. I've figured out how to stop the servo motor and adding a reverse functionality to it. Thanks for the help guys! Thanks very much for all the helpful post. More power to all!

Similar Threads

  1. Endless supply of 'syntax error's.
    By BitHead in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th December 2009, 21:21
  2. Replies: 0
    Last Post: - 1st September 2008, 08:03
  3. Math operations & Syntax?
    By kevj in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd February 2008, 02:40
  4. Need help with I2C syntax problem?
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 20:11
  5. Syntax error PIC16F684
    By milestag in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st September 2005, 19:54

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