Question on Shift Registers
Don J
Posts: 12
I have built an Amateur radio repeater controller and have all but run out of pins on my BS2.
I want to add a couple more peripheral devices and need more outputs.
Hence, I need a Shift Register.
What I have to be able to do is control each output "bit" independently.
Example: %01111110, bits 1 & 8 are "0" and bits 2-7 are "1".
Say I want to change bit 2 to a "0" but do not want to send data to bits 1 and 3-8,
I want them to stay at their current state, whatever that might be.
This is due to the fact that their states could be constantly changing and I would not know
what their state is at the time of bit 2 being changed.
Now after much research I believe this is how that portion of the code should look and
this is were I need the help to confirm that.
SHIFTOUT 0, 1, MSBFIRST, [noparse][[/noparse](0 >> 7)\1]
Here's why I think this is the proper code.
First of all 0 is the dec/binary conversion for %0.
Second I am using the right-shift operator "with 7" to choose bit "2" to be changed.
Third 1 is for a single bit to be sent.
Someone Please educate me!
Thanks,
Don
Post Edited (Don J) : 3/28/2007 5:41:58 PM GMT
I want to add a couple more peripheral devices and need more outputs.
Hence, I need a Shift Register.
What I have to be able to do is control each output "bit" independently.
Example: %01111110, bits 1 & 8 are "0" and bits 2-7 are "1".
Say I want to change bit 2 to a "0" but do not want to send data to bits 1 and 3-8,
I want them to stay at their current state, whatever that might be.
This is due to the fact that their states could be constantly changing and I would not know
what their state is at the time of bit 2 being changed.
Now after much research I believe this is how that portion of the code should look and
this is were I need the help to confirm that.
SHIFTOUT 0, 1, MSBFIRST, [noparse][[/noparse](0 >> 7)\1]
Here's why I think this is the proper code.
First of all 0 is the dec/binary conversion for %0.
Second I am using the right-shift operator "with 7" to choose bit "2" to be changed.
Third 1 is for a single bit to be sent.
Someone Please educate me!
Thanks,
Don
Post Edited (Don J) : 3/28/2007 5:41:58 PM GMT
Comments
Have a look at the datasheet for the 74HC595.
There are addressable latches that will let you update one bit at a time, but these require more I/O pins and you wouldn't be using SHIFTOUT to update them.
Thanks for your reply.
I understand now that if I keep a shift register status on the stamp and then
send all 8-bits to the register, that will accomplish what I want to do.
Example:
pattern VAR Byte
pattern = %01111110
My question now is how to change bit 2 from 1 to 0, without
having to know the current state of the other 7 bits.
pattern = ????????
Thanks,
Don
Look in the Stamp manual for suffixes like ".BIT0", ... , ".BIT7". You could change bit 2 of pattern by setting "pattern.bit2 = 0".
Just ran a test and this is exactly what I was looking for.
Thanks again, I'm back to forward progress.
Don