PDA

View Full Version : interrupt problem....need help urgently



johnson
- 13th April 2004, 16:15
dear all,

I have some problem regarding using an interrupt. When an external interrupt occurs, I want the program counter to jump to the specific label instead of continue from the code that interrupt occured. Any suggestion?
I wrote this in pic basic but it does not seem to be correct:


disable
isr:
if (mode<=maxmode) then
mode=mode+1
intcon.1=0
pause 50
goto main
endif
enable



the code shows that whenever interrupt occur, after operation the program should jump to main instead of continue the code.


thanks in advance :>

Melanie
- 14th April 2004, 15:34
Your example is NOT correct.

When you jump to a Interrupt Service Routine with the ON INTERRUPT statement like so...

ON INTERRUPT GOTO ISR

you must treat this routine as if it was a subroutine, EXCEPT that with a subroutine it is exited with a RETURN, an Interrupt Service Routine MUST be exited with a RESUME.

Optionally, the RESUME can have a label to jump to as in...

RESUME ContinueFromHere

or in your example you would have...

RESUME Main

but if the label is omitted, then you will resume from the point the program was 'interrupted'.

So, if you specifically need to resume from a specific point, you do so by adding a label to the end of the RESUME statement as per my example above.

If you fail to use a RESUME when exiting your ISR, then eventually you will have a stack overflow with unpredicatable results. Remember, with most PICs, your stack is only four levels deep... that means a TOTAL of FOUR subroutines and/or interrupts at any one point in time.

Melanie

johnson
- 14th April 2004, 18:34
thanks a lot:>