Expanding Output Pins of a PIC Microcontroller through Multiplexing

Expanding Output Pins of a PIC Microcontroller through Multiplexing

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
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.

  • Eight Inputs (D0 – D7)
  • Eight Outputs (Q0 – Q7)
  • Common Clock (CP)
  • Output Enable (OE – Active Low)

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
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..

  • Three Inputs (A, B, C)
  • Eight Outputs (Y0 – Y1, active Low)
  • Three Enables (2 – active low and 1 – active high)

 

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
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.

Share this post


>