|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-12-21 22:55:26
|
显示全部楼层
ORG 0030H
MAIN:MOV SP,#60H
MOV DPTR,#TAB
MOV P0,#00H;P0输出0
SETB P2.0;p2.0为高
SETB P2.1;p2.1为高
K0: JNB P2.0,K1;检查P2.0是否为0,为0跳转到标号为K1的地方
JNB P2.1,K1;检查P2.1是否为0,为0跳转到标号为K1的地方
AJMP K0;都为1,等待按键按下
K1: LCALL KEY;调用键盘扫描程序
MOV A,B
MOVC A,@A+DPTR;查表取数码管的段码
MOV P1,A;显示段码
LCALL DELAYK;延时一下
AJMP K1;循环
KEY: NOP;按键扫描子程序
LCALL DELAY
MOV P0,#00H
SETB P2.0
SETB P2.1
JNB P2.0,G0
JNB P2.1,G0
AJMP LAST;再一次判断是否按了
G0: MOV P0,#0FEH;行1置0,其余行为1
JNB P2.0,G1;判断列1是否为0,然后跳转到G1
JNB P2.1,G2;判断列2是否为0,然后跳转
MOV P0,#0FDH;行2置0,其余行为1
JNB P2.0,G3
JNB P2.1,G4
MOV P0,#0FBH
JNB P2.0,G5
JNB P2.1,G6
MOV P0,#0F7H
JNB P2.0,G7
JNB P2.1,G8
MOV P0,#0EFH
JNB P2.0,G9
JNB P2.1,G10
MOV P0,#0DFH
JNB P2.0,G11
JNB P2.1,G12
MOV P0,#0BFH
JNB P2.0,G13
JNB P2.1,G14
MOV P0,#7FH
JNB P2.0,G15
JNB P2.1,G16
G1: MOV B,#00H
AJMP OUT
G2: MOV B,#01H
AJMP OUT
G3: MOV B,#02H
AJMP OUT
G4: MOV B,#03H
AJMP OUT
G5: MOV B,#04H
AJMP OUT
G6: MOV B,#05H
AJMP OUT
G7: MOV B,#06H
AJMP OUT
G8: MOV B,#07H
AJMP OUT
G9: MOV B,#08H
AJMP OUT
G10: MOV B,#09H
AJMP OUT
G11: MOV B,#0AH
AJMP OUT
G12: MOV B,#0BH
AJMP OUT
G13: MOV B,#0CH
AJMP OUT
G14: MOV B,#0DH
AJMP OUT
G15: MOV B,#0EH
AJMP OUT
G16: MOV B,#0FH
OUT:MOV P0,#00H
SETB P2.0
SETB P2.1
JNB P2.0,G17
JNB P2.1,G17
AJMP LAST
G17: CALL DELAY
MOV P0,#00H
SETB P2.0
SETB P2.1
JNB P2.0,KEY1
JNB P2.1,KEY1;判断是否已经松键
KEY1:LJMP G0
LAST:RET
DELAY: MOV R6,#08H
DELAY1: MOV R7,#0FAH;40MS
DELAY2: DJNZ R7,DELAY2
DJNZ R6,DELAY1
RET
DELAYK: MOV R4,#10H
DELAYK1: MOV R5,#0FAH
DELAYK2: DJNZ R7,DELAYK2
DJNZ R6,DELAYK1
RET
TAB: DB 03FH;0
DB 006H;1
DB 05BH;2
DB 04FH;3
DB 066H;4
DB 06DH;5
DB 07DH;6
DB 007H;7
DB 07FH;8
DB 06FH;9
DB 077H;A
DB 07CH;b
DB 039H;C
DB 05EH;d
DB 079H;E
DB 071H;F
END
|
|