Oh, that wasn't too tough afterall.
First, you need to declare the button's input, and add a variable.
Code:
PrevButton VAR PORTB.0 ' Or, wherever it is
PrevPressed VAR BIT
Then change the routines shown here. Modifications are in Red.
Code:
ShowInstructions:
ButtonDown = 1 ' Button was pressed to get here
If T = 1 THEN PauseTime = PageTime ' display each screen for 20ms
If S = 1 THEN PauseTime = PageTime2 ' display each screen for 1ms
DisplayCount = 0 ' Reset the loop counter
ShowAgain: ' Start from 1st instruction
Finished = 0
Addr = CurrentInst ' Set the address of the Instruction text
NextPage:
LCDOUT $FE,2 ' Home cursor
GOSUB DisplayPage ' Display 1 Page
KeepWaiting:
GOSUB ButtonPause ' Check buttons while pausing
IF PrevPressed = 1 THEN
PrevPressed = 0
IF Addr - 36 >= CurrentInst THEN
Addr = Addr - 36
ELSE
GOTO KeepWaiting
ENDIF
ENDIF
If Finished = 1 THEN InstructionsDone ' if The_Lcd_Push_Button Finished=1
Readcode Addr, TwoChars ' Check for END of instructions
if (TwoChars & $7F) = $7E THEN InstructionsDone
goto NextPage ' if not EOF display next page
InstructionsDone:
DisplayCount = DisplayCount + 1
if DisplayCount = MaxShows THEN Finished = 1
If Finished = 0 THEN ShowAgain
Return
' ------------------------------------------[ Watch buttons while Pausing ]-----
ButtonPause:
for PauseLoop = 1 to PauseTime ' approx. 1 ms per loop
pauseUS 980
If ButtonDown = 1 THEN ' If a button is already Pressed
GOSUB DebounceButtons ' wait for it to be released
Else ' ELSE If ButtonDown = 0 THEN
IF S = 1 THEN ' Display description of button press
ButtonDown = 1 ' set var
Finished = 1 ' Indicate that we're done reading
S = 0 ' this is set to = 1 in mainloop 1ms
Return ' Go back to mainloop with 1ms pause
endif
if The_Lcd_Push_Button = Is_Pressed THEN
ButtonDown = 1 ' set var
Finished = 1 ' Indicate that we're done reading
T = 0 ' this is set to = 1 in mainloop 20 sec
Return ' go back to the mainloop.
EndIF
If View_Instructions_Push_Button = Is_Pressed THEN
ButtonDown = 1 ' set var
PWM Buzzer,175,1 ' indicate were going to the next page
Return ' Stop pausing and Goto next Page
EndIf
IF PrevButton = Is_Pressed THEN
ButtonDown = 1
PrevPressed = 1
RETURN
ENDIF
EndIf
next PauseLoop
Return
DebounceButtons:
If The_Lcd_Push_Button = Is_Not_Pressed THEN
IF View_Instructions_Push_Button = Is_Not_Pressed THEN
IF PrevButton = Is_Not_Pressed THEN
PAUSE 20
IF PrevButton = Is_Not_Pressed THEN
If The_Lcd_Push_Button = Is_Not_Pressed THEN
IF View_Instructions_Push_Button = Is_Not_Pressed THEN ButtonDown = 0
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
RETURN
Completely Un-Tested though.
.
Bookmarks