如何用51单片机汇编语言编写一个将十六进制数转换成十进制数,并在七段数码管上显示出来的程序

2024-12-01 17:22:34
推荐回答(1个)
回答1:

KEYVAL EQU 30H
DAT EQU 33H
SCANLED EQU 39H
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP T1ISR ;扫描显示
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#10H
MOV TH1,#0ECH
MOV TL1,#078H
MOV 33H,#10H
MOV 34H,#10H
MOV 35H,#10H
MOV 36H,#10H
SETB TR1
SETB ET1
SETB EA
MOV KEYVAL,50H
LOOP:
LCALL DATCHG
JB P1.0,LOOP1
JNB P1.0,$
INC KEYVAL
SJMP LOOP
LOOP1:
JB P1.1,LOOP
JNB P1.1,$
MOV A,KEYVAL
DEC A
MOV KEYVAL,A
SJMP LOOP
T1ISR:
PUSH ACC
CLR TR1
MOV TH1,#0ECH
MOV TL1,#78H
SETB TR1
MOV DPTR,#LEDTAB
T100:
MOV R0,#DAT
MOV A,SCANLED
ADD A,R0
MOV R0,A
MOV A,SCANLED
JNZ T101
MOV P2,#01H
SJMP T1DIS
T101:
DEC A
JNZ T102
MOV P2,#02H
SJMP T1DIS
T102:
DEC A
JNZ T103
MOV P2,#04H
SJMP T1DIS
T103:
MOV P2,#08H
T1DIS:
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
INC SCANLED
MOV A,SCANLED
CJNE A,#4,T1END
MOV SCANLED,#0
T1END:
POP ACC
RETI
DATCHG:
MOV A,KEYVAL
MOV B,#100
DIV AB
MOV 34H,A
XCH A,B
MOV B,#10
DIV AB
MOV 35H,A
MOV 36H,B
RET
LEDTAB: ; 共阴极数码管显示代码表
DB 3FH,06H,5BH,4FH,66H ;01234
DB 6DH,7DH,07H,7FH,6fh ;56789
END