Go Down

Topic: Manipulating Shift Registers - Set a Single Bit But Leave the Rest? (Read 685 times) previous topic - next topic


So I've got two 74HC595N shift registers that I am controlling. I would like to read  a value from an array and turn on a single pin while leaving the rest unchanged. I'd like to do this as fast as possible.

Currently, I have the following function defined (where digitalWriteDirect allows for direct port manipulation and "oldValue" is globally defined) but the problem is I'd like to control two separate banks of shift registers. This method doesn't distinguish between values written to different data pins.

Code: [Select]
void shiftOutFast( uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal )
 uint8_t i ;
 ulVal = ulVal | oldValue;
 for ( i=0 ; i < 8 ; i++ ){
   if ( ulBitOrder == LSBFIRST ){
     digitalWriteDirect( ulDataPin, !!(ulVal & (1 << i)) );
     digitalWriteDirect( ulDataPin, !!(ulVal & (1 << (7 - i))) );
   digitalWriteDirect( ulClockPin, HIGH );
   digitalWriteDirect( ulClockPin, LOW );
 oldValue = ulVal;

I mean, I could always write a separate function for each data pin but that just seems silly. Basically, I've got an array that is 100 columns and it has three rows. Row 0 - 1 are the bytes of data (corresponding to "addresses") and row 2 is the data pin to be written to. I want to turn on all of LEDs but in an arbitrary order (as opposed to just shifting a 1 down in order).


Shift in the new pattern you want - only the outputs that are different will change when the Latch pin updates the output register.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


You have to send 8 bits to the shift register each time you want to change an output. There's no way around that.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

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