Go Down

Topic: 74HC595: Getting code for 4 daisy chained 74HC595 to work (Read 742 times) previous topic - next topic



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.


Code: [Select]
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);


Oct 05, 2013, 01:09 am Last Edit: Oct 05, 2013, 01:11 am by guix Reason: 1
Read this:


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/

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131