0% found this document useful (0 votes)
18 views

Lecture #09

The document describes using an 8051 microcontroller to control three traffic lights, with each light having a green period of 3 seconds. It includes a flow chart and assembly code to implement the traffic light control.

Uploaded by

Abdo Hesham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lecture #09

The document describes using an 8051 microcontroller to control three traffic lights, with each light having a green period of 3 seconds. It includes a flow chart and assembly code to implement the traffic light control.

Uploaded by

Abdo Hesham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Electrical Engineering Department

Benha Faculty of Engineering


Benha University

Microprocessors and
Microcontrollers E1328
#Lecture_09
Dr. Mahmoud Adel Hassan,
Ph.D. Degree in Engineering Sciences in
Electrical Engineering,
Email: [email protected]
# 8th Semester 2022/2023
Outline
➢Example : Traffic Lights
• Example:-
Using MC 8051, write an assembly code to manage three traffic lights. For each one green LED
is on for 3 sec.

Apply Hardware wiring,

Draw Flow Chart.


The flow chart for this program is shown in figure

Initialize O/P Delay for


Port P2 & P3 3 Sec

Set O/Ps P2.0 Set O/Ps P2.2


P2.4&P3.0 only P2.3&P2.7 only

Delay for Delay for


3 Sec 3 Sec

Set O/Ps P2.1


P2.5&P2.6 only
Delay for 1 msec Delay for 1 sec
DELAY: MOV R6,#250D DELAY1: MOV R5,#250D
LABEL: ACALL DELAY
MOV R7,#250D ACALL DELAY
ACALL DELAY
LABEL1: DJNZ R6,LABEL1
ACALL DELAY
LABEL2: DJNZ R7,LABEL2 DJNZ R5,LABEL
RET
RET DELAY: MOV R6,#250D
MOV R7,#250D
LOOP1: DJNZ R6,LOOP1
LOOP2: DJNZ R7,LOOP1
RET
Assembly Code for MC 8051
Org 0000h M2: ACALL DELAY Loop: DJNZ R1,Loop
MOV P2,#00H DJNZ R2,M2 DJNZ R0,L1
MOV P3,#00H MOV P2,#00h RET
LIGHTS: SETB P2.0 MOV P3,#00h END
SETB P2.4 SETB P2.2
SETB P3.0 SETB P2.3
MOV R2,#20 SETB P2.7
M1: ACALL DELAY MOV R2,#20
DJNZ R2,M1 M3: ACALL DELAY
MOV P2,#00h DJND R2,M3
MOV P3,#00h MOV P2,#00h
SETB P2.1 MOV P3,#00h
SETB P2.5 LJMP LIGHTS
SETB P2.6 DELAY: MOV R0,#250D
MOV R2,#20 L1: MOV R1,#250D

You might also like