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.
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).