ATtiny85 shiftout

From wikipost
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

In an attempt to port some code originally written for Arduino I came across a function that doesn't seem to be supported on AVR-GCC. I hope I just haven't found the library yet but in any case, here's some code to produce the same function.

#define HIGH 1
#define LOW  0

void shiftOut(byte dataPin, byte clockPin, byte bitOrder, byte value)
{

  int i;

  for (i = 0; i < 8; i++)  
  {
            
    if (bitOrder == LSBFIRST) 
    {
      digitalWrite(dataPin, !!(value & (1 << i)));
    } else {
      digitalWrite(dataPin, !!(value & (1 << (7 - i))));
    }

    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
                
  }

} 

See also:

http://arduino.cc/en/Reference/ShiftOut

C and C++