Keyboard subroutine : this program sends the ASCII codes for pressed key
MOV P2,#0FF ;
K1 : MOV P1, #0 ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , K1 ;
K2 : ACALL DELAY ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , OVER ;
SJMP K2 ;
OVER : ACALL DELAY ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , OVER1 ;
SJMP K2
OVER1:MOV P1 , #11111110B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-0 ;
MOV P1, #11111101B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-1 ;
MOV P1, #11111011B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-2
MOV P1, #11110111B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-3 ;
LJMP K2 ;
ROW-0:MOV DPTR, #KCODE0 ;
SJMP FIND ;
ROW-1:MOV DPTR, #KCODE1 ;
SJMP FIND ;
ROW-2:MOV DPTR, #KCODE2 ;
SJMP FIND ;
ROW-3:MOV DPTR, #KCODE3 ;
FIND : RRC A ;
JNC MATCH ;
INC DPTR ;
SJPM FIND ;
MATCH: CLR A ;
MOVC A,@A+DPTR ;
MOV P0,A ;
LJMP K1 ;
DELAY : MOV R1, #20 ;
HERE : MOV R2 ,#250 ;
AGAIN : DJNZ R1, AGAIN ;
DJNZ R2 , HERE
KCODE0 : DB '0','1','2','3' ; R0W 0
KCODE1 : DB '4','5','6','7' ; ROW1
KCODE2 : DB '8','9,'A','B' ; ROW2
KCODE3 : DB 'C','D','E','F' ; ROW3
END
MOV P2,#0FF ;
K1 : MOV P1, #0 ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , K1 ;
K2 : ACALL DELAY ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , OVER ;
SJMP K2 ;
OVER : ACALL DELAY ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , OVER1 ;
SJMP K2
OVER1:MOV P1 , #11111110B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-0 ;
MOV P1, #11111101B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-1 ;
MOV P1, #11111011B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-2
MOV P1, #11110111B ;
MOV A, P2 ;
ANL A, #00001111B ;
CJNE A , #00001111B , ROW-3 ;
LJMP K2 ;
ROW-0:MOV DPTR, #KCODE0 ;
SJMP FIND ;
ROW-1:MOV DPTR, #KCODE1 ;
SJMP FIND ;
ROW-2:MOV DPTR, #KCODE2 ;
SJMP FIND ;
ROW-3:MOV DPTR, #KCODE3 ;
FIND : RRC A ;
JNC MATCH ;
INC DPTR ;
SJPM FIND ;
MATCH: CLR A ;
MOVC A,@A+DPTR ;
MOV P0,A ;
LJMP K1 ;
DELAY : MOV R1, #20 ;
HERE : MOV R2 ,#250 ;
AGAIN : DJNZ R1, AGAIN ;
DJNZ R2 , HERE
KCODE0 : DB '0','1','2','3' ; R0W 0
KCODE1 : DB '4','5','6','7' ; ROW1
KCODE2 : DB '8','9,'A','B' ; ROW2
KCODE3 : DB 'C','D','E','F' ; ROW3
END
No comments:
Post a Comment