electroSome

Expanding Output Pins of a PIC Microcontroller through Multiplexing

PIC16F877A

Contents

Imagine that you want to control 100 LED’s with a PIC Microcontroller. No PIC Microcontroller with a DIP package having that many IO lines. This article explains two ways to expand output pins of a Microcontroller through multiplexing. Here we are using Time Division Multiplexing to expand output pins. The first method is by using D-Latch and second method is by using Serial in Parallel Out Shift register. In this tutorial we demonstrate the working by using 64 LEDs.

Using D Flip-Flop and Decoder

74574 Octal D Flip-Flop

This way of multiplexing uses Octal (8 – Bit) D Flip-Flop 74574 and 3-to-8 Decoder 74138. The D Flip-Flop serve as a memory to store a bit of data. So to control 64 LED we need 64 D Flip-Flops, that is eight 74574 chips. We give same data to D0 t0 D7 of all chips and each chip is enabled at different times. Thus we can individually set Logic LOW or HIGH to outputs of each chip.

The 74574 D Flip-Flop has the following pins.

When the Output Enable (OE)  pin is high all the output pin of 74574 will be in Logic LOW. When it is LOW the output follows the  input when a LOW to HIGH pulse occurs at Common Clock (CP) pin. In other cases the output follows the previous output, ie latched. We connect 8 output pins of pic microcontroller to the eight inputs (D0 – D7) of each chip. The Clock for each chip is given at different times.

IC 74138 3-to-8 Decoder

Next problem is that, we need 8 Output Pins to enable  each chip. This can be solved by using a 3-to-8 decoder ( IC 74138). It converts 3  lines to 8 (Y0 –  Y7). When the input is 000 the output Y0 will be activated (Y0- LOW, Other Outputs – HIGH), when it is 001 the output Y1 will be activated (LOW) and so on..

 

The 74138 has following pins..

 

We use the three output lines of PIC Microcontroller to select one of the 8 outputs. The chip will be enable only when its two active low enable inputs are at Logic LOW and the active high enable input is at Logic HIGH. All the output pins will be high when the chip is disabled.

 

Circuit Diagram

Expanding Output Pins of a PIC Microcontroller through Multiplexing

The following example MikroC Code works the above circuit as a Chaser.

MikroC Code

void main()
{
  int i,c;
  CMCON = 0x07; // To turn off comparators
  ADCON1 = 0x06; // To turn off analog to digital converters
  TRISB = 0x00;
  TRISC = 0x00;
  TRISD = 0x00;
  PORTD = 0x00;

  do
  {
    PORTB = 1;
    for(c = 0;c<=7;c++)
    {
      for(i=0;i<=7;i++)
      {
        PORTC = i;      //To Select a particular chip
        PORTD.F0 = 1;   // Enable 74138
        Delay_ms(20);   // To give a pulse with of 20ms
        PORTD.F0 = 0;   // Disable 74138
      }
      PORTB = PORTB<<1; // Left Shift
    }
  }while(1);
}

Please go to Next Page to read about Expanding Output pins using Serial-in-Parallel Out Shift Register.

Using Serial-in-Parallel Out Shift Register

Serial in Parallel Out Shift Register 74164

Here we use the IC 74164 an Eight Bit Serial-in-Parallel Out Shift register. The Data is given serially through one pin. To connect 64 LEDs we need eight 74164 chips. We are giving same clock to eight chips and different data input lines. Thus we need 8 Output pin for Data and 1 Output pin for Clock of the PIC Microcontroller. We can see that the pin number is reduced than in the previous method, but this method is a bit slower compared to the previous. The IC 74164 has the following pins.

Here we connect the data input pin A of each chip to an Output pin of  PIC Microcontroller and B is tied to Vcc (LOGIC HIGH). The Clock pin (CP) of each chip is tied together and connected to another output pin of PIC Microcontroller. Thus we can easily control the 64 LEDs very easily.

Circuit Diagram

Expanding Output Pins of a PIC Microcontroller through Multiplexing Alternate Method

 

The following example MikroC Code works the above circuit as a Chaser.

MikroC Code

void main()
{
  int j;
  CMCON = 0x07; // To turn off comparators
  ADCON1 = 0x06; // To turn off analog to digital converters
  TRISB = 0x00;
  TRISD = 0x00;
  PORTD = 0x00;

  do
  {
    PORTB = 0xFF;
    for(j=0;j<8;j++)
    {
      PORTD.F7 = 1;
      Delay_ms(50);
      PORTD.F7 = 0;
      PORTB = 0;
      Delay_ms(200);
    }
  }while(1);
}

Here you can download MikroC Code, Proteus Files, Circuit Diagrams etc..

Expanding Output Pins of a PIC Microcontroller

Exit mobile version