How to Interface 7 Segment Display with 8051

Introduction

Hi guys, in this article we will see how to interface 7 segment display with 8051 microcontroller.

Components Required

  • 8051 Microcontroller – 1
  • 8051 Program Dumper- 1
  • 7 Segment display – 1
  • Breadboard – 1
  • Jumper wires

seven segment consists of eight LEDs which are aligned in a manner so as to display digits from 0 to 9 when proper combination of LED is switched on. Seven segment uses seven LED’s to display digits from 0 to 9 and the eighth LED is used for the dot. A typical seven segment looks like as shown in the figure below. 

Seven Segment are available in two configuration – (1) Common Anode (2) Common Cathode.

Here common anode seven segment display is used because the output current of the microcontroller is not sufficient enough to drive the LED’s, similar to the case of driving an LED. The circuit diagram shows the connections of seven segment to the controller. The pins a to g of the Seven Segment are connected to the Port P2 of the microcontroller. The common pin of the seven segment is connected to Vcc. The  ‘h’  has not been used, which is the dot pin of the controller.

1. The Common Cathode (CC) – In the common cathode display, all the cathode connections of the LED segments are joined together to logic “0” or ground. The individual segments are illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to forward bias the individual Anode terminals (a-g).

Common Cathode 7-segment Display

2. The Common Anode (CA) – In the common anode display, all the anode connections of the LED segments are joined together to logic “1”. The individual segments are illuminated by applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the Cathode of the particular segment (a-g).

Common Anode 7-segment Display

DIGITAbcDefGHEX Value
000000010x40
110011110xF9
200100100x24
300001100x30
410011000x19
501001000x12
601000000x02
700011110xF8
800000000x00
900011000x10

In general, common anode displays are more popular as many logic circuits can sink more current than they can source. Also note that a common cathode display is not a direct replacement in a circuit for a common anode display and vice versa, as it is the same as connecting the LEDs in reverse, and hence light emission will not take place.

Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased. For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Then the various digits from 0 through 9 can be displayed using a 7-segment display as shown.

Driving a 7-segment Display

Although a 7-segment display can be thought of as a single display, it is still seven individual LEDs within a single package and as such these LEDs need protection from over current. LEDs produce light only when it is forward biased with the amount of light emitted being proportional to the forward current.

This means then that an LEDs light intensity increases in an approximately linear manner with an increasing current. So this forward current must be controlled and limited to a safe value by an external resistor to prevent damage to the LED segments.

The forward voltage drop across a red LED segment is very low at about 2-to-2.2 volts, (blue and white LEDs can be as high as 3.6 volts) so to illuminate correctly, the LED segments should be connected to a voltage source in excess of this forward voltage value with a series resistance used to limit the forward current to a desirable value.

Typically for a standard red coloured 7-segment display, each LED segment can draw about 15 mA to illuminated correctly, so on a 5 volt digital logic circuit, the value of the current limiting resistor would be about 200Ω (5v – 2v)/15mA, or 220Ω to the nearest higher preferred value.

So to understand how the segments of the display are connected to a 220Ω current limiting resistor consider the circuit below.

 

 

Driving a 7-segment Display

In this example, the segments of a common anode display are illuminated using the switches. If switch a is closed, current will flow through the “a” segment of the LED to the current limiting resistor connected to pin a and to 0 volts, making the circuit. Then only segment a will be illuminated. So a LOW condition (switch to ground) is required to activate the LED segments on this common anode display.

But suppose we want the decimal number “4” to illuminate on the display. Then switches b, c, f and g would be closed to light the corresponding LED segments. Likewise for a decimal number “7”, switches a, b, c would be closed. But illuminating 7-segment displays using individual switches is not very practical.

7-segment Displays are usually driven by a special type of integrated circuit (IC) commonly known as a 7-segment decoder/driver, such as the CMOS 4511. This 7-segment display driver which is known as a Binary Coded Decimal or BCD to 7-segment display decoder and driver, is able to illuminate both common anode or common cathode displays. But there are many other single and dual display drivers available such as the very popular TTL 7447.

This BCD-to-7 segment decoder/driver takes a four-bit BCD input labelled A, B, C and D for the digits of the binary weighting of 1, 2, 4and 8 respectively, has seven outputs that will pass current through the appropriate segments to display the decimal digit of the numeric LED display.

The digital outputs of the CD4511 are different from the usual CMOS outputs because they can provide up to 25mA of current each to drive the LED segments directly allowing different coloured led displays to be used and driven.

PIN DIAGRAM

CODE

#include<reg51.h>

sfr SEG=0XA0;

void Delay(unsigned int t)

{
	unsigned int i;
	while(t--)
for(i=0;i<1257;i++);
}

main()

{
unsigned char Val[10]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
//common anode
	int i;
	SEG=0X00;
	while(1)
	{
		for(i=0;i<10;i++)

		{
			SEG=Val[i];
			Delay(50);
		}
	}
}

Thanks for reading this article for any assistance or doubts comment below.

Download Code

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: