LED 7-Segment Multiplexing

One digit requires 7 connections (wires) for all segments and 1 connection for common cathode (or anode). If I connect 6 digits to the MCU without any modification, I will need 7-segment x 6 digit = 42 connections . That means I need to use MCU with atleast 42 I/O pins. As you know, it is a waste for using a lot of MCU pins just for display. The required pins can be reduced dramatically by using a technique called Multiplexing.

Multiplexing

Multiplexing technique is based on the idea of Persistence of vision of the human eyes. The sample schematic of 3 digits multiplexing is shown below. Segment a-g of each digit are connected together. Each digit is switched on-off by controlling signal at Digit 1, Digit 2 and Digit 3. For example, if Digit 1 is ‘1’ , Digit 1 will be on. If Digit 1 is ‘0’, Digit 1 will be off. People will see all 3 digits display in the same time if each digit switch on and off fast enough.

multiplexing-3digit

3 Digits Multiplexed Schematic

By using multiplexing technique the number of required connections for 6 digits display is reduced from 42 pins to 7-Segment+6 digits = 13 pins Wow!! I can drive 6 digits 7-segment display by using just a PIC16F627A.

Programming

Multiplexing implementation is very similar to driving Led Dot Matrix. I use Timer0 interrupt for switching through each digit. Timer0 or TMR0 is an 8-bit timer which overflows every 256 (0xFF) counts. It’s known that the refresh rate above 50Hz would be enough for human’s eyes to see the display without recognizing the flickering. If I set TMR0 with 1:8 Prescaler, the multiplexing frequency will be

4MHz(internal OSC.)/4(working OSC)/8(prescaler)/256(max counts of TMR0)/6(number of digits) = 81.3 Hz which is good for a display.

Just an example, I have implemented (in Proteus) a 999999-second counter by using 6 Digits LED 7-Segment Multiplexing technique. There are 2 main components in the project, PIC16F627A or PIC16F628 and 6 x LED7-segment display. The schematic shows below. The crystal is 32.768KHz as usual. There is a 10KOhm pull up resistor at RA4 pin as this pin is an open-drain.

999999 counter schematic

999999 counter schematic

Sourcecode for MikroC…

//PIC16F627A
//4MHz Internal OSC
//MUX by the MUC itself with Interrupt
//TMR0 .. check the prescelar+delay in scan routine as they are related
//punkky@gmail.com
unsigned short number [10] = {
0x5F0x060x9b0x8f0xC60xCd, 0xDD0x07,
0xDf, 0xCf
};
unsigned short digit [6];
unsigned short counter;
unsigned short shift_register;
unsigned short x1;
unsigned short x2;
unsigned short x3;
unsigned short x4;
unsigned short x5;
unsigned short x6;
unsigned short tick;
void interrupt ()
{
if (INTCON.T0IF)
{
//Scan digits with TMR0
INTCON.T0IF0;
if (counter == 5)
{
PORTAnumber [digit [counter]];
Delay_us (500);
shift_register0x01;
PORTB = ~shift_register;
PORTA0x00;
counter0;
else
{
PORTAnumber [digit [counter]];
Delay_us (500);
shift_registershift_register << 1;
PORTB = ~shift_register;
PORTA0x00;
counter ++;
}
}
if (PIR1.TMR1IF)
{
TMR1H0x80;
PIR1.TMR1IF0;
tick1;
//update current time
x6 ++;
if (x69)
{
x60;
x5 ++;
if (x59)
{
x50;
x4 ++;
if (x49)
{
x40;
x3 ++;
if (x39)
{
x30;
x2 ++;
if (x29)
{
x20;
x1 ++;
if (x19)
{
x10;
}
}
}
}
}
}
}
}
void main ()
{
//Digital I/O for PORTA
CMCON0x07;
TRISA0x00;
PORTA0x00;
TRISB0x00;
PORTB0x00;
//Internal Clock 4MHz
PCON.OSCF1;
counter0;
// Enable TMR0
OPTION_REG.T0CS0;
// Enable Prescaler
OPTION_REG.PSA0;
// PS0,1,2 = 010 = 3
// 3 means 1:8 prescaler
// 1:2, 1:4, 1:8, 1:16, 1:32, 1:64, 1:128, 1:256
OPTION_REG.PS20;
OPTION_REG.PS11;
OPTION_REG.PS00;
INTCON.T0IF0;
INTCON.T0IE1;
INTCON.GIE1;
INTCON.PEIE1;
T1CON0x0F;
TMR1H0x80;
TMR1L0x00;
// Enable TMR1 interrupt
PIE1.TMR1IE1;
shift_register0x01;
x10;
x20;
x30;
x40;
x50;
x60;
while (1)
{
if (tick)
{
tick0;
//update digits
digit [0] = x1;
digit [1] = x2;
digit [2] = x3;
digit [3] = x4;
digit [4] = x5;
digit [5] = x6;
}
}
}

Comments are closed.