How to Multiplex Seven Segment Display with Microcontroller

Microcontroller Topics
Post Reply
User avatar
Shehani
Lieutenant
Lieutenant
Posts: 61
Joined: Mon Aug 19, 2013 2:11 pm

How to Multiplex Seven Segment Display with Microcontroller

Post by Shehani » Wed Sep 18, 2013 11:39 am

When a Seven Segment Display is interface with PIC Microcontroller it needs minimum 7 pins to display a value. But real time applications like Digital Clock, Calculator, Digital Watch requires 3-6 seven segment displays. Lets assume that we need 6 digit display, ie we need 7 segment * 6 Display = 42 pins. Thus we actually need Microcontroller with 42 output pins. This is waste and not economical to use lot of pins of a Microcontroller just for display.
1.jpg
1.jpg (11.55 KiB) Viewed 2447 times
The simplest way to drive Seven Segment Display is by using a driver or decoder and are available for up to 4 displays. Alternatively we can drive more than one Seven Segment Display by using a technique called ‘Multiplexing’. This technique is based on the principle of Persistence of Vision of our eyes. If the frames change at a rate of 25 ( or more) frames per second, human eye can’t detect that visual change. Each display is turned on above this rate and our eyes will think that the display is turned on for whole the time.

Circuit Diagram :
2.png
2.png (46.39 KiB) Viewed 2447 times
We have used Common Cathode Seven Segment Display in this example. Pins RB0 – RB6 are connected to the A – G of the display. This will count from 000 to 999.

MikroC Multiplexing Code:

Code: Select all

PORTB = Hex(s%10);
 PORTD.F2 = 1;
 Delay_ms(10);
 PORTD.F2 = 0;
 PORTB = Hex((s/10)%10);
 PORTD.F1 = 1;
 Delay_ms(10);
 PORTD.F1 = 0;
 PORTB = Hex((s/100)%10);
 PORTD.F0 = 1;
 Delay_ms(10);
 PORTD.F0 = 0;
Where ‘s’ is an unsigned integer which counts from 000 to 999 and ‘Hex’ is a user defined function which will return Seven Segment Decoded Hex of a single digit.

First we send data through the data port, then we enable corresponding display and a appropriate delay is given. It is better to adjust the delay according to the situation after making your project.

MikroC Seven Segment Decoding Function :

Code: Select all

unsigned int Hex(int a)
{
 switch(a)
 {
 case 1: return 0x06;
 case 2: return 0x5B;
 case 3: return 0x4F;
 case 4: return 0x66;
 case 5: return 0x6D;
 case 6: return 0x7D;
 case 7: return 0x07;
 case 8: return 0x7F;
 case 9: return 0x6F;
 case 0: return 0x3F;
 }
}
Article courtesy of electrosome.com
Post Reply

Return to “Microcontrollers”