On 21 April 2012 09:31, Goran Hosinsky wrote: > Can do a GOTO from an interrupt and continue in another part of the main > program - or will the return > from interrupt mix up the program? Using a GOTO itself is no biggie, the problem comes with making sure the code being "GOTOed" works concurrently without error. For example, if your code uses a global variable (not on a stack) GOTOing to the routine from an interrupt while it is being executed from the main code will almost certainly clobber the variable. > I spend most of the time in =A0__delay_ms with delays of 30 seconds. In > case of an UART interrupt I need to > get out of the delay routine, do some housekeeping (closing ports) and > go elsewhere in main where I will > handle the rs232 data. If I understand correctly, you want the interrupt routine to cancel the delay loop and execute a different bit of code. This isn't going to work with a simple GOTO from the interrupt handler: you can execute the other bit of code but at some point in time you will have to return from the interrupt context so that future interrupts can be handled. At this point your new execution point will have to stop and the old code (inside the delay loop) will continue as before. If the new code is fairly short this may not be a problem (does it matter if the delay code is extended by the length of the alternative code?). YMMV. A better way to do that would be to have a flag (a binary semaphore in concurrent processing nomenclature) which is set by the interrupt when the jump should be performed. The delay loop (which is by nature executing instructions continuously) can poll the flag and execute the GOTO from the main code. Since testing for a flag can be done in a fixed number of cycles (two for a BTFSS) the timing delay can be adjusted to accommodate the extra instructions. Best regards, Brendan --=20 Brendan Gillatt http://www.brendangillatt.co.uk --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .