Microcontroller based Traffic light systems was one of the basic project that one can do with a microcontroller to understand its concepts and working.In this post i would like to share the hardware and program code of a Traffic light controller with you all.Here in the above circuit you can see that we are using a seven segment to display as a counter and three LED's to perform the traffic lights operation.The crystal we are using is of 4MHz crystal and the Microcontroller was AT89C52.
The LED's was connected in a common anode mode so that the Microcontroller was used as a sink here.The Red color was made to flash for 10 seconds and yellow, green were assigned glow for five seconds each.The resistor values for LED's should be of 470 ohm and to the 7 segment should be around 1K.
COMMON CATHODE 7 SEGMENT: The above circuit uses a Common cathode 7 segment which have some unique characterstics.As you can see in the above 7 segment pin configuration that there is two common GND and LED's are connected in a Common cathode manner.That is when ever the pin was mde high the corrsponding LED will glow.If the pin was low the corresponding LED will go into off state.This was the working of the 7 segment.In the traffic light systems circuit the a,b,c,d ...h pins of the 7 segment was arranged in order so i have connected it in a continuous manner.While you are connecting the 7 segment to the Microcontroller you have to connect the port pin P2.0 to the pin a of the 7 segment then P2.1 to b, P2.3 to c it goes on and ends up to pin h.This is the way that the hardware should be constructed and now lets move into the programming part of the Microcontroller.
PROGRAM:
The program code was developed in Embedded C language and was done in Archimedes IDE 8051 software.The code of the above system was given below.
- #include<stdio.h>
- #include<reg51.h>
- void delay(void);
- void dat(void);
- void dat1(void);
- unsigned char a[10]={0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06,0x3f}; //Assigning arrays for lighting up the 7 segment in reverse order from 9 to 0
- unsigned int i,j,s,k; //Assigning integers
- void main()
- {
- P0=0xfe; //Giving 1111 1110 to port 0 making red light to flash.
- {
- dat(); //calling dat function
- P2=0x00; //Switching 7 segment off after one operation
- }
- P0=0xfd; //Giving 1111 1101 to port 0 to make yellow light to flash
- {
- dat1(); //calling out dat1 function to display numbers from 4 to 0
- P2=0x00;
- }
- P0=0xfb; //Giving 1111 1011 to port 0 to make green light ON.
- {
- dat1();
- P2=0x00;
- }
- }
- void dat(void)
- {
- for(i=0;i<=10;) //Calling out the array from 0 to 10
- {
- P2=a[i]; //Giving the array elements to Port 2
- i++; //Incrementing array elements
- delay(); //Calling out delay function
- }
- }
- void dat1(void)
- {
- for(i=5;i<=10;) //Calling out the array elements from 5 to 10.
- {
- P2=a[i];
- i++;
- delay();
- }
- }
- void delay(void) //function for creating delay by means of increment
- {
- for(s=0;s<=200;s++)
- {
- for(k=0;k<238;k++);
- }
- }
The #include files of the program includes the registry files of the 8051 Microcontroller.The program was classified into four sections which is
- "void main"
- "void dat"- Array for the numbers to display while the red light is ON.
- "void dat1"-Array for the numbers to display while the yellow and Green light is ON.
- "void delay"-Program to generate delay between the numbers displayed in 7 segment.
Post in your comments and queries below.I will assist you with further explanations in case you need it.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.![]()
Image may be NSFW.Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.