EasyManua.ls Logo

Cmsemicon SC8F577 Series - Page 152

Default Icon
181 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
V1.8
SC8F577x
152 / 181
www.mcu.com.cn
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
K_START:
LD
A, KOLDH
;start to judge, higher bit first
SUBA
KDATAH
;subtract the previous key value from the current key
value
SZB
STATUS, Z
JP
K_H_SAME
;if the higher bit is equal, judge the lower bit
SZB
STATUS, C
JP
KNO
;if the higher bit of current value larger than the
previous one, there is no key press
SUBIA
01H
SNZB
STATUS, C
JP
KHAVE
;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
LD
A, KDATAL
SUBA
KOLDL
SZB
STATUS, C
JP
KHAVE
;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
SUBIA
0AH
SZB
STATUS, C
JP
KHAVE
;if the whole value is more than 10 smaller than
previous value, there is a key press
JP
KNO
;if the whole value is not more than 10 smaller than
previous value, there is no key press
K_H_SAME
LD
A, KDATAL
SUBA
KOLDL
SNZB
STATUS, C
JP
K_NO
;if the higher bit is equal and the lower bit is greater
than the previous value, there is no key press
SUBIA
0AH
SZB
STATUS, C
JP
KNO
;if the current value is more than 10 smaller than the
previous value, there is a key press
KHAVE
;program of key press
JP
XXXX
;deal with the corresponding program and go to other
program
KNO:
;program of no key press
JP
XXXX
; 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.

Related product manuals