จัดไป....
;//***** READ KEY PAD *****//;
;//* INPUT : -
;//* OUTPUT : ACC,KEY_FLAG
;//* REG. USE : A,B,COUNTER,DLY0,DLY1
READ_KEY: MOV B,#11110111B ;--->>> SCAN ROW 1
MOV COUNTER,#0 ;--->>> RESET COUNTER
READ_COL: MOV KEYPORT,B
READ_COL1: JB COL1,READ_COL2 ;--->>> READ COLUMN 1
ACALL DEBOUNCE
JB COL1,READ_COL2
AJMP FIND_SW0
READ_COL2: JB COL2,READ_COL3 ;--->>> READ COLUMN 2
ACALL DEBOUNCE
JB COL2,READ_COL3
AJMP FIND_SW1
READ_COL3: JB COL3,READ_COLE ;--->>> READ COLUMN 3
ACALL DEBOUNCE
JB COL3,READ_COLE
AJMP FIND_SW2
READ_COLE: MOV A,B ;--->>> SCAN NEXT ROW
RL A ;--->>>
MOV B,A ;--->>>
MOV A,COUNTER ;--->>> COUNTER = COUNTER + 3
ADD A,#3 ;--->>>
MOV COUNTER,A ;--->>>
CJNE A,#12,READ_COL ;--->>> A = 12 ?
CLR KEY_FLAG
RET
FIND_SW2: INC COUNTER ;--->>> COUNTER = COUNTER + 1
FIND_SW1: INC COUNTER ;--->>> COUNTER = COUNTER + 1
FIND_SW0: MOV A,COUNTER
MOV DPTR,#KEY_TABLE
MOVC A,@A+DPTR
SETB KEY_FLAG
RET
RELEASE_SW?: MOV A,KEYPORT ;--->>> CHECK KEY RELEASE
ORL A,#11111000B ;--->>> DATA = 11111000 + P1
CPL A ;--->>> COMPLEMENT
JNZ RELEASE_SW? ;--->>> JUMP IF ACC NOT ZERO
RET
DEBOUNCE: MOV DLY0,#50
DEBOUNCE1: MOV DLY1,#230
DEBOUNCE2: NOP
NOP
DJNZ DLY1,DEBOUNCE2
DJNZ DLY0,DEBOUNCE1
RET
;//***** TABLE OF CONT. *****//;
KEY_TABLE: DB 1,2,3,4,5,6,7,8,9,"*",0,"#"