Little code change and it seems to work fine now! The golden rule is:*
Calling a subroutine using GOSUB and jumping out of that subroutine using GOTO before the end (RETURN) of the subroutine is reached will cause a stack overflow.
* Thanks to Ralph!
Include "modedefs.bas"
DEFINE OSC 20 ' Set Xtal freq.
DEFINE DEBUG_REG PORTD ' Set Debug pin port
DEFINE DEBUG_BIT 4 ' Set Debug pin bit
DEFINE DEBUG_BAUD 9600 ' Set Debug baud rate
DEFINE DEBUG_MODE 1 ' Set Debug mode: 0 = true, 1 = inverted
Timeout VAR BYTE
Pushbutton VAR BYTE
Exit Var bit
Startup:
DEBUg 10,13,10,13," !!! Startup !!!!",13,10,13,10
goto Main
Main:
Pushbutton = 1 ' Usually 'Pushbutton' is an input-pin
Exit = 0
If Pushbutton = 1 THEN
goto FunctionD ' If the pushbutton is pushed execute FunctionD
ENDIF
Goto Main
FunctionD:
GOSUB Timeout2
If Exit = 1 then
GOTO Main
ENDIF
DEBUG "Function D",10,13
' Execute some function
Goto FunctionD
Timeout2:
Pause 100
Timeout = Timeout + 1
if Timeout > 4 then
DEBUG 10,13,"Timeout",10,13
Timeout = 0
Exit = 1
ENDIF
RETURN
Bookmarks