Multiplexing of Seven Segment Displays with PIC Microcontroller

Multiplexing of Seven Segment Displays with PIC Microcontroller

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.

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

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 Code

Multiplexing Code

 PORTB = Hex(s%10);
 PORTD.F2 = 1;
 PORTD.F2 = 0;
 PORTB = Hex((s/10)%10);
 PORTD.F1 = 1;
 PORTD.F1 = 0;
 PORTB = Hex((s/100)%10);
 PORTD.F0 = 1;
 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.

Decoding Function

unsigned int Hex(int 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;

Download Here

You can download MikroC Source Code, Proteus files etc here.

Share this post