if-then statements


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default

    Look at what you have written and you will see why it does not work. Here is a short hint.

    MAIN:
    lcdout $fe, $80+0, "PUMP off GAS off"
    lcdout $fe, $c0+8, "WATER"
    if PORTA.2 = 1 then GOTO waterok
    if PORTA.2 = 0 then GOTO waterbad
    if PORTA.6 = 1 then GOTO tempdown
    if PORTA.7 = 1 then GOTO tempup
    PAUSE 500
    GOTO MAIN

    waterok:
    lcdout $fe, $c0+13, " OK"
    goto main

    The problem is that you jump back to main all the time so in this case you will not do the other IF statements. This is why we have GOSUB in PBP, it jumps to a SUB and when you use RETURN you will jump back to the line after..... More or less in any case.

    SO

    MAIN:
    lcdout $fe, $80+0, "PUMP off GAS off"
    lcdout $fe, $c0+8, "WATER"
    if PORTA.2 = 1 then GOSUB waterok '<------------------- JUMP if true
    if PORTA.2 = 0 then GOSUB waterbad
    if PORTA.6 = 1 then GOSUB tempdown
    if PORTA.7 = 1 then GOSUB tempup
    PAUSE 500
    GOTO MAIN

    waterok:
    lcdout $fe, $c0+13, " OK"
    RETURN '<------ to exit the SUB and return to MAIN



    Get the idea??

    M

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi C.C.,
    this might be an opportunity to use select case.

    I noticed you are using IF THEN to direct functions for each state or your PortA.2 inputs, why not use ELSE ?
    Code:
    main:
    If PortA.2 = 0 then
    gosub waterok
    ELSE
    Gosub Waterbad
    if PORTA.6 = 1 then ' assumes you have pulldown resistor
    GOSUB tempdown
    if PORTA.7 = 1 then 'assumes you have pulldown resistor
    GOSUB tempup 
    ENDIF
    endif
    endif
    goto main
    waterok:
    lcdout $fe, $c0+13, " OK"
    return
    
    waterbad:
    lcdout $FE,$c0+13, " NASTY"
    return
    
    tempdown:
    
    lcdout $fe, $80+0, "TEMP DOWN "
    RETURN
    
    tempup:
    
    lcdout $fe, $80+0, "TEMP UP "
    RETURN
    END
    HTH
    JS
    Last edited by Archangel; - 25th August 2007 at 09:00.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    How about;
    Code:
    MAIN:
        lcdout $fe, $80, "PUMP off GAS off"
        lcdout $fe, $c0+8, "WATER"
    
        if PORTA.2 = 1 then
           lcdout $fe, $c0+13, " OK "
        else
           lcdout $fe, $c0+13, " BAD"
        endif
        
        if PORTA.6 = 1 then lcdout $fe, $80, "TEMP DOWN       "
        if PORTA.7 = 1 then lcdout $fe, $80, "TEMP UP         "
        PAUSE 500
        GOTO MAIN
        END
    And maybe: if (PORTA.6=1) AND (PORTA.7=1) then lcdout $fe,$80," FAT FINGERS "..;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  2. Multiple IF-THEN statements
    By DavidK in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th June 2007, 19:28
  3. Proton Commands & statements
    By Lotondo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th November 2006, 00:37
  4. time for PBP statements
    By fnovau in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 25th October 2006, 20:42
  5. If - then statements
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th May 2006, 23:57

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