org 0000h
ajmp main
org 0080h
main:
mov dptr,#tab ;put tab at DPTR
lcall key ;call matrix key detecting program
movc a,@a+dptr ;load tab data to ACC
mov p0,a ;move ACC to PO port
CLR P2.4 ;open display on P2
ljmp main ;display in a loop
KEY: LCALL KS ;call key detecting
JNZ K1 ;if key is down, continue
LCALL DELAY2 ;no key down, call delay to remove shaking
AJMP KEY ;get back to continue detecting
K1: LCALL DELAY2
LCALL DELAY2 ; call delay to remove shaking
LCALL KS ;call key detecting
JNZ K2 ;
AJMP KEY ;
K2: MOV R2,#0EFH ;store key value to R2
MOV R4,#00H ;move 1st column to R4
K3: MOV P1,R2 ; move R2 to P1 port
L6: JB P1.0,L1 ;
MOV A,#00H ;
AJMP LK ;
L1: JB P1.1,L2 ;
MOV A,#04H ;
AJMP LK ;
L2: JB P1.2,L3 ;
MOV A,#08H ;send 3rd row value to ACC
AJMP LK
L3: JB P1.3,NEXT ;
MOV A,#0cH ;
LK: ADD A,R4 ;
PUSH ACC ;
K4: LCALL DELAY2 ;
LCALL KS ;
JNZ K4
POP ACC
RET
NEXT:
INC R4 ;add 1 to column value
MOV A,R2 ;
JNB ACC.7,KEY ;
RL A ;
MOV R2,A
AJMP K3 ;
KS: MOV P1,#0FH ;
MOV A,P1 ;
XRL A,#0FH ;ex-or A with value 0000 1111
RET ;
DELAY2: ;
MOV R6,#08H
L7: MOV R7,#0FAH
L8: DJNZ R6,L8
DJNZ R5,L7
RET
tab:; F E 0 H C 9 8 7 B 6 5 4 A 3 2 1
db 28h,0A1h,28h,34h,0a9h,60h,20h,7ah,20h,21h,61h,74h,30h,62h,0a2h,7eh
end
No comments:
Post a Comment