My comment, and Darrel's comment both said the same thing - it is bad form to put a bunch of code in the interrupt routine. Using a GOSUB essentially puts the bulk of your code inside the routine at compile time.
In order to not get stuck in an interrupt routine forever, typically you would stop servicing interrupts while in the routine. Either you shut them off and risk missing other interrupts, or you set a flag, and exit fast (having only executed a couple instructions). Your main program loop, then checks for the flag and if it is set, executes the GOSUB code. That can be the whole main program loop: (start: -> IF flag=1 THEN GOSUB do_stuff ELSE GOTO start) Then your routine just makes flag = 1 and exits.
There are a number of reasons to not do it the way you are doing - when an interrupt occurs, everything going on in the processor is stuffed into memory and a new program is executed. If a second interrupt happens, then those memory locations get overwritten and your original point in the program is destroyed. It is not practical to allow many levels of saving - if you wish to do that, you'll have to write your own interrupt program. It won't be easy, because of the way the PIC does interrupts, and it is unlikely to be generic, or fast.
But honestly, I have not encountered a situation where it's necessary to do that, and neither have you with the code you posted.
Bookmarks