Gosub - clear stack


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2007
    Posts
    4

    Question Gosub - clear stack

    Hi,
    Sorry if this has been answered elsewhere. I did several searches and did not see an answer.

    I have a project that “needs” to watch for a button push or an interrupt pin and react as soon as either happens. Instead of using interrupts (I didn’t want to use them because there is a lot of serial involved in this project) I decided to use a routine instead of pause called lull.

    lull:
    for lull_tmp = 1 to lull_time
    pause 2
    IF MOD_INT = 0 Then goto incoming
    Button SET_BTON,0,255,0,B0,1,setdatetime
    next lull_tmp
    return

    it is called with something like

    lull_time = 2500 : gosub lull

    so any time I need to pause I call lull.

    I saw what looks like an issue and I think I understand where it is coming from.
    Most of the code is based on subroutines (gosub/return) and I think when an interrupt is seen and the code uses the goto it does this sometimes in the middle of a subroutine (gosub). In other words it gets there by a gosub but never uses a return. I believe there is a section of code where I get to lull by a gosub then goto to incoming which has a return in it which sends it back to the original gosub that brought it to lull in the first place. My goal is for the interrupt or button press to goto their respective code and clear all of the gosubs in the stack. Is there anyway to do this?
    Hopefully this makes sense.

    Thanks in advance for any guidance.

    Chris

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    You may want to use SELECT CASE and divert your program with GOTO.

    Thus, you get no return address in stack.

    ----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  3. Problems with RC2 and RC3
    By Christopher4187 in forum General
    Replies: 11
    Last Post: - 29th May 2006, 17:19
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 00:02

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