ATtiny85 shiftout

From wikipost
Revision as of 03:32, 7 February 2012 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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++