單片機匯編實驗四: 掃描鍵盤及LED顯示實驗
利用P0口與行列式鍵盤接口,編寫鍵盤掃描程序,把按鍵輸入的鍵碼,顯示在數碼管上
//This is the fourthprogramof the homework
//The date:2013/3/1 The author:WQ
ORG 0000H
SJMP MAIN
MAIN:
MOV DPTR,#TABLE
MOV R1,#00H
SETB P2.6
MOV P0,#00H
CLR P2.6
SETB P2.7
MOV P0,#0H;
CLR P2.7
SCAN: //檢測第一行
MOV P3,#0FEH;
MOV A,P3
ANL A,#0F0H
XHPD0: CJNE A,#0F0H,OK0
CALL JIEDIAN
SJMP NO1
OK0: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM0
SJMP XHPD0
MM0: CJNE A,#0E0H,MM1
MOV R1,#01H
CALL JIEDIAN
MM1: CJNE A,#0D0H,MM2
MOV R1,#02H
CALL JIEDIAN
MM2: CJNE A,#0B0H,MM3
MOV R1,#03H
CALL JIEDIAN
MM3: CJNE A,#070H,XHPD0
MOV R1,#04H
CALL JIEDIAN
//檢測第二行
NO1: MOV P3,#0FDH;
MOV A,P3
ANL A,#0F0H
XHPD1: CJNE A,#0F0H,OK1
CALL JIEDIAN
SJMP NO2
OK1: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM00
SJMP XHPD1
MM00: CJNE A,#0E0H,MM10
MOV R1,#05H
CALL JIEDIAN
MM10: CJNE A,#0D0H,MM20
MOV R1,#06H
CALL JIEDIAN
MM20: CJNE A,#0B0H,MM30
MOV R1,#07H
CALL JIEDIAN
MM30: CJNE A,#070H,XHPD1
MOV R1,#08H
CALL JIEDIAN
//檢測第三行
NO2: MOV P3,#0FBH;
MOV A,P3
ANL A,#0F0H
XHPD2: CJNE A,#0F0H,OK2
CALL JIEDIAN
SJMP NO3
OK2: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM01
SJMP XHPD2
MM01: CJNE A,#0E0H,MM11
MOV R1,#09H
CALL JIEDIAN
MM11: CJNE A,#0D0H,MM21
MOV R1,#0AH
CALL JIEDIAN
MM21: CJNE A,#0B0H,MM31
MOV R1,#0BH
CALL JIEDIAN
MM31: CJNE A,#070H,XHPD2
MOV R1,#0CH
CALL JIEDIAN
//檢測第四行
NO3: MOV P3,#0F7H;
MOV A,P3
ANL A,#0F0H
XHPD3: CJNE A,#0F0H,OK3
CALL JIEDIAN
LJMP SCAN
OK3: CALL DELAY
MOV A,P3
ANL A,#0F0H
CJNE A,#0F0H,MM40
SJMP XHPD3
MM40: CJNE A,#0E0H,MM41
MOV R1,#0DH
CALL JIEDIAN
CALL DELAY
MM41: CJNE A,#0D0H,MM42
MOV R1,#0EH
MM42: CJNE A,#0B0H,MM43
MOV R1,#0FH
MM43: CJNE A,#070H,XHPD3
MOV R1,#10H
CALL JIEDIAN
LJMP scan
ORG 02f0h
DELAY: MOV R3,#012H
DELY1: MOV R4,#011H
DELY2: NOP
DJNZ R4,DELY2
DJNZ R3,DELY1
RET
JIEDIAN:
MOV A,R1
MOVC A,@A+DPTR
SETB P2.6
MOV P0,A
CLR P2.6
RET
org0250h
TABLE: DB
0H,3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79
H,71H
END
評論