你这没有给出原理图,数码管和按键是怎么接的?是仿真实现吗,下图是仿真图,用了四位一体的共阴数码管,4个按键在P3.4~P3.7上。
仿真结果,你要是仿真,就按这个仿真图画,程序就完全适用。如果是实物开发板,就是根据开发板,适当修改程序了。
汇编程序如下
S1 BIT P3.4
S2 BIT P3.5
S3 BIT P3.6
S4 BIT P3.7
DISM1 EQU 31H
DISM2 EQU 32H
DISM3 EQU 33H
DISM4 EQU 34H
START:MOV R0,#7FH
CLEAR:MOV @R0,#0
DJNZ R0,CLEAR
MAINP:ACALL DISUP;主程序
TEST1:JB S1,TEST2
ACALL DELK4
JB S1,TEST2
INC DISM1
MOV A ,DISM1
CJNE A ,#10,CMPM1
CMPM1:JC WAIT1
MOV DISM1,#0
WAIT1:JNB S1 ,$
AJMP MAINP
TEST2:JB S2,TEST3
ACALL DELK4
JB S2,TEST3
INC DISM2
MOV A ,DISM2
CJNE A ,#10,CMPM2
CMPM2:JC WAIT2
MOV DISM2,#0
WAIT2:JNB S2 ,$
AJMP MAINP
TEST3:JB S3,TEST4
ACALL DELK4
JB S3,TEST4
INC DISM3
MOV A ,DISM3
CJNE A ,#10,CMPM3
CMPM3:JC WAIT3
MOV DISM3,#0
WAIT3:JNB S3 ,$
AJMP MAINP
TEST4:JB S4,MAINP
ACALL DELK4
JB S4,MAINP
INC DISM4
MOV A ,DISM4
CJNE A ,#10,CMPM4
CMPM4:JC WAIT4
MOV DISM4,#0
WAIT4:JNB S4 ,$
AJMP MAINP
DISUP:MOV DPTR,#TABLE;显示子程序
MOV R0 ,#DISM1
MOV R2 ,#0FEH
DISB1:MOV P2 ,R2
MOV A ,@R0
MOVC A ,@A+DPTR
MOV P0 ,A
MOV A ,R2
RL A
MOV R2 ,A
ACALL DELAY
INC R0
CJNE R0 ,#DISM4+1,DISB1
RET
DELK4:MOV R6 ,#10
SJMP DELA1
DELAY:MOV R6 ,#2
DELA1:MOV R7 ,#150
DJNZ R7 ,$
DJNZ R6 ,DELA1
RET
TABLE:DB 3FH,06H,5BH,4FH,66H;共阴段码表
DB 6DH,7DH,07H,7FH,6FH
END
还在用汇编的不是学校的学生就是玩嵌入式的高手