Difference between revisions of "ATtiny85 shiftout"

From wikipost
Jump to navigationJump to search
(No difference)

Latest revision as of 13:32, 7 February 2012

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:


C and C++