單片機4×4矩陣鍵盤設(shè)計方案
;;;;;;;;;;定義單元;;;;;;;;;;
COUNT EQU 30H
;;;;;;;;;;入口地址;;;;;;;;;;
ORG 0000H
LJMP START
ORG 0003H
RETI
ORG 000BH
RETI
ORG 0013H
RETI
ORG 001BH
RETI
ORG 0023H
RETI
ORG 002BH
RETI
;;;;;;;;;;主程序入口;;;;;;;;;;
ORG 0100H
START: LCALL CHUSHIHUA
LCALL PANDUAN
LCALL XIANSHI
LJMP START
;;;;;;;;;;初始化程序;;;;;;;;;;
CHUSHIHUA: MOV COUNT,#00H
RET
;;;;;;;;;;判斷哪個按鍵按下程序;;;;;;;;;;
PANDUAN: MOV P3,#0FFH
CLR P3.4
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ SW1
LCALL DELAY10MS
JZ SW1
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,K1
MOV COUNT,#0
LJMP DK
K1: CJNE A,#0DH,K2
MOV COUNT,#4
LJMP DK
K2: CJNE A,#0BH,K3
MOV COUNT,#8
LJMP DK
K3: CJNE A,#07H,K4
MOV COUNT,#12
K4: NOP
LJMP DK
SW1: MOV P3,#0FFH
CLR P3.5
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ SW2
LCALL DELAY10MS
JZ SW2
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,K5
MOV COUNT,#1
LJMP DK
K5: CJNE A,#0DH,K6
MOV COUNT,#5
LJMP DK
K6: CJNE A,#0BH,K7
MOV COUNT,#9
LJMP DK
K7: CJNE A,#07H,K8
MOV COUNT,#13
K8: NOP
LJMP DK
SW2: MOV P3,#0FFH
CLR P3.6
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ SW3
LCALL DELAY10MS
JZ SW3
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,K9
MOV COUNT,#2
LJMP DK
K9: CJNE A,#0DH,KA
MOV COUNT,#6
LJMP DK
KA: CJNE A,#0BH,KB
MOV COUNT,#10
LJMP DK
KB: CJNE A,#07H,KC
MOV COUNT,#14
KC: NOP
LJMP DK
SW3: MOV P3,#0FFH
CLR P3.7
MOV A,P3
ANL A,#0FH
XRL A,#0FH
JZ SW4
LCALL DELAY10MS
JZ SW4
MOV A,P3
ANL A,#0FH
CJNE A,#0EH,KD
MOV COUNT,#3
LJMP DK
KD: CJNE A,#0DH,KE
MOV COUNT,#7
LJMP DK
KE: CJNE A,#0BH,KF
MOV COUNT,#11
LJMP DK
KF: CJNE A,#07H,KG
MOV COUNT,#15
KG: NOP
LJMP DK
SW4: LJMP PANDUAN
DK: RET
;;;;;;;;;;顯示程序;;;;;;;;;;
XIANSHI: MOV A,COUNT
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
SK: MOV A,P3
ANL A,#0FH
XRL A,#0FH
JNZ SK
RET
;;;;;;;;;;10ms延時程序;;;;;;;;;;
DELAY10MS: MOV R6,#20
D1: MOV R7,#248
DJNZ R7,$
DJNZ R6,D1
RET
;;;;;;;;;;200ms延時程序;;;;;;;;;;
DELAY: MOV R5,#20
LOOP: LCALL DELAY10MS
DJNZ R5,LOOP
RET
;;;;;;;;;;共陰碼表;;;;;;;;;;
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H
DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H
;;;;;;;;;;結(jié)束標(biāo)志;;;;;;;;;;
END
DIY機械鍵盤相關(guān)社區(qū):機械鍵盤DIY
單片機相關(guān)文章:單片機教程
單片機相關(guān)文章:單片機視頻教程
單片機相關(guān)文章:單片機工作原理
評論