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

Traffic Controller

The document describes a program to control traffic lights using an 8051 microcontroller with C programming. LEDs are connected to ports P0 and P1 to represent the traffic lights. The program cycles through 5 cases - with the west, north, east, south lights turning green individually while the others remain red, before all lights turn red. The C code uses a while loop to repeatedly load the port registers with hex codes to turn the appropriate LED on for each case, with delay functions in between. The experiment aims to demonstrate real-time microcontroller applications and develop 8051 programming skills.

Uploaded by

sharada
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views

Traffic Controller

The document describes a program to control traffic lights using an 8051 microcontroller with C programming. LEDs are connected to ports P0 and P1 to represent the traffic lights. The program cycles through 5 cases - with the west, north, east, south lights turning green individually while the others remain red, before all lights turn red. The C code uses a while loop to repeatedly load the port registers with hex codes to turn the appropriate LED on for each case, with delay functions in between. The experiment aims to demonstrate real-time microcontroller applications and develop 8051 programming skills.

Uploaded by

sharada
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Program 4: Traffic

Controller
8051 Microcontroller Programming in C
Problem definition:

Write 8051 C program to interface Traffic Controller.


Objective of Program:
Road traffic control involves directing vehicular and
pedestrian traffic around a circle, square, construction
zone, accident or other road disruption.

In the laboratory, simulated environment is created.

Embedded systems can be used for traffic controller.


Need and Application of concept:
• Ensuring the safety of the general public, vehicles,
emergency response teams and construction workers.

• Saving life and property.

• Demonstaration of 8051 microcontroller with C


programming, for real-time & real-life situation.
Theoretical background:
LEDs are connected as follows, with port P0 & P1, which should be loaded with appropriate
hex codes.
Flow of process:
1. West lamp is green, all other lamps red
2. Moving clock-wise, next north becomes green & all others
red
3. Again turn clock-wise, east turns green & other lamps red
4. At last, turn clock-wise, south becomes green & others red.
5. For pedestrians to allow, next, all lamps turn red
Case 1: west open, all closed
Case 2: north open, all closed
Case 3: east open, all closed
Case 4: south open, all closed
Case 5: all closed, red LEDs all four
All the Hex code – listed:
  Instructions used:
• Port number loaded with hex code (LED glows = 1, LED off = 0)
P0=0x58;
• infinite while … do loop
while(1)
{ …
}
• delay function
for(i=0;i<35000;i++);
Algorithm:
1. include file
2. declare delay function
3. main function
4. while loop:
5. load port with 58 hex
6. load port with 01 hex
7. call delay, appropriately.
8. repeat steps 5,6,7 – with codes 54, 04, 12, 05, 41, 05, 50, 05.
9. delay function
10. infinite loop continues from steps 5 to 8
Code (8051 program in C):
#include<at89c51xd2.h> P0=0x50;
delay();
void delay(void); delay(); P1=0x05;
delay();
unsigned int i;
P0=0x12; delay();
void main() P1=0x05; }
{ while(1) }
delay();
{ P0=0x58; delay();
P1=0x01; void delay(void)
P0=0x41; {
delay();
P1=0x05; for(i=0;i<35000;i+
delay(); +);
P0=0x54; delay(); for(i=0;i<35000;i+
delay();
P1=0x04; +);
}
Learning outcome of experiment:
• Design and write the C programs for computing / IO /
logical tasks using 8051 Microcontroller.
[L3]
Program Outcome of this course
(POs)
PO1:
Graduates will demonstrate the knowledge of
mathematics, basic sciences, logical reasoning and
engineering.
… ThanQ

You might also like