INTERFACING SEVEN SEGMENT DISPLAY WITH 89c51


Seven segment displays are important display units in Electronics and widely used to display numbers from 0 to 9. It can also display some character alphabets like A,B,C,H,F,E etc.It just consists 8 LEDs, each LED used to illuminate one segment of unit and the 8th LED used to illuminate DOT in 7 segment display.
There are two types of 7 segment displays: Common Anode and Common Cathode:
Common Anode: In this all the Negative terminals (cathode) of all the 8 LEDs are connected together (see diagram below), named as COM. And all the positive terminals are left alone.
Common Cathode: In this all the positive terminals (Anodes) of all the 8 LEDs are connected together, named as COM. And all the negative thermals are left alone.

For constructing the truth table , listing the 7 display input signals, decimal number and corresponding 4 digit binary numbers.The truth table for the decoder design depends on the type of 7-segment display. Here we consider a common cathode seven-segment display, the output of decoder or segment driver must be active high in order to glow the segment.

Program 1: Displaying 0-9 in seven segment display

Code:

#include<reg51.h>
void delay(int);
void main()
{
  while(1)
  {
    P3=0XFC;
    delay(500);
    P3=0X60;
    delay(500);
    P3=0XDA;
    delay(500);
    P3=0XF2;
    delay(500);
    P3=0X66;
    delay(500);
    P3=0XB6;
    delay(500);
    P3=0XBE;
    delay(500);
    P3=0XE0;
    delay(500);
    P3=0XFF;
    delay(500);
    P3=0XF6;
    delay(500);
   }
}
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<100;j++);
}

simulation:


Download code Here

Program 2:Displaying 0-99 in seven segment display

Code:
#include<reg51.h>
void delay(int);
void main()
{
 int a[10]={0XFC,0X60,0XDA,0XF2,0X66,0XB6,0XBE,0XE0,0XFE,0XF6},k,l,m;
 while(1)
 {
  
  for(k=0;k<10;k++)
  {
   for(l=0;l<10;l++)
   {
    for(m=0;m<20;m++)
    {
           P2=0X80;
           P3=a[k];
           delay(5);
           P2=0X40;
           P3=a[l];
           delay(200);
    }
   }
  }
 }
}
void delay(int n)
{
 int i,j;
 for(i=0;i<n;i++)
 for(j=0;j<10;j++);
}
   

simulation:



Download code Here




Comments

Popular posts from this blog

INTERFACING OF LCD WITH 89C51

THE LOOP CONTROL STRUCTURE