cancelling a GOSUB without RETURN
Hello Everybody. I am bringing up this subject again because on several occasions, my code would be much simpler using a GOSUB that contains a GOTO. However, I was told that not cancelling a GOSUB will cause code failure at some point. I've got an idea that I'm wondering if it would work. Tie MCLR to a port pin. Make the port pin an input. Both pins are tied to B+ through a resistor. In the code where the the GOTO is inside a GOSUB, make that port pin output low. It seems to me that this would reset the PIC and cancel the gosub. Am I correct? Example with 12F629 GPIO.3 (MCLR) attached to GPIO.4. Both tied to B+ through 10K:
BOOTUP:
CMCON = 7 'comparators off
TRISIO = %11111111 'ALL INPUTS
DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
PAUSE 500 'SETTLE DOWN
START:
DO THIS AND THAT
GOSUB CHECKSWITCH
GOTO START
CHECKSWITCH:
IF GPIO.0 = 1 THEN RETURN
LOW GPIO.4 'WILL THIS CANCEL GOSUB & SEND TO BOOTUP??
Could you please explain a little bit more why you need so ?
Hi,
Resetting the PIC via another pin seems technically possible. But I would like to know some example conditions which demands that a GOSUB be cancelled. I sometimes use sbroutines which may be called from other subroutines or just be executed themselve. I just use a software flag (accordingly set before a GOSUB or a GOTO) which decides how to end that routine by a return or a GOTO.
The stack pointer is not readable or writable. And three is no reference for a user initiated PUSH or POP on the mid range manual (I hope I have not skipped anything :D)
On a 18F you can push/pop it you. For reset it can be automatic when you mess up your stack, or by a RESET instruction.
Jersons technic is good as you will not be using the already pushed stack anyway and keep on pushing as if it were empty.