单片机a51数码管4位显示计数程序
发布网友
发布时间:2022-12-29 14:35
我来回答
共1个回答
热心网友
时间:2023-11-17 21:04
您好,这样的;
DATEQU 30H
SCANLEDEQU 34H
KEY BIT P3.2
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP T1ISR;扫描显示
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#10H
MOV TH1,#0ECH
MOV TL1,#078H
MOV SCANLED,#0
MOV 30H,#00H
MOV 31H,#10H
MOV 32H,#10H
MOV 33H,#10H
SETB ET1
SETB TR1
SETB EA
LOOP:
JB KEY,$
JNB KEY,$
INC 30H
MOV A,30H
CJNE A,#10,LOOP
MOV 30H,#0
MOV A,31H
CJNE A,#10H,LP1
CLR A
LP1:
INC A
MOV 31H,A
CJNE A,#10,LOOP
MOV 31H,#0
MOV A,32H
CJNE A,#10H,LP2
CLR A
LP2:
INC A
MOV 32H,A
CJNE A,#10,LOOP
MOV 32H,#0
MOV A,33H
CJNE A,#10H,LP3
CLR A
LP3:
INC A
MOV 33H,A
CJNE A,#10,LOOP
MOV 33H,#0
LJMP 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,#08H
SJMP T1DIS
T101:
DEC A
JNZ T102
MOV P2,#04H
SJMP T1DIS
T102:
DEC A
JNZ T103
MOV P2,#02H
SJMP T1DIS
T103:
MOV P2,#01H
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
;--------------------
LEDTAB:
DB 0C0H;"0"00H
DB 0F9H;"1"01H
DB 0A4H;"2"02H
DB 0B0H;"3"03H
DB 99H;"4"04H
DB 92H;"5"05H
DB 82H;"6"06H
DB 0F8H;"7"07H
DB 80H;"8"08H
DB 90H;"9"09H
DB 88H;"A"0AH
DB 83H;"B"0BH
DB 0C6H;"C"0CH
DB 0A1H;"D"0DH
DB 86H;"E"0EH
DB 8EH;"F"0FH
DB 0FFH;" "10H
;--------------------
END