Step 9: IO port expansion, alternative solution

Picture of IO port expansion, alternative solution
There is another solution for providing more output lines. We went with the latch based multiplexer because we had 8 latches available when building the LED cube.

You can also use a serial-in-parallel out shift register to get 64 output lines. 74HC164 is an 8 bit shift register. This chip has two inputs (may also have an output enable pin, but we will ignore this in this example).
  • data
  • clock
Every time the clock input changes from low to high, the data in Q6 is moved into Q7, Q5 into Q6, Q4 into Q5 and so on. Everything is shifted one position to the right (assuming that Q0 is to the left). The state of the data input line is shifted into Q0.

The way you would normally load data into a chip like this, is to take a byte and bit-shift it into the chip one bit at a time. This uses a lot of CPU cycles. However, we have to use 8 of these chips to get our desired 64 output lines. We simply connect the data input of each shift register to each of the 8 bits on a port on the micro controller. All the clock inputs are connected together and connected to a pin on another IO port.

This setup will use 9 IO lines on the micro controller.

In the previous solution, each byte in our buffer array was placed in it's own latch IC. In this setup each byte will be distributed over all 8 shift registers, with one bit in each.

The following pseudo-code will transfer the contents of a 64 bit buffer array to the shift registers.

// PORT A: bit 0 connected to shift register 0's data input, bit 1 to shift register 1 and so on.
// PORT B: bit 0 connected to all the clock inputs
// char buffer[8] holds 64 bits of data

for (i=0; i < 8; i++)

PORTB = 0x00; // Pull the clock line low, so we can pull it high later to trigger the shift register
PORTA = buffer[i]; // Load a byte of data onto port A
PORTB = 0x01; // Pull the clock line high to shift data into the shift registers.


This is perhaps a better solution, but we had to use what we had available when building the cube. For the purposes of this instructable, we will be using a latch based multiplexer for IO port expansion. Feel free to use this solution instead if you understand how they both work.

With this setup, the contents of the buffer will be "rotated" 90 degrees compared to the latch based multiplexer. Wire up your cube accordingly, or simply just turn it 90 degrees to compensate ;) 
zeevy10 months ago

I am going to use 74HC164, do i need to change the wiring to the cube or rotating the cube 90 degrees will just work?

mathieulj1 year ago
Shift registers can usually be chained up back to back so that you would only need data and clock no matter how many LEDs you have. Some even have an output latch so that your output doesn't change until you toggle an IO pin. Nice work though.
walmis3 years ago
you can use SPI peripheral to clock in data faster
Scerion walmis3 years ago
Yes I agree - I use SPI with a large LED Matrix and 20 shift registers driving 2304 LEDs ( actually 1152, but they are bi-color red/green so I shift in the red bytes for all rows first, then the green bytes ). SPI is much much faster than manual bit-banging. I worked out that it could run around 16000 LEDs at an acceptable frame rate with a 16mhz ATMega328 - but who would want to solder all those together? :-)

This is a great article though, and I'll be using this to make a cube soon!
david_jc084 years ago
no seria mejor usar un 74LS164N todos en seria y solo usar un puerto del pic???
ya que la salida 8 se conecta a los puertos a y b del siguiente 74LS164N ya que si introducimos mas de ocho bit estos los toma como dato de entrapa en siguiente integrado .De esta manera, encadenando varios de estos integrados podemos construir un registro de desplazamiento del largo que deseemos

Sí es posible encadenarlos de esa manera, la diferencia es que cargar todos los datos tomaría 8 veces más ciclos de trabajo y por tanto más tiempo. Pero si puedes trabajar lo suficientemente rápido puedes usar mucho menos puertos de salida del micro
kool-lites4 years ago
Where is the Code Example for this setup you mentioned in the test?