Pages: [1]   Go Down
Author Topic: Manipulating Shift Registers - Set a Single Bit But Leave the Rest?  (Read 586 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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).
« Last Edit: February 08, 2013, 07:48:29 pm by tms8c8 » Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 517
Posts: 26294
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Shift in the new pattern you want - only the outputs that are different will change when the Latch pin updates the output register.
Logged

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.

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 142
Posts: 5290
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

Pages: [1]   Go Up
Jump to: