There are many ways of doing this...
In the example appended (just to get you started), the Subroutine exits ONE SECOND after the Button has been pressed. If the Button is pressed within the one second period, a new value is assigned and the Counter is reset for one second again. Only when ONE Second has elapsed from the last Button press, will the subroutine exit with the key value.
This Subroutine assigns ASCII numeric 2, or alphabetic A, B or C to the Button.
You will have to expand this out across your entire keypad, and integrate LCD Display, but the principle remains the same. At the heart of this, we are simply counting 100 loops of 10mS each. 10mS is also a good debounce time, so it serves a dual purpose.
Code:
ButtonA var PortB.0
CounterA var BYTE
CounterB var BYTE
'
' Subroutine Assigns one of FOUR Characters 2,A,B,C when Button Pressed
' ---------------------------------------------------------------------
' CounterA = Number of Button Presses (0-4)
' CounterB = Number of 10mS Loops Executed
' also contains ASCII Character (or Zero) - on Exit
'
GetKey2ABC:
CounterA=0
CounterB=0
GetKey2ABCLoop:
If ButtonA=0 then
CounterA=CounterA+1
If CounterA>4 then CounterA=1
CounterB=0
While ButtonA=0
CounterB=CounterB+1
Pause 10
If CounterB>100 then goto GetKey2ABCExit
Wend
else
CounterB=CounterB+1
Pause 10
endif
If CounterB<100 then goto GetKey2ABCLoop
GetKey2ABCExit:
Lookup CounterA,[0,"2ABC"],CounterB
Return
Bookmarks