Pages: [1]   Go Down
Author Topic: 74HC595: Getting code for 4 daisy chained 74HC595 to work  (Read 548 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I try to getting my code for 4 daisy chained 74HC595 to work.  The attached functions is for two 74HC595. I know that I need to shiftout 4 times, but what else do I need to change in the function? How can I split the whichPin integer into 4 bytes.

Thanks!

Code:
void registerWrite(int whichPin, int whichState) {
  // the bits you want to send. Use an unsigned int,
  // so you can use all 16 bits:
  unsigned int bitsToSend = 0;   

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // break the bits into two bytes, one for
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);

  // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);
}
Logged

France
Offline Offline
God Member
*****
Karma: 29
Posts: 898
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this:

http://bildr.org/2011/08/74hc595-breakout-arduino/

There is a little library at the bottom.

You can also use SPI: http://jumptuck.com/2011/11/03/how-to-drive-595-shift-registers-with-avr-hardware-spi/
« Last Edit: October 04, 2013, 06:11:42 pm by guix » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks smiley
Logged

Pages: [1]   Go Up
Jump to: