Saturday, 5 September 2015

Multiplexed Seven Segment Display interfacing with 8051

             We have already discuss basic about "single seven segment interface to 8051" in which seven segment is individually drive through 8 pin of microcontroller AT89S52. If we want to display two,three or more seven segment display using single MCU than there is problem that we face is lack of I/O pins in MCU, as one seven segment would take 8 I/O pin and four seven segment would take 28 I/O pins.That's why multiplexing technique is used to drive multiple seven segment display. In this tutorial i'll explain you how to interface multiple seven segment display to 8051.   
          Here we'll used "persistence of vision" to archive this multiplexing.This technique is used in cinematography to display images so fast that our brain cannot distinguish any lag between two consecutive images. Similarly, when we multiplex more than one seven segments, we display only one Seven segment at a time, and we switch between them so fast that our brain cannot distinguish between them.
            In multiplexing all the display are connected in parallel such that if you active any segment than the particular segment of all displays glow up.But we switch on and off the common line of segment very fast.

Circuit Diagram:

Multiplexed Seven Segment circuit diagram 

          In the above circuit all the similar segment of seven segment display are connected together and which is connected to the PORT0 of AT89S52 through current limiting resistors(R2 toR9).Particular segment is turn on when the corresponding pin of PORT0 is  high(1) because segment is common cathode.But it'll not glow until it's cathode is not connected to ground.But here cathode of the seven segments are not directly connected to ground.Three NPN (BC547) transistor is used as a switch to on and off the particular segment.Therefore, the transistor selects which displays is active at a time.Here base of all three transistor are connected to the P2.0, P2.1, P2.2 through base resistor don't forgot to put base resistor may your transistor stop working.Common line of segment is connected to ground when the logic high(1) is apply to the base of the transistor and disconnected when logic low(0) is apply to the base of transistor.

         Lets say each display is active for 10 milliseconds at time.It's light up 100 time in 1 second and our eyes can not sense this fast change.Now it's time to do this task in coding. 



sbit hundredth = P2^0;  

sbit tenth = P2^1;

sbit unit = P2^2;

const unsigned char seven[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
volatile unsigned int Select_digit = 0,Count=0;
unsigned char digits[4];
void delay(unsigned int msdelay)// Delay function 
unsigned int x,y;
void main (void)

TMOD=0X01;//Timer 0 in mode mode 16-bits mode
TH0=0XF0; //Load value for ~5ms(4.44ms) 
TR0=1;//Start timer 0
EA=1; //Enable globle interrupt  
ET0=1;//Enable timer overflow interrupt
Count++;//Increment count every ~1 sec
delay(1000);//Delay of ~1 sec
void Timer0_ISR() interrupt 1 //Timer0 ISR
    digits[0] = (Count/100);// hundredth
    digits[1] = ((Count%100)/10); // tenth   
    digits[2] = ((Count%100)%10); // unit
    hundredth=tenth=unit=0;//turn off all segment                  
    P2 =(((1<<Select_digit))); // turn on a one digit at time all others are turn off 
    P0 = seven[digits[Select_digit]]; // Select appropriate data than Send data to PORT2 and display  
    if(Select_digit==2) //if last digit than come to first digit
Select_digit++;  //Go to next digit      
TH0=0XF0; // Reload value for next interrupt

            In above code TIMER0 is used in 16-bit mode and timer interrupt is used to refresh our display.The timer interrupt is generated in predefined time and switch to next display and display the digit. TH0 and TL0 hold the value for ~5 millisecond so TIMER0 Interrupt is generated in every ~5 millisecond.The array digit[] is used to store the value of digit that we want to display.Here we used only three digits so array hold the value of these three digit.first of all hundredth digit is display at that time the transistor Q3 is turn on and Q1,Q2 is turn off after that switch to the next display to display tenth at that time Q2 is turn on and Q1,Q3 is turn off after that switch to next display to display unit at that time Q1 is turn on and Q2,Q3 turn off.One digit is turn on for only ~5 ms so 200 times/seconds.
          Here we used three digit so three switching is required to completely show the three digit number so the update frequency of display is 200/3 =  66.66Hz so the three number digits are show approximately 66 times/second.This is very fast so our eye can't catch up therefor we see all the three digits turn on simultaneously.
           Now friend it's your turn to make your own simple small projects, like counter,water level indicator etc. using this example. You can download complete project from below link.

I hope you found this useful,don't forgot to share this with your friends.


Multiplexed seven segment display interface with 8051 - Keil uVision 


No comments:

Post a Comment