PBASIC Nesting Problems
I've created a menu structure using a BS2P24 that displays a menu on a
Serial LCD, and accepts data input via the MemKey Module (Solutions 3). All
seems to work well, until I hit a certain point in the program when the
entire application seems to reset and begin at the intialization phase. The
point of error seems to be when the program is recovering from several
nested subroutines. (ie main_menu -> process_menu -> set_time ->
process_time) It reaches the process_time subroutine without a hitch, then
returns to initilization!
After a couple of "well" placed debug statements the program looks like its
reseting at the process_menu subroutine. This subroutine consists of a
series of IF...THEN statements.
PROCESS_MENU: IF NUMBER_VALUE = "A" THEN NIL
IF NUMBER_VALUE = "B" THEN NIL
IF NUMBER_VALUE = 1 THEN PLAY_MOVIE
IF NUMBER_VALUE = 2 THEN SET_TIME
IF NUMBER_VALUE = 3 THEN PLAY_SOUND
debug "DONE! - 3", cr
RETURN
Any ideas?
thanks again,
Matt
Serial LCD, and accepts data input via the MemKey Module (Solutions 3). All
seems to work well, until I hit a certain point in the program when the
entire application seems to reset and begin at the intialization phase. The
point of error seems to be when the program is recovering from several
nested subroutines. (ie main_menu -> process_menu -> set_time ->
process_time) It reaches the process_time subroutine without a hitch, then
returns to initilization!
After a couple of "well" placed debug statements the program looks like its
reseting at the process_menu subroutine. This subroutine consists of a
series of IF...THEN statements.
PROCESS_MENU: IF NUMBER_VALUE = "A" THEN NIL
IF NUMBER_VALUE = "B" THEN NIL
IF NUMBER_VALUE = 1 THEN PLAY_MOVIE
IF NUMBER_VALUE = 2 THEN SET_TIME
IF NUMBER_VALUE = 3 THEN PLAY_SOUND
debug "DONE! - 3", cr
RETURN
Any ideas?
thanks again,
Matt
Comments
of IF-THEN is a GOTO. If you're ending the PLAY_MOVIE, SET_TIME and
PLAY_SOUND code segments with a RETURN, you could be causing problems.
I've created a multilevel menu system using a stock BS2, a parallel LCD and a
74HC165 input shift register for my buttons. I had several menu items and a
couple with multiple items below them -- it was tricky, but worked without
problems. The only subroutines were to scan the inputs and update the LCD.
Everything else was controlled with BRANCH.
If you want a copy of that code, send me a note offline.
-- Jon Williams
-- Parallax
In a message dated 8/9/02 10:06:49 AM Central Daylight Time,
mgeorgy@d... writes:
> I've created a menu structure using a BS2P24 that displays a menu on a
> Serial LCD, and accepts data input via the MemKey Module (Solutions 3). All
> seems to work well, until I hit a certain point in the program when the
> entire application seems to reset and begin at the intialization phase. The
> point of error seems to be when the program is recovering from several
> nested subroutines. (ie main_menu -> process_menu -> set_time ->
> process_time) It reaches the process_time subroutine without a hitch, then
> returns to initilization!
>
> After a couple of "well" placed debug statements the program looks like its
> reseting at the process_menu subroutine. This subroutine consists of a
> series of IF...THEN statements.
>
> PROCESS_MENU: IF NUMBER_VALUE = "A" THEN NIL
> IF NUMBER_VALUE = "B" THEN NIL
> IF NUMBER_VALUE = 1 THEN PLAY_MOVIE
> IF NUMBER_VALUE = 2 THEN SET_TIME
> IF NUMBER_VALUE = 3 THEN PLAY_SOUND
> debug "DONE! - 3", cr
> RETURN
>
>
> Any ideas?
>
> thanks again,
>
[noparse][[/noparse]Non-text portions of this message have been removed]
The Stamp only has 4 allowable levels of subroutine nesting. If you
go beyond that, when the program hits a RETURN at the 5th level, it
will reset.
L0: gosub L1
L1: gosub L2:return
L2: gosub L3:return
L3: gosub L4:return
L4: gosub L5:return
L5: return ' crash (reset) here
Also, with respect to other causes for the difficulty you are facing,
I think the scenario Jon brought up is very likely--a goto in a chain
where you are thinking gosub.
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
>I've created a menu structure using a BS2P24 that displays a menu on a
>Serial LCD, and accepts data input via the MemKey Module (Solutions 3). All
>seems to work well, until I hit a certain point in the program when the
>entire application seems to reset and begin at the intialization phase. The
>point of error seems to be when the program is recovering from several
>nested subroutines. (ie main_menu -> process_menu -> set_time ->
>process_time) It reaches the process_time subroutine without a hitch, then
>returns to initilization!
>After a couple of "well" placed debug statements the program looks like its
>reseting at the process_menu subroutine. This subroutine consists of a
>series of IF...THEN statements.
>PROCESS_MENU: IF NUMBER_VALUE = "A" THEN NIL
> IF NUMBER_VALUE = "B" THEN NIL
> IF NUMBER_VALUE = 1 THEN PLAY_MOVIE
> IF NUMBER_VALUE = 2 THEN SET_TIME
> IF NUMBER_VALUE = 3 THEN PLAY_SOUND
> debug "DONE! - 3", cr
> RETURN
>Any ideas?
>thanks again,
>Matt