You might do something like this:
Obvioulsy you can't have code that takes a long time to exectute in each section or you'll miss the button press. If that's the case, move the code that handles the button to a subroutine and call that routine multiple times from within the section(s) that takes the longest time.
Code:
ButtonPressed CON 0
FirstPieceOfCode CON 1
LastPieceOfCode CON 3
CodeToRun VAR BYTE
ButtonHasBeenPressed VAR BIT
ChangeButton VAR PortB.2
CodeToRun = FirstPieceOfcode
ButtonHasBeenPressed = 0
Main:
If ChangeButton = ButtonPressed THEN
ButtonHasBeenPressed = 1
ENDIF
IF (ButtonHasBeenPressed = 1) AND (ChangeButton <> ButtonPressed) THEN ' But was pressed but is now released
ButtonHasBeenPressed = 0
CodeToRun = CodeToRun + 1 ' Advance to next code section
If CodeToRun > LastPieceOfCode THEN ' Wrap around and start over
CodeToRun = FirstPieceOfCode
ENDIF
ENDIF
Select Case CodeToRun
Case 1
'Some code
Case 2
'Some other code
Case 3
'Yet some other code
END SELECT
Goto Main
This is not tested or even compiled so use it as an idea.
Bookmarks