aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-08-11 22:59:00 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-08-11 22:59:00 +0000
commit6b6d46c3e1fa2c05aee87d84c197ea620efb7370 (patch)
tree0b72598ea83e7aaa3677ed5b4978ad52643d377c /cores/arduino
parent8dca3d5ad33b8ba7de070a0a0481ac9763c323a6 (diff)
Adding shiftIn() from Wiring (no count or delaytime though).
Diffstat (limited to 'cores/arduino')
-rwxr-xr-xcores/arduino/wiring.h3
-rwxr-xr-xcores/arduino/wiring_shift.c19
2 files changed, 19 insertions, 3 deletions
diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h
index d0ce1c3..6f61293 100755
--- a/cores/arduino/wiring.h
+++ b/cores/arduino/wiring.h
@@ -117,7 +117,8 @@ void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
-void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);
diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c
index 956f864..cfe7867 100755
--- a/cores/arduino/wiring_shift.c
+++ b/cores/arduino/wiring_shift.c
@@ -24,9 +24,24 @@
#include "wiring_private.h"
-void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
+uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
+ uint8_t value = 0;
+ uint8_t i;
+
+ for (i = 0; i < 8; ++i) {
+ digitalWrite(clockPin, HIGH);
+ if (bitOrder == LSBFIRST)
+ value |= digitalRead(dataPin) << i;
+ else
+ value |= digitalRead(dataPin) << (7 - i);
+ digitalWrite(clockPin, LOW);
+ }
+ return value;
+}
+
+void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
- int i;
+ uint8_t i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)