from interrupt to other labels


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default from interrupt to other labels

    I have a question on interrupt and GOTO lables

    How can I go from an interrupt routine to another label in the code? i know this is a wierd question but let me try to explain.

    if i have nested subroutines, subroutines that call other subroutines, and i have an interrupt set up so that if a button gets pressed then the interrupt will be called, then from the interrupt i want to go to another state, or another label in the software. a semi lame example is below of what i'm trying to do. please let me know what i can do to accomplish this wierd task. thank you all.

    main:
    GOSUB subroutine1
    'code here
    GOTO label1


    subroutine1:
    'code here
    GOSUB subroutine2
    RETURN

    subroutine2:
    'code here
    GOSUB subroutine3
    RETURN

    subroutine3:
    'code here
    RETURN

    label1:
    'get in here from interrupt
    GOTO label1

    label2:
    'get in here from interrupt
    goto label2

    DISABLE
    myINT:
    'IF interrupt then i want to go to label1
    'IF something else i want to go to label 2
    RESUME
    ENABLE

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Look at the interrupt as a subroutine. What ever you have triggering the interrupt will cause this special sub to run. Then as in a gosub, when it is finished the resume resumes...
    So what ever lable1 and label2 are, do these inside of the interrupt.

    Not a good idea to break out of an interrupt. Need to finish it and enable/resume.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Careful when using nested subs... may run into stack overflow sooner than you may think.

    You should rethink of your whole program. Maybe INTs are not needed at all. General rules, keep ISR short, set variables and/flags in, once you get out, your main program will check those variables and branch to the according routines.

    If you plan to use gosub/goto in your ISR, the routine you will jump to have to be within the DISABLE/ENABLE code section.
    Last edited by mister_e; - 29th May 2008 at 05:14.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Careful when using nested subs... may run into stack overflow sooner than you may think.
    your right. i did run into a stack overflow problem when i was simulating the code. i tried to make my program more modular with nested subs but i guess the stack can only be 3 gosubs deep, anything more will give me a stack overflow problem

    i will put my routines in loop1 and loop2 inside the interrupt. i think that will work and i won't run into an overflow problem.

    thank you mr. e

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What would loop1 and loop2 do? And what will trigger then int?
    Like Steve said, might be a better way.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  4. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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