From d677719d0ef0f8ad831a8859aceefc0c3dcb57e7 Mon Sep 17 00:00:00 2001 From: Philip Howard Date: Tue, 10 Jul 2012 22:43:51 +0100 Subject: [PATCH] Experimental shiftOutWithDelay --- wiringPi/wiringShift.c | 33 +++++++++++++++++++++++++++++++++ wiringPi/wiringShift.h | 1 + 2 files changed, 34 insertions(+) diff --git a/wiringPi/wiringShift.c b/wiringPi/wiringShift.c index 68c5faf..3682b22 100644 --- a/wiringPi/wiringShift.c +++ b/wiringPi/wiringShift.c @@ -82,3 +82,36 @@ void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) digitalWrite (cPin, LOW) ; } } + + +/* + * shiftOut: + * Shift data out to a clocked source + ********************************************************************************* + */ + +void shiftOutWithDelay (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val, uint8_t delay) +{ + int8_t i; + + if (order == MSBFIRST) + for (i = 7 ; i >= 0 ; --i) + { + digitalWrite (dPin, val & (1 << i)) ; + delayMicroseconds (delay) ; + digitalWrite (cPin, HIGH) ; + delayMicroseconds (delay) ; + digitalWrite (cPin, LOW) ; + delayMicroseconds (delay) ; + } + else + for (i = 0 ; i < 8 ; ++i) + { + digitalWrite (dPin, val & (1 << i)) ; + delayMicroseconds (delay) ; + digitalWrite (cPin, HIGH) ; + delayMicroseconds (delay) ; + digitalWrite (cPin, LOW) ; + delayMicroseconds (delay) ; + } +} diff --git a/wiringPi/wiringShift.h b/wiringPi/wiringShift.h index d723c5f..79c0fa6 100644 --- a/wiringPi/wiringShift.h +++ b/wiringPi/wiringShift.h @@ -35,6 +35,7 @@ extern "C" { extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ; extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ; +extern void shiftOutWithDelay (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val, uint8_t delay) ; #ifdef __cplusplus }