Interfacing 7 (Seven) Segment Display To 8051 Microcontroller
Interfacing 7 (Seven) Segment Display To 8051 Microcontroller
org)
8051 Microcontroller (https://www.electronicshub.org/free-project-circuits/embedded/8051/), Electronics
(https://www.electronicshub.org/free-project-circuits/electronics/), Embedded (https://www.electronicshub.org/free-project-
circuits/embedded/), Free Project Circuits (https://www.electronicshub.org/free-project-circuits/), Mini Projects
(https://www.electronicshub.org/free-project-circuits/mini-projects-list/)
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
(https://www.electronicshub.org/8051-microcontroller-introduction/).
Before going to start this concept, get an idea about how to interface LEDs with 8051
Microcontroller (/led-interfacing-8051/).
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 (https://www.electronicshub.org/bcd-7-segment-led-
display-decoder-circuit/).
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 1 of 21
:
Outline
Circuit 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 (/water-
level-indicator/)
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.
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 2 of 21
:
(https://www.electronicshub.org/wp-content/uploads/2014/07/Internal-
connections-of-seven-segment.jpg)
Internal Connections of Seven Segment
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
In the first circuit, I am interfacing a Single Digit 7 Segment display with 8051. The 7-Segment
Display is of common cathode type.
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 3 of 21
:
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.
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 4 of 21
:
Circuit Components (https://www.electronicshub.org/basic-
electrical-circuits-componentstypes/)
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 (https://www.electronicshub.org/best-resistor-kits/)
33pF Ceramic capacitors x 2
11.0592 MHz crystal
10μF Electrolytic capacitor
2N2222 NPN Transistor X 4
Push button
Connecting wires
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 5 of 21
:
Also read the post – [How to Interface DC Motor with 8051 Microcontroller (/interfacing-dc-
motor-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.
(https://www.electronicshub.org/wp-
content/uploads/2014/07/Common-cathode-7-segment-
Display.jpg)
Common cathode 7 segment Display
Circuit 2
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 6 of 21
:
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.
HEX
DIGIT DP G F E D C B A
VALUE
0 0 0 1 1 1 1 1 1 0x3f
1 0 0 0 0 0 1 1 0 0x06
2 0 1 0 1 1 0 1 1 0x5b
3 0 1 0 0 1 1 1 1 0x4f
4 0 1 1 0 0 1 1 0 0x66
5 0 1 1 0 1 1 0 1 0x6d
6 0 1 1 1 1 1 0 1 0x7d
7 0 0 0 0 0 1 1 1 0x07
8 0 1 1 1 1 1 1 1 0x7f
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 7 of 21
:
9 0 1 1 0 0 1 1 1 0x67
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
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};
2. 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
1. 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}
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 8 of 21
:
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;
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 9 of 21
:
CODE
(https://www.electronicshub.org)
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 (https://www.electronicshub.org/wp-
content/uploads/2015/12/Interfacing-7-segment-display-with-8051.rar)
1 #include<reg51.h>
2 #define led P0
3 sbit sw1=P2^0;
4 sbit sw2=P2^1;
5 sbit sw3=P2^2;
6 sbit sw4=P2^3;
7 unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
8 //void delay (int);
9 void display (unsigned long int);
10 void sdelay (char);
11
12 /*void delay (int d)
13 {
14 unsigned char i;
15 for(;d>0;d--)
16 {
17 for(i=250;i>0;i--);
18 for(i=248;i>0;i--);
19 }
20 }*/
21
22 void sdelay (char d)
23 {
24 for(;d>0;d--);
25 }
26
27 void display (unsigned long int n)
28 {
29 led=ch[n/1000];
30 sw1=1;
31 sdelay(30);
32 sw1=0;
33
34 led=ch[(n/100)%10];
35 sw2=1;
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 10 of 21
:
36 sdelay(30);
37 sw2=0;
38
39 led=ch[(n/10)%10];
40 sw3=1;
41 sdelay(30);
42 sw3=0;
43
44 led=ch[n%10];
45 sw4=1;
46 sdelay(30);
47 sw4=0;
48 }
49
50 void main()
51 {
52 unsigned long int i=1;
53
54 while(1)
55 {
56 i=++i;
57 display(i);
58 if(i==9999)
59 i=0;
60 }
61 }
hub.com/elktros/80c5aefc16a9cb68767d3d9393c96945/raw/bf3ee9f9c341d6af553aa336ba88f10b2c63f7db/8051_7_Segment_Interface_4_Digit.c)
8051_7_Segment_Interface_4_Digit.c (https://gist.github.com/elktros/80c5aefc16a9cb68767d3d9393c96945#file-
8051_7_segment_interface_4_digit-c) hosted with by GitHub (https://github.com)
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 11 of 21
:
Seven Segment Display Interfacing with 8051 Microcontroller
How to Operate?
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 12 of 21
:
7 Segment Display Interfacing to 8051 Microcontroller
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.
Related Posts:
Arduino 7 Segment Display Interface (https://www.electronicshub.org/arduino-7-segment-
display-interface/)
Arduino 4-Digit 7-Segment LED Display (https://www.electronicshub.org/arduino-4-digit-7-
segment-led-display/)
7 Segment Display Pinout (https://www.electronicshub.org/7-segment-display-pinout/)
2 Digit Up/Down Counter Circuit (https://www.electronicshub.org/2-digit-up-down-counter/)
8 Channel Quiz Buzzer Circuit using Microcontroller (https://www.electronicshub.org/8-
channel-quiz-buzzer-circuit-using-microcontroller/)
Interfacing LED with 8051 (https://www.electronicshub.org/led-interfacing-8051/)
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 13 of 21
:
17 Responses
Best website. It provide very important information regarding EMBEDDED SYSTEM . Well
arranged articles with clean circuit diagrams.
Reply
Reply
muru says:
Reply
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 14 of 21
:
Jon elias says:
Reply
John says:
Reply
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.
Reply
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 15 of 21
:
chand says:
i want to design the same project for for my third year mini project
Reply
code please
Reply
#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++)
{
}
}
}
}
Reply
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 16 of 21
:
UAE ABDUU says:
Reply
Amar says:
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
Reply
Thilak says:
Reply
Ravi says:
It is not used.
Reply
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 17 of 21
:
Bala Gokul says:
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.
Reply
Rajeev says:
Reply
Reply
Proteus
Reply
Leave a Reply
Your email address will not be published. Required fields are marked *
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 18 of 21
:
Comment *
Name *
Email *
Website
Post Comment
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 19 of 21
:
(htt (htt
ps:// ps:// (htt
ww ww ps://
w.fa (htt w.yo ww
(https://www.electronicshub.org)
ceb p://t utu w.in
ook. witt be.c stag
comer.c om/ ram.
/ele om/ user com
ctro
Get
eh_ /ele /eh
Our Latest Newletters
nics org) ctro _or
Get Great Contentnics
hub. g/)
That You Love.
No Ads Or Spams,hub
We Promise.
org)
org)
General
Projects
Projects
Tutorials
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 20 of 21
:
About Advertise with us
(https://www.electronicshub.org/about/)
Contact
(https://www.electronicshub.org/contact/)
Affiliate Disclosure(https://www.electronicshub.org/affiliate-disclosure/)
Disclaimer(https://www.electronicshub.org/disclaimer/)
Terms and Conditions(https://www.electronicshub.org/terms-and-conditions/)
Privacy Policy(https://www.electronicshub.org/privacy-policy/)
https://www.electronicshub.org/interfacing-7-segment-display-8051/ 5/12/24, 11 35 PM
Page 21 of 21
: