Try this idea, it works with PBP in a PIC18F4620 and should work with any PIC that has EEPROM.
I set a byte variable "ProgramState" to 1 in a data statement and write this to EEPROM when the program is loaded into the PIC.
At power up, the code reads the value stored in ProgramState, EEPROM location 0, here set to 1, and jumps to the appropriate code block.
MAIN:
READ 0, ProgramState
If ProgramState = 1 then RunCode1
If ProgramState = 2 then RunCode2
If ProgramState = 3 then RunCode3
If ProgramState > 3 then
write 0, 1 'reset ProgramState to first code block
goto MAIN
endif
RunCode1:
execute codeblock 1
if ButtonDown = 1 then
write 0, 2
endif
goto MAIN
RunCode2:
execute codeblock 2
if ButtonDown = 1 then
write 0, 3
endif
goto MAIN
etc
HTH
BrianT
Bookmarks