Feature Request:
1): The green light has a 25s countdown. There is a 5s yellow light time when the green light transitions to the red light. The red light will directly turn green after 25s.
2): Press the button to simulate the red light running input, and generate a 5s buzzer beep.
Development Environment:
Software: Keil uVision4
Hardware: HOT51 enhanced MCU development board
code:
ORG 0000H
AJMP MAIN
ORG 0003H
LJMP INTER
ORG 000BH
LJMP TIMER1
ORG 0030H
; Main function starts
MAIN: MOV R7,#00H
DJNZ R7,$
MOV SP,#60H
MOV TMOD,#01H
MOV TH0,#3CH; The timer timing is 50ms
MOV TL0,#0AFH
MOV R6,#20; Timer count 20*50ms=1s
SETB ET0
SETB EX0
SETB OF
SETB TR0
;--------------------------------------------------------------;
ST1: MOV R5,#25; The main road lights up green for 25 seconds, and the branch road lights up red for 25 seconds
DIS1: MOV A,R5
JNZ NEXT1; if 5s has been reduced to 0, jump to the next state ST3
AJMP ST2
NEXT1: MOV A,#25
CLR C
SUBB A, R5 ; Subtract to get the time that has passed
MOV B,A
MOV A,#07H ; Get the jump offset from the table
I have AB
MOV DPTR,#TAB1
ADD A,DPL ; add offset
MOV DPL,A
MOV A,#00H
ADDC A, VAT
IOV VAT, A
MOV A, R4
JZ NOSP1 ; If the chirping time is not 0, chirp (negate p1.2), otherwise do not chirp
CPL P1.2
NOSP1: MOV A,#00H; Dynamic display, cycle lighting of digital tubes
MOV P0,#00H
MOV P2,#0FFH
MOVC A,@A+DPTR
MOV P0,A ; Display the unit digit of the branch
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F6H
MOVC A,@A+DPTR
MOV P0,A ; Display branch tens digit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F5H
MOVC A,@A+DPTR
MOV P0,A ; Display the main line unit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F4H
MOVC A,@A+DPTR
MOV P0,A ; Display the main road tens
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F2H
MOVC A,@A+DPTR
MOV P0,A; The following 3 outputs show the main branch lighting status
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F1H
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F0H
MOVC A,@A+DPTR
MOV P0,A
MOV P0,#00H
MOV P2,#0FFH
AJMP DIS1 ; Return to the start cycle and light up the digital tube
TAB1: DB 3FH,4FH,6DH,5BH,08H,00H,01H ;25
DB 6FH,5BH,66H,5BH,08H,00H,01H ;24
DB 7FH,5BH,4FH,5BH,08H,00H,01H ;23
DB 07H,5BH,5BH,5BH,08H,00H,01H ;22
DB 7DH,5BH,06H,5BH,08H,00H,01H ;21
DB 6DH,5BH,3FH,5BH,08H,00H,01H ;20
DB 66H,5BH,6FH,06H,08H,00H,01H ;19
DB 4FH,5BH,7FH,06H,08H,00H,01H ;18
DB 5BH,5BH,07H,06H,08H,00H,01H ;17
DB 06H,5BH,7DH,06H,08H,00H,01H ;16
DB 3FH,5BH,6DH,06H,08H,00H,01H ;15
DB 6FH,06H,66H,06H,08H,00H,01H ;14
DB 7FH,06H,4FH,06H,08H,00H,01H ;13
DB 07H,06H,5BH,06H,08H,00H,01H ;12
DB 7DH,06H,06H,06H,08H,00H,01H ;11
DB 6DH,06H,3FH,06H,08H,00H,01H ;10
DB 66H,06H,6FH,3FH,08H,00H,01H ;09
DB 4FH,06H,7FH,3FH,08H,00H,01H ;08
DB 5BH,06H,07H,3FH,08H,00H,01H ;07
DB 06H,06H,7DH,3FH,08H,00H,01H ;06
DB 3FH,06H,6DH,3FH,08H,00H,01H ;05
DB 6FH,3FH,66H,3FH,08H,00H,01H ;04
DB 7FH,3FH,4FH,3FH,08H,00H,01H ;03
DB 07H,3FH,5BH,3FH,08H,00H,01H ;02
DB 7DH,3FH,06H,3FH,08H,00H,01H ;01
;--------------------------------------------------------------;
ST2: MOV R5,#5; The main road lights up yellow for 5 seconds, and the branch road lights up red for 5 seconds
DIS2: MOV A,R5
JNZ NEXT2; if 5s has been reduced to 0, jump to the next state ST3
AJMP ST3
NEXT2: MOV A,#5
CLR C
SUBB A, R5 ; Subtract to get the time that has passed
MOV B,A
MOV A,#07H ; Get the jump offset from the table
I have AB
MOV DPTR,#TAB2
ADD A,DPL ; add offset
MOV DPL,A
MOV A,#00H
ADDC A, VAT
IOV VAT, A
MOV A, R4
JZ NOSP2 ; If the chirping time is not 0, chirp (negate p1.2), otherwise do not chirp
CPL P1.2
NOSP2: MOV A,#00H; Dynamic display, cycle lighting of digital tubes
MOV P0,#00H
MOV P2,#0FFH
MOVC A,@A+DPTR
MOV P0,A ; Display the unit digit of the branch
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F6H
MOVC A,@A+DPTR
MOV P0,A ; Display branch tens digit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F5H
MOVC A,@A+DPTR
MOV P0,A ; Display the main line unit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F4H
MOVC A,@A+DPTR
MOV P0,A ; Display the main road tens
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F2H
MOVC A,@A+DPTR
MOV P0,A; The following 3 outputs show the main branch lighting status
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F1H
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F0H
MOVC A,@A+DPTR
MOV P0,A
MOV P0,#00H
MOV P2,#0FFH
AJMP DIS2 ; Return to the start cycle and light up the digital tube
TAB2: DB 6DH,3FH,6DH,3FH,08H,01H,00H ;05
DB 66H,3FH,66H,3FH,08H,01H,00H ;04
DB 4FH,3FH,4FH,3FH,08H,01H,00H ;03
DB 5BH,3FH,5BH,3FH,08H,01H,00H ;02
DB 06H,3FH,06H,3FH,08H,01H,00H ;01
;--------------------------------------------------------------;
ST3: MOV R5,#25; The branch road lights up green for 25 seconds, and the main road lights up red for 25 seconds
DIS3: MOV A,R5
JNZ NEXT3; If 25s has been reduced to 0, jump to the next state ST4
AJMP ST4
NEXT3: MOV A,#25
CLR C
SUBB A, R5 ; Subtract to get the time that has passed
MOV B,A
MOV A,#07H ; Get the jump offset from the table
I have AB
MOV DPTR,#TAB3
ADD A,DPL ; add offset
MOV DPL,A
MOV A,#00H
ADDC A, VAT
IOV VAT, A
MOV A, R4
JZ NOSP3 ; If the chirping time is not 0, chirp (negate p1.2), otherwise do not chirp
CPL P1.2
NOSP3: MOV A,#00H; Dynamic display, cycle lighting of digital tubes
MOV P0,#00H
MOV P2,#0FFH
MOVC A,@A+DPTR
MOV P0,A ; Display the unit digit of the branch
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F6H
MOVC A,@A+DPTR
MOV P0,A ; Display branch tens digit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F5H
MOVC A,@A+DPTR
MOV P0,A ; Display the main line unit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F4H
MOVC A,@A+DPTR
MOV P0,A ; Display the main road tens
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F2H
MOVC A,@A+DPTR
MOV P0,A; The following 3 outputs show the main branch lighting status
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F1H
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F0H
MOVC A,@A+DPTR
MOV P0,A
MOV P0,#00H
MOV P2,#0FFH
AJMP DIS3 ; Return to the start cycle and light up the digital tube
TAB3: DB 6DH,5BH,3FH,4FH,01H,00H,08H ;25
DB 66H,5BH,6FH,5BH,01H,00H,08H ;24
DB 4FH,5BH,7FH,5BH,01H,00H,08H ;23
DB 5BH,5BH,07H,5BH,01H,00H,08H ;22
DB 06H,5BH,7DH,5BH,01H,00H,08H ;21
DB 3FH,5BH,6DH,5BH,01H,00H,08H ;20
DB 6FH,06H,66H,5BH,01H,00H,08H ;19
DB 7FH,06H,4FH,5BH,01H,00H,08H ;18
DB 07H,06H,5BH,5BH,01H,00H,08H ;17
DB 7DH,06H,06H,5BH,01H,00H,08H ;16
DB 6DH,06H,3FH,5BH,01H,00H,08H ;15
DB 66H,06H,6FH,06H,01H,00H,08H ;14
DB 4FH,06H,7FH,06H,01H,00H,08H ;13
DB 5BH,06H,07H,06H,01H,00H,08H ;12
DB 06H,06H,7DH,06H,01H,00H,08H ;11
DB 3FH,06H,6DH,06H,01H,00H,08H ;10
DB 6FH,3FH,66H,06H,01H,00H,08H ;09
DB 7FH,3FH,4FH,06H,01H,00H,08H ;08
DB 07H,3FH,5BH,06H,01H,00H,08H ;07
DB 7DH,3FH,06H,06H,01H,00H,08H ;06
DB 6DH,3FH,3FH,06H,01H,00H,08H ;05
DB 66H,3FH,6FH,3FH,01H,00H,08H ;04
DB 4FH,3FH,7FH,3FH,01H,00H,08H ;03
DB 5BH,3FH,07H,3FH,01H,00H,08H ;02
DB 06H,3FH,7DH,3FH,01H,00H,08H ;01
;--------------------------------------------------------------;
ST4: MOV R5,#5; The main road lights up yellow for 5 seconds, and the branch road lights up red for 5 seconds
DIS4: MOV A,R5
JNZ NEXT4; if 5s has been reduced to 0, jump to the next state ST3
AJMP ST1
NEXT4: MOV A,#5
CLR C
SUBB A, R5 ; Subtract to get the time that has passed
MOV B,A
MOV A,#07H ; Get the jump offset from the table
I have AB
MOV DPTR,#TAB4
ADD A,DPL ; add offset
MOV DPL,A
MOV A,#00H
ADDC A, VAT
IOV VAT, A
MOV A, R4
JZ NOSP4 ; If the chirping time is not 0, chirp (negate p1.2), otherwise do not chirp
CPL P1.2
NOSP4: MOV A,#00H; Dynamic display, cycle lighting of digital tubes
MOV P0,#00H
MOV P2,#0FFH
MOVC A,@A+DPTR
MOV P0,A ; Display the unit digit of the branch
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F6H
MOVC A,@A+DPTR
MOV P0,A ; Display branch tens digit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F5H
MOVC A,@A+DPTR
MOV P0,A ; Display the main line unit
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2, #0F4H
MOVC A,@A+DPTR
MOV P0,A ; Display the main road tens
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F2H
MOVC A,@A+DPTR
MOV P0,A; The following 3 outputs show the main branch lighting status
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F1H
MOVC A,@A+DPTR
MOV P0,A
INC DPTR
MOV A,#00H
MOV P0,#00H
MOV P2,#0F0H
MOVC A,@A+DPTR
MOV P0,A
MOV P0,#00H
MOV P2,#0FFH
AJMP DIS4 ; Return to the start loop and light up the digital tube
TAB4: DB 6DH,3FH,6DH,3FH,01H,08H,00H ;05
DB 66H,3FH,66H,3FH,01H,08H,00H ;04
DB 4FH,3FH,4FH,3FH,01H,08H,00H ;03
DB 5BH,3FH,5BH,3FH,01H,08H,00H ;02
DB 06H,3FH,06H,3FH,01H,08H,00H ;01
;--------------------------------------------------------------;
;Timer interrupt service routine
TIMER1: MOV TH0,#3CH
MOV TL0,#10H
DJNZ R6,BACK
DEC R5
MOV R6,#20
MOV A, R4
JZ BACK
DEC R4
BACK: RETI
; Red light running external interrupt service routine
INTER: MOV R4,#5; External analog red light input, buzzer beeps for 5 seconds
RARELY
END
Previous article:Connection diagram of 51 MCU and NRF24L01 wireless module
Next article:51 MCU drives 74hc595 chip program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- ARM's strategic layout in the field of Internet of Things
- BearPi-HM Nano Development Board Review 1 Getting Started with Program Development
- 【GD32307E-START】Unboxing + Impressions of the board + Lighting ceremony
- Sequential logic circuit
- I have some doubts about SensorTile.box
- A novice needs help. When drawing PCB manual wiring in AD13.4, why can't I see the trace of the wiring before the wiring is completed?
- What are the important techniques for PCB wiring?
- Naming of Cadence Allegro 17.2 built-in pads
- Video: Talking about TI CC2650
- How stable is RT-Thread?