Go Down

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

tms8c8

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)) );
   }
   else{
     digitalWriteDirect( ulDataPin, !!(ulVal & (1 << (7 - i))) );
   }
   digitalWriteDirect( ulClockPin, HIGH );
   MNOP(6);
   digitalWriteDirect( ulClockPin, LOW );
   MNOP(6);
 }
 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).

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

fungus

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