7 segment Interfacing with 8051 Microcontroller

Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest
7-segment-interfacing-with-8051-microcontroller
7 Segment Interface with 8051 Microcontroller

7 Segments are commonly used display devices which is capable of displaying numbers and some alphabets. It is more common in Embedded design applications where we needs to display some count or increment numerical values. This tutorial is focused to teach the interfacing of 7 segment interfacing with 8051 microcontroller and how to program it to display numerical or characters.

TYPES OF 7 SEGMENT:

common-anode-cathode-7-segment-display
Common anode and Common cathode Display

There are two types of 7 segment  one is Common Cathode and another one is common Anode. Both of them vary with their mode of connections and programming. As we all know that 7 segment is made of series of LED’s  aligned together to perform the function of display.

7-segment-common-anode-common-cathode-connections
Connection configuration of 7 segments

There is one common difference between these two segments, that is they both differ in power sourcing of LED’s in it. Common Anode segments are draw current directly from the power source using the Vcc pin and sink it using Microcontroller pins. But Common Cathode LED’s are sourced by pins of the microcontroller and sink by means of GND pin.

DISPLAYING NUMERICALS OR CHARACTERS IN 7 SEGMENT:

digit-display-7-segment-number-alphabet-programming
Digit formation in 7 Segment

In 7 segment the display of digits is done by means of turning on or turning off the LED’s in respective places. For example if we need to display the digit ‘0’ we need to enable LED’s  “a,b,c,d,e,f” , that is applying logic 1 or sourcing from microcontroller in case of Common cathode and applying logic 0 or sinking through pins in case of common anode. So for connecting 7 segment from P2.0 to a ………P2.7 to dp of 7 segment our hex code will be

0 – 0011 1111 – 0x3F

1 – 0000 0110 – 0x06

2 – 0101 1011 – 0x5B

Like this we can program to display any digits of our desire by feeding hex code to the ports of the Microcontroller.

 CODE:

The below code describes how to display 0 to 9 digits in the 7 segments with some specific time intervals between.

#include<stdio.h>
#include<reg51.h>
void delay(void);
unsigned char array[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //Array for digits 0 to 9
void main()                       //Main Program
  {
   while(1)
    {
      unsigned int i;
      for(i=0;i<=10;i++)
       {
        P2=array[i];             //Sending hex values one by one
        delay();
       }
    }
  }
void delay(void)              //Delay Function
  {
    unsigned int s,k;
    for(s=0;s<400;s++)
     {
      for(k=0;k<200;k++);
     }
 }

For 7 Segment common anode displays you need to give logic 0 to the LED segments in order to light up.

NOTE:

  • Modify the line 12 in the above program as P2=~array[i]; to make it work for common anode segment.
  • “~” sign will complement all the values to apply logic 0 at desired pins of the 7 segment.
Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest

Related Designs and Schematics

The following two tabs change content below.

Frank Donald

Junior Network Engineer at Tata Communications
Frank Donald is an Electronics and Communication Engineer who is very passionate about his subject. Reading, Surfing and Blogging are the things he loves.

Ask your query

Be the First to Comment!

Notify of
avatar
wpDiscuz