"WAIT" modifier with multiple choices - how to?


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default "WAIT" modifier with multiple choices - how to?

    Hi There,

    I'm wondering if it is possible to "WAIT" for more than only one condition at the time in DEBUGIN/SERIN2.

    I usually write something like this:
    Code:
    START:
    DEBUGIN 1000,START,[WAIT("first")]
    ....
    I'd like to wait for more than the word "first" but also for "second" and "third".

    But how?
    Roger

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    Yes you can. But maybe you can give an example of what you want?

    Ioannis

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default "WAIT" modifier with multiple choices - how to?

    My circuit has a serial data receiver; it "waits" for three different sets of characters (= commands) to perform different actions, one at the time.

    If "READ" is received, it will do this; if "WRITE" is received, it will do that and so for the third command, "COPY".

    Voilą how I imagine it should be working (this is obviously not the actual code, just the idea of what it should be doing):
    Code:
    START:
    DEBUGIN 1000,START,[WAIT("READ" OR "WRITE" OR "COPY")]
    IF "READ" DO...
    IF "WRITE" DO...
    IF "COPY" DO...
    ....
    I need to "wait" for either incoming command but there's where I'm stuck in the DEBUGIN/SERIN2 timeout loop.

    Due to my lack of knowledge, I have to make my circuit currently doing only one thing...frustrating
    Roger

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    My approach would be to just receive whatever comes in, then parse it later.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    My approach would be to just receive whatever comes in, then parse it later.
    + 1

    though life would be easier if
    "READ" became "*READ/n" ditto for the others {/n=chr 13


    Code:
    buff var byte[5]
    DEBUGIN 1000,START,[WAIT("*" str buff\5\13]
    then see what you got
    Warning I'm not a teacher

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default "WAIT" modifier with multiple choices - how to?

    Great! I'll give it a try.

    Thanks a lot
    Roger

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default "WAIT" modifier with multiple choices - how to?

    Thanks again Richard

    Code:
    '======= VARIABLES ================================================================================
    InString VAR BYTE[3]
    LED      VAR RC2
    Counter  VAR BYTE
    Blinks   VAR BYTE
    
    '======= INITIALIZE VARIABLES =====================================================================
    InString[0] = 0
    InString[1] = 0
    InString[2] = 0
    LED         = 0
    Counter     = 0
    Blinks      = 0
    
    '======= PROGRAM ==================================================================================
    ' Wait for strings:
    ' *AAA# = 1 blink
    ' *BBB# = 2 blinks
    ' *CCC# = 3 blinks
    
    START:
    
    Blinks      = 0
    
        DEBUGIN 1000,START,[WAIT("*"), STR InString\3\35] ' InString starts with "*" and ends with "#"
       
        if InString[0] = 65 then
            if InString[1] = 65 then
                if InString[2] = 65 then
                    Blinks = 1
                ENDIF    
            ENDIF    
        ENDIF    
    
        if InString[0] = 66 then
            if InString[1] = 66 then
                if InString[2] = 66 then
                    Blinks = 2
                ENDIF    
            ENDIF    
        ENDIF    
    
        if InString[0] = 67 then
            if InString[1] = 67 then
                if InString[2] = 67 then
                    Blinks = 3
                ENDIF    
            ENDIF    
        ENDIF    
    
    
    BLINK:
        FOR Counter = 1 to Blinks
            LED = 1
            PAUSE 500
            LED = 0
            PAUSE 500
        NEXT Counter
        GOTO START
            
    END
    Roger

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    that will do it roger


    this might be a little bit faster as only one value of instring[0] can ever be true at any one time


    Code:
    select case InString[0]
        case = 65 ;    ps you can use case = "A" to make it more readable 
            if InString[1] = 65 then
                if InString[2] = 65 then
                    Blinks = 1
                ENDIF    
            ENDIF    
       case 66  
            if InString[1] = 66 then
                if InString[2] = 66 then
                    Blinks = 2
                ENDIF    
            ENDIF    
       case 67 
            if InString[1] = 67 then
                if InString[2] = 67 then
                    Blinks = 3
                ENDIF    
            ENDIF    
    END select
    Last edited by richard; - 2nd January 2022 at 22:58.
    Warning I'm not a teacher

  9. #9
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default "WAIT" modifier with multiple choices - how to?

    ps you can use case = "A" to make it more readable
    Thanks for the tip, Richard

    Using a 16F630 for this project, I'm quite limited in program size.

    I tried something like this too:
    Code:
    IF InString[0] = 65 AND InString[1] = 65 AND InString[2] = 65 THEN Blinks = 1
    IF InString[0] = 66 AND InString[1] = 66 AND InString[2] = 66 THEN Blinks = 2
    IF InString[0] = 67 AND InString[1] = 67 AND InString[2] = 67 THEN Blinks = 3
    But, if I recall well, this code is around 80 words larger than the nested IF..THEN conditions.

    And as far as I can remember, SELECT CASE is also quite word consuming. I'll still give it a try later...
    Roger

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    The AND in the If statement is really memory hungry.

    Ioannis

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    Long ago, our member Melanie posted this great test program parsing strings and executing commands from a terminal through serial port, with no interrupts in a fast closed loop. It had great structure and expanding possibilities.

    Have a look here for the comms1.bas program: http://www.picbasic.co.uk/forum/show...=2078#post2078

    Ioannis

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: "WAIT" modifier with multiple choices - how to?

    also, might need a real chip though. 64 bytes for serial work is a challenge
    16f1825 or 16f18326 vs 16f630 price difference trivial performance and resources difference enormous , just saying.

    an asm routine can do a string compare much more efficiently if you have a chip with two fsr's but the old clunkers
    don't have that either. its a difficult path with meagre resources.
    all good fun though.

    Code:
    InString VAR BYTE[4]
    InString[3]=1
    ARRAYREAD InString, 4, ncb, [WAIT ("AAA"),Blinks]
    goto ncx
    ncb:
    InString[3]=2
    ARRAYREAD InString, 4, ncc, [WAIT ("BBB"),Blinks]
    goto ncx
    ncc:
    InString[3]=3
    ARRAYREAD InString, 4, ncd, [WAIT ("CCC"),Blinks]
    goto ncx
    ncd:
    Blinks=0
    ncx:
    other option is a if elseif chain , not sure anymore which used least ram,flash
    Last edited by richard; - 3rd January 2022 at 11:15.
    Warning I'm not a teacher

Similar Threads

  1. How to do the "SerIN" and "SerOut " for the usb ?
    By vicce67 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 13th March 2015, 03:01
  2. Replies: 0
    Last Post: - 14th November 2013, 04:32
  3. Replies: 3
    Last Post: - 15th October 2012, 09:06
  4. Multiple "AND"'s in select case?
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st January 2010, 20:10
  5. Replies: 1
    Last Post: - 16th February 2005, 21:05

Members who have read this thread : 1

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