Can you give varied levels of priority to blocks of code?


Results 1 to 8 of 8

Threaded View

  1. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Hi Joe,
    Try something like this:
    Code:
    CMCON=7 ' DISABLE ANALOG ON 628A
    
    INCLUDE "modedefs.bas" 
    
    input 0
    input 1
    input 2
    input 3
    input 4
    input 5
    input 6
    output 7
    
    FIRE_PIN      VAR PortB.5
    RESTROOM_PIN  VAR PortB.4 
    LAST_CALL_PIN VAR PortA.1
    CLOSING_PIN   VAR PortB.0
    
    
    GOTO START
    '-----------------------------------------
    '---------- Subroutines ------------------
    '-----------------------------------------
    
    '---=== Initialize LCD LCD  ===---
    INIT_LCD:
       serout 7,N2400,[254,1,"?c0"] 'Sets curser to off . . Anderson Backpack
       pause 300
       serout 7,N2400,[254,1,"?f?a"] ' special initialization for Anderson Backpack
       ' sets curser to beginning of row 1
       pause 3500 ' give lcd time to initalize after clear
    RETURN
    
    '---=== Reports status of RESTROOM to partons on LCD  ===---
    RESTROOM:
       serout 7,N2400,[254,1,"?f?a"]
       pause 250
       SEROUT 7,N2400, [254,1,"RESTROOMS ARE CLOSED"]
       PAUSE 3000
       serout 7,N2400,[254,1,"?f?a"]
    RETURN
    
    
    '---=== Reports status of FIRE to partons on LCD  ===---
    FIRE:
       serout 7,N2400,[254,1,"?f?a"]
       pause 250
       SEROUT 7,N2400, [254,1,"FIRE, PLEASE EVACUATE"]
       pause 3000
       serout 7,N2400,[254,1,"?f?a"]
    RETURN
    
    '---=== Reports status of LAST_CALL to partons on LCD  ===---
    LAST_CALL:
       serout 7,N2400,[254,1,"?f?a"]
       pause 250
       SEROUT 7,N2400, [254,1, "LAST CALL FOR ALCOHOL, SOON ONLY COFFEE SERVED!"]
       'SEROUT 7,N2400,[254,192,]
       pause 3000
       serout 7,N2400,[254,1,"?f?a"]
    RETURN
    
    '---=== Reports status of CLOSING to partons on LCD  ===---
    CLOSING:
       serout 7,N2400,[254,1,"?f?a"]
       pause 250
       serout 7,N2400,[254,1,"CLOSING TIME THANK YOU AND GOODNIGHT!"]
       PAUSE 3000
       serout 7,N2400,[254,1,"?f?a"]
    RETURN
    
    '---=== GREETING to partons on LCD  ===---
    GREETING:
       serout 7,N2400,[254,1,"?f?a"]
       pause 250
       serout 7,N2400,[254,1,"WELCOME TO MY PUB"]
       PAUSE 3000
       serout 7,N2400,[254,1,"?f?a"]
    RETURN
    
    '-----------------------------------------
    '---------- Main Program Code ------------
    '-----------------------------------------
    
    START: 
       GOSUB INIT_LCD
       GOSUB GREETING  
    
    MAIN:
    'CHECKS STATUS RESTROOMS AND REPORTS TO PATRONS ON LCD 
    
       IF FIRE_PIN = 1 THEN
          GOSUB FIRE
       ELSE
          IF RESTROOM_PIN = 1 THEN
             GOSUB RESTROOM
          ELSE
             IF LAST_CALL_PIN = 1 THEN
                GOSUB LAST_CALL
             ELsE
                IF CLOSING_PIN = 1 THEN
    		GOSUB CLOSING
                ELSE
                    GOSUB GREETING
                ENDIF
             ENDIF
          ENDIF
       ENDIF
       PAUSE 1000
    GOTO MAIN
    
    END
    I did not make any changes to the actual code lines you have, but did rearrange them into subroutines that could be called by nested IF...THEN...ELSE...ENDIF statements. This provides the priority levels you wanted. The first IF...THEN that is true will execute and then jump over the subsequent code in the ELSE portion of the statement. Additionally, I added a 5th option (GREETING) if none of the other conditions are true. You can change around the priority any way you want. Also note that I assigned names to the pins to make them easier to understand later on in the code. I haven't access to my compiler right now, so I haven't "run" my version, it isn't bug tested. Also, I am sure there are more ways to "skin this cat" but this is a start.

    EDIT: Got access to my PBP, and it compiled without errors, so you just need to check it out on you equipment.

    HTH,
    Steve
    Last edited by SteveB; - 11th August 2006 at 14:41.

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, 21:31
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23
  4. Still HSEROUT woes
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 11th July 2006, 21:13
  5. Timer PIC16F57
    By leonel in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 1st July 2005, 08:14

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