PDA

View Full Version : from interrupt to other labels



jmbanales21485
- 29th May 2008, 00:24
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

mackrackit
- 29th May 2008, 01:33
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.

mister_e
- 29th May 2008, 05:04
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.

jmbanales21485
- 29th May 2008, 12:51
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

mackrackit
- 29th May 2008, 13:32
What would loop1 and loop2 do? And what will trigger then int?
Like Steve said, might be a better way.