Thursday, 13 August 2015

Interfacing Seven Segment Display to 8051

       Hi friends in this tutorial i'll explain you how to interface single seven segment display to 8051 micro-controller.You just need to some basic knowledge of seven segment display and 8051 programming.If your are newbie to seven segment display than you can learn basic about seven segment display from my older post about seven segment display.You can learn all about seven segment display from this post.
         Now we interface common anode seven segment display with AT89S52. I already describe basic about common anode display.

Circuit Diagram

         Here,common anode display is used to display digit 0 to 9 and some time used to display alphabets A to F,dot is use to display decimal point.Show in circuit diagram pin a to g of seven segment is connected to the port P2 of AT89S52 microcontroller through the current limiting resistors R2 to R9(330R) and common pin is connected to the Vcc(5V).Make sure that a to g pins of 7 segment are connected to the P2.0 to P2.6 respectively.Since we are using common anode seven segment display so we need to send logic-0 to the particular segment to glow. 

Seven segment interface circuit diagram


           Now we display digit on seven segment we need to illuminated different logic combination of  segments.For example if you want to display digit 4 on seven segment than you need to glow b,c,f and g segments,take another example if  you want to display digit 7 than you need to glow a,b and c.The below truth table show you hex decimal values to display digit 0 to 9 on common anode seven segment.And we need to send this hex value from the port P2 to seven segment.   


Truth table common anode seven segment

Embedded C code:


#include<reg51.h>

#define Seven_segment_port P2 //Seven segment a to g is connected to the port P2

unsigned char Seven_segment[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//Initialize aray of hex values.



void delay_ms(unsigned int ms)//this function generate delay of ms milliseconds 

{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<127;j++);
}
void main()
{
unsigned int count=0;
while(1)
{
for(count=0;count<10;count++)
{
Seven_segment_port = Seven_segment[count];//send hex values of digits to port P2
delay_ms(1000);//~1sec delay 
}
}
}

    In above code Seven_segment_port is define for port P2 and Seven_segment is the array which holds the hex values of digits 0 to 9.Digits display on seven segment continuously one by one with ~1 sec delay.You can download complete project code from below link.


Downloads:


2 comments:

  1. I have read so many articles on the topic of the blogger lovers however this post is actually a fastidious article, keep it up.

    Gifts

    ReplyDelete