Shift1 cascading support

This commit is contained in:
flo
2012-02-06 09:25:32 +01:00
parent 750fc7b712
commit 32a9ba26d4
2 changed files with 18 additions and 16 deletions
+16 -14
View File
@@ -106,26 +106,25 @@ void fio_shiftOut1_init(fio_register shift1Register, fio_bit shift1Bit){
fio_digitalWrite(shift1Register,shift1Bit,HIGH);
delayMicroseconds(300);
}
void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value){
void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch){
/*
* this function are based on Shif1 protocol developed by Roman Black (http://www.romanblack.com/shift1.htm)
*
* test sketches:
* http://pastebin.com/raw.php?i=2hnC9v2Z
* http://pastebin.com/raw.php?i=bGg4DhXQ
* http://pastebin.com/raw.php?i=tg1ZFiM5 - flickering neighbor
* http://pastebin.com/raw.php?i=tg1ZFiM5
* tested with:
* TPIC6595N - seems to work fine (circuit: http://www.3guys1laser.com/arduino-one-wire-shift-register-prototype)
* 7HC595N - flickering neighbor
* 7HC595N
*/
// disable interrupts since timing is going to be critical
uint8_t oldSREG;
oldSREG = SREG;
cli();
// iterate but ignore last bit (is it correct now?)
for(int8_t i = 7; i>=1; --i){
for(int8_t i = 7; i>=0; --i){
// assume that pin is HIGH (smokin' pot all day... :) - requires initialization
if(LOW==!!(value & (1 << i))){
@@ -144,19 +143,22 @@ void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value
//hold pin HIGH for 15us
delayMicroseconds(15);
}
if(!noLatch && i==1) break;
}
if(!noLatch){
// send last bit (=LOW) and Latch command
fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
// Hold pin low for 200us
delayMicroseconds(199);
fio_digitalWrite_HIGH(shift1Register,shift1Bit);
// Hold pin high for 300us and leave it that way - using explicit HIGH here, just in case.
delayMicroseconds(299);
}
// send last bit (=LOW) and Latch command
fio_digitalWrite_SWITCHTO(shift1Register,shift1Bit,LOW);
// Hold pin low for 200us
delayMicroseconds(199);
fio_digitalWrite_HIGH(shift1Register,shift1Bit);
// Hold pin high for 300us and leave it that way - using explicit HIGH here, just in case.
delayMicroseconds(299);
// enable interrupts
SREG = oldSREG;
}
void fio_shiftOut1(uint8_t pin, uint8_t value){
fio_shiftOut1(fio_pinToOutputRegister(pin, SKIP),fio_pinToBit(pin),value);
void fio_shiftOut1(uint8_t pin, uint8_t value, boolean noLatch){
fio_shiftOut1(fio_pinToOutputRegister(pin, SKIP),fio_pinToBit(pin),value, noLatch);
}
+2 -2
View File
@@ -142,7 +142,7 @@ void fio_shiftOut(fio_register dataRegister, fio_bit dataBit, fio_register clock
* @param shift1Bit[in] pins bit
* @param value[in] value to shift out, last byte is ignored and always shifted out LOW
*/
void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value);
void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch = false);
/*!
* @method
* @abstract one wire shift out
@@ -150,7 +150,7 @@ void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value
* @param pin[in] digital pin
* @param value[in] value to shift out, last byte is ignored and always shifted out LOW
*/
void fio_shiftOut1(uint8_t pin, uint8_t value);
void fio_shiftOut1(uint8_t pin, uint8_t value, boolean noLatch = false);
/*!
* @method
* @abstract initializes one wire shift out protocol