;***************************************
;--FUNCTION : KEYBOARD DRIVER.ASM.
;--PROGRAMER : MicroAC.
;--DATE : 07/04/2012.
;--PARAMETER IN <-- NONE.
; OUT--> R7.
;--NOTE :IF FUNCTION NAME EXIST "_" HAVE
; PARA AND USE INT0 TO ENABLE
; KEY SCAN WITH PORT0 SET 0xf0.
;***************************************
NAME KEYBOARD
;--KEY BOARD TALBE.
;-- " 1 2 3 SEN-TEL "
;-- " 4 5 6 EMG-CALL "
;-- " 7 8 9 USUAL-CALL "
;-- " * 0 # ON/OFF "
;--KEY VALUE LIST
; 7EH,0BEH,0DEH,0EEH, 1~4
; 7DH,0BDH,0DDH,0EDH, 5~8
; 7BH,0BBH,0DBH,0EBH, 9~12
; 77H,0B7H,0D7H,0E7H 13~16
;DECLAR MACRO REG
SCAN_PORT EQU P0
;DECLAR KEY VALUE
;NOTE:BEFORE YOU USE THESE CONST YOU NEED ADD "#".
; FOR INSTAMCE,USE KEY1 THEN SET "#KEY1".
KEY1 EQU 7EH ;KEY "1"
KEY2 EQU 0BEH ;KEY "2"
KEY3 EQU 0DEH ;KEY "3"
KEYS EQU 0EEH ;KEY "SEND TEL"
KEY4 EQU 7DH ;KEY "4"
KEY5 EQU 0BDH ;KEY "5"
KEY6 EQU 0DDH ;KEY "6"
;KEY "EMERGENT CALL",YOU MUST CLICK 3 TIMES FOR ASSURANCE.
KEYE EQU 0EDH
KEY7 EQU 7BH ;KEY "7"
KEY8 EQU 0BBH ;KEY "8"
KEY9 EQU 0DBH ;KEY "9"
KEYU EQU 0EBH ;KEY "USUALLY CALL"
KEYX EQU 77H ;KEY "*"
KEY0 EQU 0B7H ;KEY "0"
KEYC EQU 0D7H ;KEY "#"
;KEY "START SYSTEM",IF YOU CLICK AGAIN SYSTEM WILL TURN OFF.
KEYB EQU 0E7H
;?CODE ATTRIBUTE?FUNCTION NAME?MODULE NAME SEGMENT CODE
?PR?_KeyScan?KEYBOARD SEGMENT CODE
PUBLIC _KeyScan ;SERVE TO EXTERN
RSEG ?PR?_KeyScan?KEYBOARD
USING 0 ;UISING WORK REG 0
;扫描顺序:从第四行(H1)开始到第一行H4,扫描的数据为0FEH、0FDH、0FBH、0F7H .
_KeyScan: ;KeyScan(0xfe),R7<-0xfe.
MOV R7,#0FEH
MOV A,R7
MOV R2,#30 ;FOR DELAY ABOUT 20MS.
MOV R1,#255
SCAN_ONE :
PUSH ACC
MOV SCAN_PORT,A
CALL Delay
CJNE A,SCAN_PORT,SCAN_KEY_1
LJMP EXIT
SCAN_KEY_1:
MOV A,SCAN_PORT
CJNE A,#KEY1,SCAN_KEY_2
MOV R7,#1
LJMP EXIT
SCAN_KEY_2:
CJNE A,#KEY2,SCAN_KEY_3
MOV R7,#2
LJMP EXIT
SCAN_KEY_3:
CJNE A,#KEY3,SCAN_KEY_S
MOV R7,#3
LJMP EXIT
SCAN_KEY_S:
CJNE A,#KEYS,SCAN_TWO
MOV R7,#4
LJMP EXIT
SCAN_TWO:
POP ACC
SETB C
RLC A
PUSH ACC
MOV SCAN_PORT,A
CALL Delay
CJNE A,SCAN_PORT,SCAN_KEY_4
LJMP EXIT
SCAN_KEY_4:
MOV A,SCAN_PORT
CJNE A,#KEY4,SCAN_KEY_5
MOV R7,#5
LJMP EXIT
SCAN_KEY_5:
CJNE A,#KEY5,SCAN_KEY_6
MOV R7,#6
LJMP EXIT
SCAN_KEY_6:
CJNE A,#KEY6,SCAN_KEY_E
MOV R7,#7
LJMP EXIT
SCAN_KEY_E:
CJNE A,#KEYE,SCAN_THREE
MOV R7,#8
LJMP EXIT
SCAN_THREE:
POP ACC
SETB C
RLC A
PUSH ACC
MOV SCAN_PORT,A
CALL Delay
CJNE A,SCAN_PORT,SCAN_KEY_7
LJMP EXIT
SCAN_KEY_7:
MOV A,SCAN_PORT
CJNE A,#KEY7,SCAN_KEY_8
MOV R7,#9
LJMP EXIT
SCAN_KEY_8:
CJNE A,#KEY8,SCAN_KEY_9
MOV R7,#10
LJMP EXIT
SCAN_KEY_9:
CJNE A,#KEY9,SCAN_KEY_U
MOV R7,#11
LJMP EXIT
SCAN_KEY_U:
CJNE A,#KEYU,SCAN_FOUR
MOV R7,#12
LJMP EXIT
SCAN_FOUR:
POP ACC
SETB C
RLC A
PUSH ACC
MOV SCAN_PORT,A
CALL Delay
CJNE A,SCAN_PORT,SCAN_KEY_X
LJMP EXIT
SCAN_KEY_X:
MOV A,SCAN_PORT
CJNE A,#KEYX,SCAN_KEY_0
MOV R7,#13
LJMP EXIT
SCAN_KEY_0:
CJNE A,#KEY0,SCAN_KEY_C
MOV R7,#14
LJMP EXIT
SCAN_KEY_C:
CJNE A,#KEYC,SCAN_KEY_B
MOV R7,#15
LJMP EXIT
SCAN_KEY_B:
CJNE A,#KEYB,EXIT
MOV R7,#16
LJMP EXIT
; RET ;END OF FUNCTION.
Delay:
DJNZ R2,Delay0
Delay0:
DJNZ R1,$
RET
EXIT:
END