Shift Register. A little confused.
PoundSign2
Posts: 129
Hello friends! I would like to incorporate a shift register with my Propeller, however I am unsure how the code should look. All I'm after is to understand how I can use the shift register with the Propeller and how I go about programming it in SPIN. My shift registers are the SN74HC595. Do I set a pin to send the latch high every, for this example, 5 seconds, and send data through the clock within those 5 seconds? I'm just confused how I use this amazing IC.
Comments
Note: As I've been (fairly) accused of spoon-feeding newcomers, I'm not doing that any more. You'll need to study this a bit (use the data sheets), and setup your program with appropriate constants.
BTW... when I worked for Parallax I wrote a book called StampWorks. It has a whole chapter on using the 74x595 -- it would be useful study material.
SPI Assembly - Serial Peripheral Interface
http://obex.parallax.com/object/564/
·
SPI Spin - Serial Peripheral Interface
http://obex.parallax.com/object/566
I'll try to mess with the aforementioned code by JohnnyMac. That really gave me an understanding. Although Do you have to do...
In order to latch the bit/s? Is there a more, how do I say it...'better'...way to do this? Like auto-latch every so often or once 8 bits have been configured?
On the 74HC595 once the correct number of bits have been shifted out (8 bits per device, which can be daisy-chained) the latch line must be pulsed. That code effectively does that. On a 74HC165 you would pulse the latch line prior to reading the bits in.
BTW.. before you call that code snippet, make sure you set the clock and latch pins to output/low state. The data pin should be an input.
8-bit byte before shifting the 8 bits out?
To set bit3 of myValue it's as easy as:
myValue := wr_bit(myValue, 3, 0)
Of course, you don't have to use my method; you can set and clear manually
myValue |= 1 << 3
or...
myValue &= !(1 << 3)
Like most programming languages, Spin is fairly flexible.