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.  

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 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. DigitDpgfedcbaHex value 0001111110x3f 1000001100x06 2010110110x5b 3010011110x4f 4011001100x66 5011011010x6d 6011111010x7d 7000001110x07 8011111110x7f 9011001110x67
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

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; for (i=0;i<10;i++)                         {                                     P2=arr[i];                                     delay_ms(500);                         }

For Circuit 2

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?

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.

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. while(1) { for(x=0;x<10;x++) { P1=seg[x]; for(i=0;i<45000;i++) { } } } } Comment * Name * Email * Website

Δ

Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 75Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 38Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 60Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 18Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 26Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 6Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 81Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 48Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 83Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 73Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 78Interfacing 7 Seven  Segment Display to 8051 Microcontroller - 71