Can RESUME replace RETURN in a GOSUB?


Closed Thread
Results 1 to 7 of 7

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Hi Peter,

    The RESUME command does the same thing as a RETURN, except that it also turns on the GIE (INTCON.7) bit to re-enable Interrupts.   Not a good idea if your program isn't set-up to handle interrupts. And, since it's still a RETURN, it doesn't solve your problem.

    However, unlike Visual Basic, the program doesn't have to return from the exact same Subroutine that was called to begin with. You can GOTO another section of code and then RETURN from there.
    Code:
    BADCODE:
    SOMEWHERE IN MY CODE:
    IF PORTA.1 = 1 THEN GOSUB DOSOMETHING
    
    DOSOMETHING:
        IF PORTB.2 = 1 Then Return
        IF PORTA.5 = 0 Then Return
        IF PORTB.0 = 0 Then DoSomethingElse
    GoTo DOSOMETHING 'STAY HERE UNTIL RB2, RA5 OR RB0 DOES SOMETHING
    
    DoSomethingElse:
        ... 
    RETURN
    Or, if you want it to jump somewhere that doesn't return, you can set a "Flag" in the subroutine, and act on it in the main loop.
    Code:
    FlagBit  VAR  BIT
    
    BADCODE:
    SOMEWHERE IN MY CODE:
        FlagBit = 0
        IF PORTA.1 = 1 THEN GOSUB DOSOMETHING
        IF FlagBit = 1 then START
        ...
    
    DOSOMETHING:
        IF PORTB.2 = 1 Then Return
        IF PORTA.5 = 0 Then Return
        IF PORTB.0 = 0 Then FlagBit = 1 : Return
    GoTo DOSOMETHING 'STAY HERE UNTIL RB2, RA5 OR RB0 DOES SOMETHING
    This way, the RETURN has been satisfied, so you're free to GOTO anywhere.
    <br>
    Last edited by Darrel Taylor; - 7th October 2005 at 18:46.
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Thank you Darrel. I thought
    IF PORTB.0 = 0 Then FlagBit = 1 : Return
    was the same as
    IF PORTB.0 = 0 Then FlagBit = 1
    Return
    If it is the same, isn't it going to RETURN regardless of PORTB.0 or Flagbit? Does the first statement RETURN only when PORTB.0 = 0? Thank you. -Peter


    DOSOMETHING:
    IF PORTB.2 = 1 Then Return
    IF PORTA.5 = 0 Then Return
    IF PORTB.0 = 0 Then FlagBit = 1 : Return
    GoTo DOSOMETHING 'STAY HERE UNTIL RB2, RA5 OR RB0 DOES SOMETHING

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


    Did you find this post helpful? Yes | No

    Default

    You can have several statements on a single line and they will all be executed ONLY if the IF is true.

    IF A = B then C = A : LOW PORTB.0 : PAUSE 100 : RETURN

    Which is the same as ...

    IF A = B then
    &nbsp;&nbsp;&nbsp;&nbsp;C = A
    &nbsp;&nbsp;&nbsp;&nbsp;LOW PORTB.0
    &nbsp;&nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;&nbsp;RETURN
    ENDIF

    HTH

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel. You have opened up a whole new way for me to accomplish certain tasks. I migrated from a different basic compiler which doesn't support multiple commands on a single line. Being able to do this solves a lot of problems. - Peter

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  3. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  4. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 00:02
  5. Mssp
    By capitano in forum Code Examples
    Replies: 2
    Last Post: - 15th December 2004, 19:33

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