交通灯下面的数码管倒计时显示模块 倒计时时不规律有时候会闪一下 不知道如何解决?
SECOND1 EQU 30H
SECOND2 EQU 31H
DBUF EQU 40H
TEMP EQU 44H
LED_G1 BIT P2.1
LED_Y1 BIT P2.2
LED_R1 BIT P2.3
LED_G2 BIT P2.4
LED_Y2 BIT P2.5
LED_R2 BIT P2.6
;***********************************************
ORG 0000H
LJMP START
ORG 0100H
START:
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
CLR TF0
SETB TR0
CLR A
MOV P2,A
;***********************************************
LOOP:
MOV R2,#20
MOV R3,#20
MOV SECOND1,#25
MOV SECOND2,#25
LCALL DISPLAY
LCALL STATE1
WAIT1:
JNB TF0,WAIT1
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R2,WAIT1
MOV R2,#20
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT1
;***********************************************
MOV R2,#5 ;判断1s是否到,200ms*5=1s
MOV R3,#3 ;绿灯闪3s
MOV R4,#4 ;绿灯闪烁间隔为50ms*4=200ms
MOV SECOND1,#5
MOV SECOND2,#5
LCALL DISPLAY
WAIT2:
LCALL STATE2
JNB TF0,WAIT2
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R4,WAIT2
CPL LED_G1
MOV R4,#4
DJNZ R2,WAIT2
MOV R2,#5
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT2
;***********************************************
MOV R2,#20
MOV R3,#2
MOV SECOND1,#2
MOV SECOND2,#2
LCALL DISPLAY
WAIT3:
LCALL STATE3
JNB TF0,WAIT3
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R2,WAIT3
MOV R2,#20
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT3
;***********************************************
MOV R2,#20
MOV R3,#20
MOV SECOND1,#25
MOV SECOND2,#25
LCALL DISPLAY
WAIT4:
LCALL STATE4
JNB TF0,WAIT4
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R2,WAIT4
MOV R2,#20
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT4
;***********************************************
MOV R2,#5
MOV R3,#3
MOV R4,#4
MOV SECOND1,#5
MOV SECOND2,#5
LCALL DISPLAY
WAIT5:
LCALL STATE5
JNB TF0,WAIT5
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R4,WAIT5
CPL LED_G2
MOV R4,#4
DJNZ R2,WAIT5
MOV R2,#5
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT5
;***********************************************
MOV R2,#20
MOV R3,#2
MOV SECOND1,#2
MOV SECOND2,#2
LCALL DISPLAY
WAIT6:
LCALL STATE6
JNB TF0,WAIT6
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R2,WAIT6
MOV R2,#20
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT6
LJMP START
;***********************************************
STATE1:
SETB LED_G1
CLR LED_Y1
CLR LED_R1
CLR LED_G2
CLR LED_Y2
SETB LED_R2
RET
STATE2:
CLR LED_Y1
CLR LED_R1
CLR LED_G2
CLR LED_Y2
SETB LED_R2
RET
STATE3:
CLR LED_G1
SETB LED_Y1
CLR LED_R1
CLR LED_G2
CLR LED_Y2
SETB LED_R2
RET
STATE4:
CLR LED_G1
CLR LED_Y1
SETB LED_R1
SETB LED_G2
CLR LED_Y2
CLR LED_R2
RET
STATE5:
CLR LED_G1
CLR LED_Y1
SETB LED_R1
CLR LED_G2
CLR LED_Y2
RET
STATE6:
CLR LED_G1
CLR LED_Y1
SETB LED_R1
CLR LED_G2
SETB LED_Y2
CLR LED_R2
RET
;***********************************************
DISPLAY:
MOV A,SECOND1
MOV B,#10
DIV AB
MOV DBUF+3,A
MOV A,B
MOV DBUF+2,A
MOV A,SECOND2
MOV B,#10
DIV AB
MOV DBUF+1,A
MOV A,B
MOV DBUF,A
MOV R0,#DBUF
MOV R1,#TEMP
MOV R7,#4
DP10:
MOV DPTR,#LEDMAP
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
DJNZ R7,DP10
MOV R0,#TEMP
MOV R1,#4
DP12:
MOV R5,#8
MOV R7,#8
MOV A,@R0
DP13:
RLC A
MOV P3.0,C
CLR P3.1
SETB P3.1
DJNZ R7,DP13
INC R0
DJNZ R1,DP12
RET
LEDMAP:
DB 3FH,06H,5BH,4FH,66H
DB 6DH,7DH,07H,7FH,6FH
END
|