19.3.2 Judge method of key press
- Base of judgment: no press down---large “data”; press down---small “data”;
- The current value is smaller than previous value in a certain extent, which can be considered as the
key have been “pressed down”;
- Within a certain period of time, “data” change from large to small is considered that a key is pressed.
Example: judgment of key press
;start to judge, higher bit first
;subtract the previous key value from the current key
value
;if the higher bit is equal, judge the lower bit
;if the higher bit of current value larger than the
previous one, there is no key press
;if the higher bit of current value smaller than the
previous one, and the difference is greater or equal to
2, there is a key press
;if the higher bit of current value is 1 less than the
previous value, and the lower bit is also smaller, then
there is a key press
;if the whole value is more than 10 smaller than
previous value, there is a key press
;if the whole value is not more than 10 smaller than
previous value, there is no key press
;if the higher bit is equal and the lower bit is greater
than the previous value, there is no key press
;if the current value is more than 10 smaller than the
previous value, there is a key press
;deal with the corresponding program and go to other
program
; deal with the corresponding program and go to other
program
The previous value store in the KOLDH and KOLDL, and the current value store in the KDATAH and
KDATAL. It is considered that the key is pressed when the current value more than 10 lower than the previous
value in this example, but this threshold should be set according to the specific situation in practical application.