单片机4位倒计时器
1. 四位数显管前两位控制分钟显示,后两位控制秒显示。
2.P1.5一按,可以使分钟加1 P1.6一按,可以使分钟减1. P1.7秒+1 P 1.7 秒-1
3.外部中断0启动倒计时,倒计时为0时,蜂鸣器响。
4.外部中断1清零。
比如我在数显管上设定15.00,一按外部中断0,则倒计时开始,到0时蜂鸣器响,结束。 很急啊!我编的程序老是错误!谢谢高手的解答啊!
晶振为12MHZ的 展开
我以前做了一个倒计时,贴给你做个参考:
ORG 0000H
JMP BEGIN
ORG 000BH
LJMP T0INT
ORG 001BH
LJMP T1INT
LEDD EQU 30H
LEDC EQU 36H
SECC EQU 37H
MINC EQU 38H
HOUR EQU 39H
TCNT EQU 3AH
ORG 0030H
;---------------------------------------
TABLE: ; 共阴极数码管显示代码表
DB 0FCH ;"0" 00H
DB 60H ;"1" 01H
DB 0DAH ;"2" 02H
DB 0F2H ;"3" 03H
DB 66H ;"4" 04H
DB 0B6H ;"5" 05H
DB 0BEH ;"6" 06H
DB 0E0H ;"7" 07H
DB 0FEH ;"8" 08H
DB 0F6H ;"9" 09H
DB 0EEH ;"A" 0AH
DB 3EH ;"B" 0BH
DB 9CH ;"C" 0CH
DB 7AH ;"D" 0DH
DB 9EH ;"E" 0EH
DB 8EH ;"F" 0FH
DB 00H ;" " 10H
; DB 3FH,06H,5BH,4FH,66H ;12345
; DB 6DH,7DH,07H,7FH, ;6789
;---------------------------------------
DELAY:
MOV R6,#25
DLY01:
MOV R7,#100
DJNZ R7,$
DJNZ R6,DLY01
RET
;---------------------------------------
BEGIN:
MOV SP,#5FH
MOV TMOD,#11H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV TH1,#0F4H
MOV TL1,#48H
MOV LEDC,#6
MOV R0,#LEDD
CLR A
INIT:
MOV @R0,A
INC R0
DJNZ LEDC,INIT
SETB ET1
SETB TR1
MOV P2,#0
MOV TCNT,#0
MOV HOUR,#0
MOV MINC,#0
MOV SECC,#0
SETB ET0
SETB EA
LOOP:
JB P1.0,LOOP1
LCALL DELAY
JB P1.0,LOOP1
JNB P1.0,$
INC HOUR
MOV A,HOUR
CJNE A,#24,LOOPH
LOOPH:
JC LOOPH1
MOV HOUR,#0
LOOPH1:
LCALL DISHOUR
SJMP LOOP
LOOP1:
JB P1.1,LOOP2
LCALL DELAY
JB P1.1,LOOP2
JNB P1.1,$
MOV A,HOUR
JNZ LOOPH2
MOV HOUR,#23
SJMP LOOPH3
LOOPH2:
DEC HOUR
LOOPH3:
LCALL DISHOUR
SJMP LOOP
LOOP2:
JB P1.2,LOOP3
LCALL DELAY
JB P1.2,LOOP3
JNB P1.2,$
INC MINC
MOV A,MINC
CJNE A,#60,LOOPM
LOOPM:
JC LOOPM1
MOV MINC,#0
LOOPM1:
LCALL DISMIN
SJMP LOOP
LOOP3:
JB P1.3,LOOP4
LCALL DELAY
JB P1.3,LOOP4
JNB P1.3,$
MOV A,MINC
JNZ LOOPM2
MOV MINC,#59
SJMP LOOPM3
LOOPM2:
DEC MINC
LOOPM3:
LCALL DISMIN
SJMP LOOP
LOOP4:
JB P1.4,LOOP5
LCALL DELAY
JB P1.4,LOOP5
JNB P1.4,$
INC SECC
MOV A,SECC
CJNE A,#60,LOOPS
LOOPS:
JC LOOPS1
MOV SECC,#0
LOOPS1:
LCALL DISSEC
LJMP LOOP
LOOP5:
JB P1.5,LOOP6
LCALL DELAY
JB P1.5,LOOP6
JNB P1.5,$
MOV A,SECC
JNZ LOOPS2
MOV SECC,#59
SJMP LOOPS3
LOOPS2:
DEC SECC
LOOPS3:
LCALL DISSEC
LJMP LOOP
LOOP6:
JB P3.1,LOOP7
LCALL DELAY
JB P3.1,LOOP7
JNB P3.1,$
CPL TR0
LOOP7:
LJMP LOOP
;---------------------------------------
T1INT:
PUSH ACC
CLR TR1
MOV TH1,#0F4H
MOV TL1,#48H
SETB TR1
MOV DPTR,#TABLE
MOV R0,#LEDD
MOV A,LEDC
T1INT0:
JNZ T1INT1
MOV P2,#01H
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
SJMP T1INTD
T1INT1:
DEC A
JNZ T1INT2
MOV P2,#02H
INC R0
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
SJMP T1INTD
T1INT2:
DEC A
JNZ T1INT3
MOV P2,#04H
INC R0
INC R0
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
SJMP T1INTD
T1INT3:
DEC A
JNZ T1INT4
MOV P2,#08H
INC R0
INC R0
INC R0
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
SJMP T1INTD
T1INT4:
DEC A
JNZ T1INT5
MOV P2,#10H
INC R0
INC R0
INC R0
INC R0
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
SJMP T1INTD
T1INT5:
DEC A
JNZ T1INTD
MOV P2,#20H
INC R0
INC R0
INC R0
INC R0
INC R0
MOV A,@R0
MOVC A,@A+DPTR
CPL A
MOV P0,A
T1INTD:
INC LEDC
MOV A,LEDC
CJNE A,#6,T1INT6
T1INT6:
JC T1INTE
MOV LEDC,#0
T1INTE:
POP ACC
RETI
;---------------------------------------
HBCD:
MOV B,#10
DIV AB
SWAP A
ORL A,B
RET
;---------------------------------------
T0INT:
PUSH ACC
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
INC TCNT
MOV A,TCNT
CJNE A,#20,T0INT1
T0INT1:
JC T0INTE
MOV TCNT,#0
MOV A,SECC
ORL A,MINC
ORL A,HOUR
JNZ T0INT2
SETB P3.0
CLR TR0
POP ACC
RETI
T0INT2:
MOV A,MINC
ORL A,HOUR
JNZ T0INT3
MOV A,SECC
CJNE A,#6,T0INT21
T0INT21:
JNC T0INT22
CPL P3.0
T0INT22:
DEC SECC
LCALL DISSEC
SJMP T0INTE
T0INT3:
MOV A,SECC
JZ T0INT31
DEC SECC
LCALL DISSEC
SJMP T0INTE
T0INT31:
MOV SECC,#59
LCALL DISSEC
MOV A,MINC
JZ T0INT32
DEC MINC
LCALL DISMIN
SJMP T0INTE
T0INT32:
MOV MINC,#59
LCALL DISMIN
DEC HOUR
LCALL DISHOUR
T0INTE:
POP ACC
RETI
;---------------------------------------
DISSEC:
MOV A,SECC
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 30H,A
POP ACC
SWAP A
ANL A,#0FH
MOV 31H,A
RET
;---------------------------------------
DISMIN:
MOV A,MINC
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 32H,A
POP ACC
SWAP A
ANL A,#0FH
MOV 33H,A
RET
;---------------------------------------
DISHOUR:
MOV A,HOUR
LCALL HBCD
PUSH ACC
ANL A,#0FH
MOV 34H,A
POP ACC
SWAP A
ANL A,#0FH
MOV 35H,A
RET
;---------------------------------------
END
2023-08-24 广告
请描述你的问题,或直接贴你的程序。
我的qq 229928252!你加下吧