Assume that we have initialized the LCD and Keypad port accordingly and the hardware is confirmed working.
Looking at one of the subroutines that I've created below:
'This subroutine will display the current light level
Sub Display_Light_Reading
'Local variable
'Declare a 16 bit variable for the key value
DIM Display_Light_Reading_InputKeyDigit As Word
Light_Reading_OK_to_Exit = False
'Clear the LCD screen
CLS
'Display the reading of light level
DO Until Light_Reading_OK_to_Exit = True
'Get the light reading
Current_light_reading = GetLightReading
'Call the light reading display routine
GoSub Put_Light_Level_Display(Current_light_reading)
'Get key data from keypad
Display_Light_Reading_InputKeyDigit = KeypadRaw
Select Case Display_Light_Reading_InputKeyDigit
Case KEY_CANCEL
Light_Reading_OK_to_Exit = True
Case KEY_RIGHT
CLS
PRINT "KEY_RIGHT"
LOCATE 1,0
LCDInt(Display_Light_Reading_InputKeyDigit)
Wait 1 s
Light_Reading_OK_to_Exit = True
Case KEY_LEFT
CLS
PRINT "KEY_LEFT"
LOCATE 1,0
LCDInt(Display_Light_Reading_InputKeyDigit)
Wait 1 s
Light_Reading_OK_to_Exit = True
Case KEY_UP
Case KEY_DOWN
Case KEY_OK
Case Else
End Select
'Delay for 50 ms before taking next input
Wait 5 10ms
LOOP
End Sub
The intention of the subroutine is to put up the light level (calling Put_Light_Level_Display()) and also read in the keypad so that we will decide on next action to take (stay or leave this subroutine).
During runtime, if we hit on KEY_CANCEL, the PIC will exit from subroutine - This is the expected behavior.
In the same routine, if we hit on KEY_RIGHT, the PIC will put up "KEY_RIGHT" string on LCD as well as the raw keypad data on the second row of LCD. This is observed in the LCD output but we never exit the subroutine similar to KEY_CANCEL.
FYI the "KEY_RIGHT" string display is for debugging purpose and for illustration of the issue. In actual, we do not need it.
My original intention is to make KEY_RIGHT, KEY_LEFT and also KEY_CANCEL leaves this subroutine when user hits on any of them, it seems like QCBASIC couldn't interprete my intention properly.
Any advice on how to resolve the matter above would be greatly appreciated. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi guys,
Assume that we have initialized the LCD and Keypad port accordingly and the hardware is confirmed working.
Looking at one of the subroutines that I've created below:
'This subroutine will display the current light level
Sub Display_Light_Reading
'Local variable
'Declare a 16 bit variable for the key value
DIM Display_Light_Reading_InputKeyDigit As Word
Light_Reading_OK_to_Exit = False
'Clear the LCD screen
CLS
'Display the reading of light level
DO Until Light_Reading_OK_to_Exit = True
'Get the light reading
Current_light_reading = GetLightReading
'Call the light reading display routine
GoSub Put_Light_Level_Display(Current_light_reading)
'Get key data from keypad
Display_Light_Reading_InputKeyDigit = KeypadRaw
Select Case Display_Light_Reading_InputKeyDigit
Case KEY_CANCEL
Light_Reading_OK_to_Exit = True
Case KEY_RIGHT
CLS
PRINT "KEY_RIGHT"
LOCATE 1,0
LCDInt(Display_Light_Reading_InputKeyDigit)
Wait 1 s
Light_Reading_OK_to_Exit = True
Case KEY_LEFT
CLS
PRINT "KEY_LEFT"
LOCATE 1,0
LCDInt(Display_Light_Reading_InputKeyDigit)
Wait 1 s
Light_Reading_OK_to_Exit = True
Case KEY_UP
Case KEY_DOWN
Case KEY_OK
Case Else
End Select
'Delay for 50 ms before taking next input
Wait 5 10ms
LOOP
End Sub
The intention of the subroutine is to put up the light level (calling Put_Light_Level_Display()) and also read in the keypad so that we will decide on next action to take (stay or leave this subroutine).
During runtime, if we hit on KEY_CANCEL, the PIC will exit from subroutine - This is the expected behavior.
In the same routine, if we hit on KEY_RIGHT, the PIC will put up "KEY_RIGHT" string on LCD as well as the raw keypad data on the second row of LCD. This is observed in the LCD output but we never exit the subroutine similar to KEY_CANCEL.
FYI the "KEY_RIGHT" string display is for debugging purpose and for illustration of the issue. In actual, we do not need it.
My original intention is to make KEY_RIGHT, KEY_LEFT and also KEY_CANCEL leaves this subroutine when user hits on any of them, it seems like QCBASIC couldn't interprete my intention properly.
Any advice on how to resolve the matter above would be greatly appreciated. :-)