Seven segment displays are used to indicate numerical information. Seven segments display can display digits from 0 to 9 and even we can display few characters like A, b, C, H, E, e, F, etc. These are very popular and have many more applications. So, in this project, I’ll show you how a 7 Segment Display works by interfacing 7 Segment Display to 8051 Microcontroller.
Before going to start this concept, get an idea about how to interface LEDs with 8051 Microcontroller.
This article describes you how to interface seven segment display to AT89C51 microcontroller. This system displays the digits from 0 to 9 continuously with a predefined delay. In the process, I’ll design two circuits: one circuit with a single digit 7 Segment Display and the other circuit consists of a 4-digit 7 Segment Display.
Outline
ToggleCircuit Principle
Seven segment displays internally consist of 8 LEDs. In these LEDs, 7 LEDs are used to indicate the digits 0 to 9 and single LED is used for indicating decimal point. Generally seven segments are two types, one is common cathode and the other is common anode.
Important Related Post – Water Level Indicator Project Complete Documentation
In common cathode, all the cathodes of LEDs are tied together and labeled as com. and the anode are left alone. In common anode, seven segment display all the anodes are tied together and cathodes are left freely. Below figure shows the internal connections of seven segment Display.
In the first circuit, I will interface a Common Cathode Single Digit 7 Segment Display to the 8051 Microcontroller while in the second circuit, I will interface a Common Anode type 4-Digit 7-Segment Display to the 8051 Microcontroller.
Circuit Diagram
Circuit 1: Interfacing 7 Segment Display to 8051 (Single Digit – CC)
In the first circuit, I am interfacing a Single Digit 7 Segment display with 8051. The 7-Segment Display is of common cathode type.
Circuit 2: Interfacing 7 Segment Display to 8051 (4-Digit – CA)
In the second circuit, I have interfaced a 4-digit 7-Segment Display to 8051 Microcontroller and the display type is of common anode.
Circuit Components
- AT89C51 Microcontroller
- AT89C51 Programming board
- Programming cable
- 12V DC battery or adaptor
- Common Cathode 7 segment Display
- Common Anode 4-Digit 7-Segment Display
- Resistors – 10KΩ X 2, 330Ω, 1KΩ X 8, 470Ω X 4
- 1KΩ X 8 Resistor Pack
- 33pF Ceramic capacitors x 2
- 11.0592 MHz crystal
- 10μF Electrolytic capacitor
- 2N2222 NPN Transistor X 4
- Push button
- Connecting wires
Also read the post – [How to Interface DC Motor with 8051 Microcontroller?]
Circuit Design
Circuit 1
Here, common cathode seven segment is used to display the digits. In this circuit, pins a to h of the 7 segment are connected to the PORT 2 of the microcontroller and com pin is connected to the ground through the 330 ohm resistor. This resistor is used to drop the voltage. Since we are using common cathode seven segment we need to send LOGIC 1 to the segments to glow.
Figure shows structure of common cathode seven segments. Here dot is used for indicating the decimal point. Here all the cathodes of LED’s are connected to the Gnd pin. The operating voltage of this LED’s is 2 to 3V but from controller we will get 5V so to drop the remaining voltage we have to connect a to g pins to the controller through the resistor.
Circuit 2
Since the 4-digit 7-Segment display used in the second circuit is of common anode type, we need to drive the LED segments through the common terminals. I have used 4 NPN Transistors to drive the 4 common anodes and the transistors are controlled by the 8051.
Coming to the segments a to h, they are connected to PORT0 Pins of 8051.
Digit Drive Pattern
To display the digits on 7 segment, we need to glow different logic combinations of segments. For example if you want to display the digit 3 on seven segment then you need to glow the segments a, b, c, d and g. The below table show you the Hex decimal values what we need to send from PORT2 to Display the digits from 0 to 9.
NOTE: These values are suitable only for a Common Cathode display. If you want to drive a Common Anode display, then you have to take the complement of each bit and replace the hexadecimal values in the code (which I have done in the code of the second circuit).
Algorithm
For Circuit 1
- First initialize all the segment hex values of the digits in an array.
unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
- Now take for loop and assign array values to the PORT2 with some time delay.
for (i=0;i<10;i++)
{
P2=arr[i];
delay_ms(500);
}
For Circuit 2
- First initialize all the segment hex values of the digits in an array.
unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}
2. As per the value, switch the digits.
void display (unsigned long int n)
{
led=ch[n/1000];
sw1=1;
sdelay(30);
sw1=0;
led=ch[(n/100)%10];
sw2=1;
sdelay(30);
sw2=0;
led=ch[(n/10)%10];
sw3=1;
sdelay(30);
sw3=0;
led=ch[n%10];
sw4=1;
sdelay(30);
sw4=0;
}
CODE
Code for Circuit 1 (Single Digit)
The code and the simulation files for the first circuit can be downloaded from this link: Download Project Code
Code for Circuit 2 (4-Digit)
Simulation Video of Circuit1
How to Operate?
- Initially burn the program to the microcontroller
- Give the connections as per the circuit diagram
- Make sure that a to g pins of 7 segment are connected to the P2.0 to P2.6 respectively in the first circuit and to PORT0 pins in the second circuit.
- Switch on the supply, you can observe that digits 0 to 9 will display continuously with some delay in the first circuit and digits from 0 to 9999 will display on 4-digit 7-segment display in the second circuit.
- Switch of the supply.
Project Output Video
Applications
- Seven segments are widely used in digital clocks to display the time.
- These are used in electronic meters for displaying the numerical information.
- Used in Instrument panels
- Used in digital readout displays.
Limitations
- The complexity is increased to display large information.
- It is not possible to display the symbols on seven segment.
17 Responses
Best website. It provide very important information regarding EMBEDDED SYSTEM . Well arranged articles with clean circuit diagrams.
Thank you so much for your wonderful feedback.
I want 4seng use the digital clk coding ,
Is it the same for a dual 7 seg display. It is a 5202BHG1-G 30
Could I get the code please!
I want to use the above project partly for my fourth year college project.
I need to get the code for the above project so as to get an idea on how to go about programming in microcontroller. And use it as dummy project.
I am using seven segment display to display information about to my customers. I’m not allowed to say anything more than this about my project.
Hope to get the codes as soon as possible.
Urgent.
Thank you.
i want to design the same project for for my third year mini project
code please
#include
void main()
{
unsigned char seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};
unsigned char x;
unsigned int i;
P1=0x00;
while(1)
{
for(x=0;x<10;x++)
{
P1=seg[x];
for(i=0;i<45000;i++)
{
}
}
}
}
are you sure for this code??
We had done this if u people had any idea about controlling seven segment display with switches and one more requirement is if switch one is pressed buzzer buzzes one time if 2 then 2 times
Where is the function delay used??
It is not used.
this video is help full for me but it is not that much use full can you
explain me how is the 4 seven segment is working(operating) at the same time?
like to display 666 we need to give control signal to each select line… how you will be giving the… control signal to 4 seven segment display?
reply ASAP because I am doing a project based on this.
I want to weighting scale program
Which Simulation program is used in this project?
Proteus