Shop OBEX P1 Docs P2 Docs Learn Events
Question on Shift Registers — Parallax Forums

Question on Shift Registers

Don JDon J Posts: 12
edited 2007-03-28 18:37 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-28 16:47
    You can't do that with a shift register. You really have to reload the whole thing. It's not hard if you have a byte variable available that can hold the current status of the shift register. You change one (or more) bits of that variable, then send the 8-bit byte to the shift register. The 74HC595 works fine for this. You use SHIFTOUT to send the updated byte, then use a third pin to copy the shift register to the output latches in the chip so all of them get updated at once.

    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.
  • Don JDon J Posts: 12
    edited 2007-03-28 17:50
    Mike,
    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-28 18:08
    Don,
    Look in the Stamp manual for suffixes like ".BIT0", ... , ".BIT7". You could change bit 2 of pattern by setting "pattern.bit2 = 0".
  • Don JDon J Posts: 12
    edited 2007-03-28 18:14
    Thanks Mike !
  • Don JDon J Posts: 12
    edited 2007-03-28 18:37
    Mike,

    Just ran a test and this is exactly what I was looking for.
    Thanks again, I'm back to forward progress.

    Don
Sign In or Register to comment.