timeout of Hserin, goto, gosub or both?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2007
    Posts
    65

    Default timeout of Hserin, goto, gosub or both?

    Hi All


    does anybody knows how TimeOUT and Hserin behave with sub(s) routine(s)?

    Manual refer to "Jump To", but can it jump to a sub and come back with return.(would be nice)

    or it would be a GOTO, with a point of no return?

    my code behave weirdly sometimes..



    Ex program:


    Code:
    Main:
    
    LOW RED_LED   ; Error led off
    HSEROUT ["GIMEDATA",13]
    GoSub BufferChar
    
    ;Show received
    if RED_LED=0
        DEBUG StrList[0],StrList[1],StrList[2]
      else
        DEBUG "ERROR",13
      endif
    
    GOTO Main
    
    
    ;A buffering char sub routine
    BUfferChar:
    gotchar=0
    Hserin 50, NoData, [return_code]
    While return_code<>13
      Hserin 50, NoData, [return_code]
      StrLIst[gotchar]=return_code
      gotchar=gotchar+1   
      WEND
    
    RETURN
    
    
    NoData:   ; Called by many routines that uses Hserin
    
     RCSTA.4 = 0 ; disable receiving of any other char
     
     return_code = 13  ; will end the While loop
     HIGH RED_LED   ; Show Error led
     
     RCSTA.4 = 1 ; Enable receiving
    
    RETURN
    
    END

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    It is a GOTO.

    I think that you should place a limit to the While/Wend othewise if the Chr 13 doesn't arrive, gotchar=gotchar+1 will grow bigger than your array, and you will corrupt some data in your program.

    If gotchar>X then do something could help.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Oh, thanks for that!

    I wonder actually, how that "WHILE" would react since HSerin is doing a GOTO somewhere else.
    Either that loop automatically get closed or it create a bug...

    I guess I should not use serial-In that way.


    and now I get even more confused about GOTO's inside a gosub? is that clean?

    Any GO-GO masters?
    Last edited by flipper_md; - 27th October 2009 at 00:32. Reason: confused

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Difficult to give suggestions without knowing what you have in mind to achieve. The below is a simple way to get out of the While/Wend loop.

    Code:
    StrLIst    var byte[10] ' for example not knowing the true dimension
    gotchar   var byte
    
    
    BUfferChar:
    gotchar=0
    return_code=0
    low HIGH RED_LED
    While return_code<>13 or gotchar >9
      Hserin 50, NoData, [return_code]
      StrLIst[gotchar]=return_code
      gotchar=gotchar+1   
      WEND
    RETURN
    
    
    Nodata:
    HIGH RED_LED   ; Show Error led (use the high state of this pin to workout   the timeout in the main routine)
    Return
    Al.
    Last edited by aratti; - 27th October 2009 at 09:16.
    All progress began with an idea

  5. #5
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    well, I believe as you suggest that it's ok to break a While loop...

    but what's tickle me is the GOTO timeout of Hserin, he would break out of a GoSub.

    If it's really a GOTO, there must not be any trace of where it was initiated in the stack, so NoData will not know where to return...
    And even more buggy, the BufferChar Gosub will not be completed.
    hence creating a bug.

    So in the end, I would believe it's not safe to use either a GOTO or a HSerin inside a Gosub.
    Last edited by flipper_md; - 28th October 2009 at 02:08. Reason: more taughs

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    If it's really a GOTO, there must not be any trace of where it was initiated in the stack, so NoData will not know where to return...
    And even more buggy, the BufferChar Gosub will not be completed.
    hence creating a bug.
    When your program jumps to NoData label, in the stacker is still pending the last GOSUB instruction (the one that directed the program flow to the routine under BUfferChar label), so no matter how many GOTO you will use, the first RETURN will clear the last pending gosub and pointer will return the program flow to the main program routine (if the gosub had been executed there). And this is what will happen with the RETURN under NoData label.

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Jul 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    very interres-thing!

    thanks much for this Al

    So it means goto's are safe inside a gosub, as long as there is a return in the end. I like that!

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 12:45
  2. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 20:54
  3. Problems with RC2 and RC3
    By Christopher4187 in forum General
    Replies: 11
    Last Post: - 29th May 2006, 18:19
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 21:10
  5. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 01:02

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