Quantcast
Viewing all articles
Browse latest Browse all 215

7 segment Interfacing and Programming with 8051 Microcontroller

Image may be NSFW.
Clik here to view.
7-segment-display-interface-8051-microcontroller-common-cathode
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 segments with your 8051 microcontroller and how to program it to display numerical or characters.

TYPES OF 7 SEGMENT:

Image may be NSFW.
Clik here to view.
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.
Image may be NSFW.
Clik here to view.
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:

Image may be NSFW.
Clik here to view.
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.

  1. #include<stdio.h>
  2. #include<reg51.h>
  3. void delay(void);
  4. unsigned char array[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //Array for digits 0 to 9
  5. void main()                       //Main Program
  6.   {
  7.    while(1)
  8.     {
  9.       unsigned int i;
  10.       for(i=0;i<=10;i++)
  11.        {
  12.         P2=array[i];             //Sending hex values one by one
  13.         delay();
  14.        }
  15.     }
  16.   }
  17. void delay(void)              //Delay Function
  18.   {
  19.     unsigned int s,k;
  20.     for(s=0;s<400;s++)
  21.      {
  22.       for(k=0;k<200;k++);
  23.      }
  24.  }

NOTE:

  • For 7 Segment common anode displays you need to give logic 0 to the LED segments in order to light up.
  • 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.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 215

Trending Articles