As explained earlier, a seven segment interfaced with PIC uses almost an entire port (minimum 7 pins) to display a value. But a real time application, like watch, calculator etc., usually requires at least 3-4 seven segments. In such a case it is not advisable to use a port of the controller for each seven segment. In these cases, multiplexing technique is used to work with more than one seven segment. Here multiplexing of four seven-segments has been explained with PIC18F4550 to display four-digit count from 0000 to 9999.
The data pins (a-g) of all the seven-segments are connected to a single port (Port D*) as shown in the circuit diagram. Transistors BC547 are connected to COM pins of seven-segment for switching. The switching of COM pins is controlled by four pins of PortA.
Project Source Code
###
// Program for Seven segment multiplexing using PIC18F4550 Microcontroller
// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
#define seg_port LATD
#define seg_unit LATA.F0
#define seg_decade LATA.F1
#define seg_hundred LATA.F2
#define seg_thousand LATA.F3
unsigned int i=0,j=0,k=0;
void main(void)
{
unsigned int value[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned int count,num0,num1,num2,num3,num4;
TRISA=0; // Configure PortA as output port
LATA=0;
TRISD=0; // Configure PortD as output port
LATD=0;
for(count=0;count<9999;count++) // Counter from 0 to 9999
{
num0=count;
num1=num0%10; // Extract the value of unit digit
num0=num0-num1;
num0=num0/10;
num2=num0%10; // Extract the value of decade digit
num0=num0-num2;
num0=num0/10;
num3=num0%10; // Extract the value of hundred digit
num0=num0-num3;
num0=num0/10;
num4=num0%10; // Extract the value of thousand digit
num0=num0-num4;
num0=num0/10;
for(i=0;i<10;i++) // Delay= ((5msx4)x10) = 200ms between two consecutive counts
{
seg_unit=1;seg_decade=0;seg_hundred=0;seg_thousand=0; // Display unit digit
seg_port=value[num1];
Delay_ms(5);
seg_unit=0;seg_decade=1;seg_hundred=0;seg_thousand=0; // Display decade digit
seg_port=value[num2];
Delay_ms(5);
seg_unit=0;seg_decade=0;seg_hundred=1;seg_thousand=0; // Display hundred digit
seg_port=value[num3];
Delay_ms(5);
seg_unit=0;seg_decade=0;seg_hundred=0;seg_thousand=1 // Display thousand digit
seg_port=value[num4];
Delay_ms(5);
}
}
}
###
Circuit Diagrams
Project Components
Project Video
Source: Seven Segment Multiplexing using PIC18F4550 Microcontroller