我发现无论用AVR还是51单片机编写矩阵键盘程序时都仿真不出来,不知道是不是对矩阵键盘的编程思想理解有误,求求解!小弟初学汇编语言,用汇编语言变了一个8*2的矩阵键盘驱动,用扫描法的。但仿真不出结果,望大家围观,改正我的错误。
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN:MOV SP,#60H
MOV DPTR,#TAB
MOV P0,#00H
SETB P2.0
SETB P2.1
K0: JNB P2.0,K1
JNB P2.1,K1
AJMP K0
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
JNB P2.0,G1
JNB P2.1,G2
MOV P0,#0FDH
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
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
简单注释了一下,望指点
一周热门 更多>