More ports with shift registers


To increase the number of output lines you can use shift registers using (and losing) only two pins of your Arduino.

Most people use the SN74HC595 for this purpose. The advantage of this chip is providing an RCLK to latch the contents of the shift register. If you don't need that feature an old SN74164 will do, having only 14 pins instead of 16.

If you run out of space on your breadboard you might even shorten your chips like this:

← original







← shortened
When you shorten you chips be extremly careful not to destroy them.
If you are afraid you might damage some of the logic functions of the chip have a close look at X-ray pictures like this.

So two of them will fit together with a TEXTDOL ZIF (zero insertion force) socket on a 30x10 breadboard.

Using 2 SN74164 gives you 16 lines which is more than enough to control all the address lines (wires not shown in this photograph) of a memory chip.


Arduino color SN74164
+5V red VCC, pin 14
ground black ground, pin 7
d13 SCK (serial clock) green CLK, pin 8
d11 MOSI yellow A and B, pins 1+2

If you are cascading two (or more) SN74164 chips pin 13 (QH) of the predecessor goes to pins 1+2 (A and B) of the successor while clock goes to all the shift registers.


To control the transmission to the shift register(s) you can either use the SPI library or do everything by yourself as I did.
By doing this you save some 500 bytes of FLASH memory.

#define FILENAME "SPI1a"

// data: Pin-11, clock: Pin-13

void setup() {
  Serial.begin(9600);
  Serial.println(FILENAME);
  DDRB = B00101100; // set SCK + MOSI + SS to OUTPUT
  SPCR = B01010000; // SPI enable + Master Select
}

void loop() {
  for (word i = 0; i < 65535; i++) {
    transmit(i);
    delayMicroseconds(10);
  }
}

void transmit(word w) {
  SPDR = highByte(w);
  while ( (SPSR & B10000000) != B10000000);
  byte dummy1 = SPDR;  
  SPDR = lowByte(w);
  while ( (SPSR & B10000000) != B10000000);
  byte dummy2 = SPDR;
}



contact: nji(at)gmx.de