This tutorial will show how to control multiple LED outputs from a microcontroller using an STP16C596 shift register. The STP16C596 is similar to the popular 74HC595 shift register, but it’s nicer because it can sink a constant current to the LEDs it’s driving. It works slightly differently, however, so this code won’t work exactly for the ’595.
This is a stub. More explanation will follow, but for now, here are schematics and code for Arduino.
Parts you’ll need:
- STP16C596 shift register
- Arduino microcontroller
- LEDs
- 1-kilohm resistor
The Circuit
The code
/*
Shift Register Example
for ST16C596 shift register
This sketch turns on each of the LEDs attached to a ST16C596 shift register,
in sequence from output 0 to output 15.
Hardware:
* ST16C596 shift register attached to pins 2, 3, and 4 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register
Created 22 May 2009
Modified 23 Mar 2010
by Tom Igoe
see http://www.tigoe.net/pcomp/code/category/arduinowiring/534 for more
*/
//Pin connected to latch pin (LE) of ST16C596
const int latchPin = 4;
//Pin connected to clock pin (CLK) of ST16C596
const int clockPin = 3;
////Pin connected to Data in (SDI) of ST16C596
const int dataPin = 2;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
Serial.println("reset");
}
void loop() {
// intialize a 16-bit integer (unsigned, to use all 16 bits)
// that will hold all the states of the outputs:
unsigned int outputStates = 0;
// loop over the 16 positions of the shift register,
// turning on each one in sequence:
for (int thisPosition = 0; thisPosition < 16; thisPosition++) {
// take the latch pin low while shifting bits out:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in outputStates:
bitWrite(outputStates, thisPosition, HIGH);
// since shiftOut() shifts out a byte, separate
// outputStates into two bytes, the high byte
// and the low byte:
byte highPins = highByte(outputStates);
byte lowPins = lowByte(outputStates);
// shift the two bytes out:
shiftOut(dataPin, clockPin, MSBFIRST, lowPins);
shiftOut(dataPin, clockPin, MSBFIRST, highPins);
// take the latch pin high at the end of
// shifting:
digitalWrite(latchPin, HIGH);
// delay before turning on next LED:
delay(250);
}
}


