Traffic light program in assembly language

Publisher:幸福如意Latest update time:2015-10-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   The traffic light program in assembly language uses a 51 single-chip microcomputer, which basically completes the control of two sets of traffic lights to light up alternately. Each intersection has three indicator lights: left turn, straight and pedestrian. The straight light has three colors: red, yellow and green. Non-motor vehicles and cars share the left turn and straight lights. First, the east-west straight green light and pedestrian light are on for 1 minute, the left turn light is on for 30 seconds, and the yellow light is on for 5 seconds (at the same time, the north-south red light is on for 95 seconds), then the east-west red light is on for 95 seconds (at the same time, the north-south straight green light and pedestrian light are on for 1 minute, the left turn light is on for 30 seconds, and the yellow light is on for 5 seconds), then the east-west green light is on, and so on.

   Every time the green light is on, the corresponding pedestrian light is on. 60S/30S/5S/60S/30S/5S
   East-West Road: Green and Pedestrians/Left Turn/Yellow/Red/Red/Red
   North-South Road: Red/Red/Red/Green and Pedestrians/Left Turn/Yellow
   When the pedestrian light is on, there is a voice prompt to let the blind pass. In case of a sudden traffic accident, the light can be turned to red. When an important person passes, the light can be changed to green manually.

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

Reference address:Traffic light program in assembly language

Previous article:AT89C52 MCU + AT24C02 + 1602 password lock
Next article:A simple single-chip traffic light program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号