ORG 0000H ; Main program entry address
LJMP MAIN ; Jump to the beginning of the main program
ORG 0003H ; External interrupt 0 interrupt program entry address
ORG 000BH ; Timer 0 interrupt program entry address
LJMP T0_INT ; Jump to the interrupt service program
ORG 0013H ; External interrupt 1 interrupt program entry address
MAIN : MOV SP,#50H
MOV IE,#8EH ; CPU interrupt, enable T0 interrupt, T1 interrupt and external interrupt 1 interrupt
MOV TMOD,#51H ; Set T1 to counting mode, T0 to timing mode, and both work in mode 1
MOV TH1,#00H ; Clear T1 counter http://www.5imcu.net/sylyuan.asp
MOV TL1,#00H
SETB TR1 ; Start T1 timer
SETB EX1 ; Enable INT1 interrupt
SETB IT1 ; Select edge trigger mode
MOV DPTR ,#0003H
MOV A, #80H ;Assign initial value to 8255, 8255 works in mode 0
MOVX @DPTR, A
AGAIN: JB P3.1,N0 ;Judge whether to set the initial value of the east-west direction traffic light time, if P3.1 is 1, jump
MOV A,P1
JB P1.7,RED ;Judge whether P1.7 is 1, if it is 1, set the red light time, otherwise set the green light time
MOV R0,#00H ;R0 is cleared
MOV R0,A ;Store the initial time of the east-west direction green light http://www.5imcu.net/sylyuan.asp
MOV R3,A
LCALL DISP1
LCALL DELAY
AJMP AGAIN
RED: MOV A,P1
ANL A,#7FH ;P1.7 is set to 0
MOV R7,#00H ;R7 is cleared
MOV R7,A ;Store the initial time of the red light in the east
-west direction
MOV R3,A
LCALL DISP1
LCALL DELAY
AJMP AGAIN
;----------------------------------
N0: SETB TR0 ;Start T0 timer
MOV 76H,R7 ;Store the red light time in 76H N00: MOV A,76H ;Prohibit the east-west direction, allow the north-south direction
MOV R3,A
MOV DPTR,#0000H ;Set 8255A port, the red light in the east-west direction is on, and the green light in the north-south direction is on
MOV A,#0DDH
MOVX @DPTR, A
N01: JB P2.0,B0
N02: SETB P3.0
CJNE R3,#00H,N01 ;Compare the value in R3 to see if it is 0, if not, jump to the current instruction to execute
;------Program for the yellow light flashing for 5 seconds------
N1: SETB P3.0
MOV R3,#05H
MOV DPTR,#0000H ; Set 8255A port, the yellow light in the east-west and north-south directions is on
MOV A,#0D4H
MOVX @DPTR,A
N11: MOV R4,#00H
N12: CJNE R4,#7DH,$ ; The yellow light stays on for 0.5 seconds N13: MOV DPTR,#0000H ; Set 8255A port, the yellow light in the north
-south direction is off
MOV A,#0DDH
MOVX @DPTR,A
N14: MOV R4,#00H
CJNE R4,#7DH,$ ; The yellow light stays off for 0.5 seconds
CJNE R3,#00H,N1 ; Exit when the flashing time reaches 5 seconds
;-----------------------------------
N2: MOV R7,#00H
MOV A,R0 ; East-west traffic is allowed, north-south traffic is prohibited
MOV R3,A
MOV DPTR,#0000H ; Set port 8255A, green light on in east-west direction, red light on in north-south direction
MOV A,#0EBH
MOVX @DPTR,A
N21: JB P2.0,T03
N22: CJNE R3,#00H,N21
;------Yellow light flashes for 5 seconds program------
N3: MOV R3,#05H
MOV DPTR,#0000H ; Set 8255A port, east-west, north-south direction yellow light is on
MOV A,#0E2H
MOVX @DPTR,A
N31: MOV R4,#00H
CJNE R4,#7DH,$ ;Yellow light stays on for 0.5 seconds
N32: MOV DPTR,#0000H ; Set 8255A port, north-south direction yellow light is off
MOV A,#0EBH
MOVX @DPTR,A
N33: MOV R4,#00H
CJNE R4,#7DH,$ ;Yellow light stays off for 0.5 seconds
CJNE R3,#00H,N3 ; Exit
SJMP N00 when the flashing time reaches 5 seconds
;------Red light running alarm program------
B0: MOV R2,#03H ;Alarm duration is 3 seconds
B01: MOV A,R3
JZ N1 ;If the countdown is completed, no more alarm
CLR P3.0 ;Alarm
CJNE R2,#00H,B01 ;Judge whether 3 seconds are over
SJMP N02
;------1 second delay subroutine-------
N7: RETI
T0_INT:MOV TL0,#9AH ;Send the initial value of 10ms to timer T0
MOV TH0,#0F1H
INC R4
INC R5
CJNE R5,#0FAH,T01 ;Judge whether the delay is enough for one second, if not, call the display subroutine
MOV R5,#00H ;R5 clears
DEC R3 ;Countdown initial value minus one DEC
R2 ;Alarm initial value minus one
T01: ACALL DISP ;Call display subroutine
RETI ;Interrupt return
;------Display subroutine------
DISP: JNB P2.4,T02
DISP1: MOV B,#0AH
MOV A,R3 ;Display conversion of value 2 to 10 in R3
DIV AB
MOV 79H,A
MOV 7AH,B
DIS: MOV A,79H ;Display tens digit
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV DPTR,#0002H
MOVX @DPTR,A
MOV DPTR,#0001H
MOV A,#0F7H
MOVX @DPTR,A
LCALL DELAY
DS2: MOV A,7AH ;Display ones digit
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV DPTR,#0002H
MOVX @DPTR,A
MOV DPTR,#0001H
MOV A,#0FBH
MOVX @DPTR,A
RET
;------Traffic flow detection program in the east-west direction------
T03: MOV A,R3
SUBB A,#00H ;If the green light countdown is completed, the traffic flow will no longer be detectedhttp ://www.duankudp.com/
JZ N3
JB P2.0,T03
INC R7
CJNE R7,#64H,E1
MOV R7,#00H ;If the interruption reaches 100 times, clear
E1: SJMP N22
;------Traffic flow display program in the east-west direction------
T02: MOV B,#0AH
MOV A,R7 ;R7 median value 2 to 10 display conversion
DIV AB
MOV 79H,A
MOV 7AH,B
DIS3: MOV A,79H ;Display tens digithttp ://www.duankudp.com/
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV DPTR,#0002H
MOVX @DPTR,A
MOV DPTR,#0001H
MOV A,#0F7H
MOVX @DPTR,A
LCALL DELAY
DS4: MOV A,7AH ;display units digit
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV DPTR,#0002H
MOVX @DPTR,A
MOV DPTR,#0001H
MOV A,#0FB H
MOVX @DPTR,A
LJMP N7
;------delay 4MS subroutine----------
DELAY: MOV R1,#0AH
LOOP: MOV R6,#64H
NOP
LOOP1: DJNZ R6,LOOP1
DJNZ R1,LOOP
RET
;------Character table------
TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
END
Previous article:AT89C52 MCU + AT24C02 + 1602 password lock
Next article:A simple single-chip traffic light program
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- msp430f149 baud rate setting
- Application of STM32F03X serial port idle interrupt + DMA
- Bought a very good ESP32-S2 development board
- What is the IC model of infrared remote control transmitter?
- Image frequency suppression measurement
- NUCLEO_G431RB Review - CRC Calculation
- Please help me explain this circuit schematic, how it works, and where each module is.
- How to use printf for debugging
- Comparison between Internal PA and External FEM
- When studying (100 examples of single-chip C language programming practice), I encountered a problem with undefined identifiers. Please tell me how to solve it!