Shop OBEX P1 Docs P2 Docs Learn Events
More outputs on a BS1 rev. D — Parallax Forums

More outputs on a BS1 rev. D

akudaikonakudaikon Posts: 10
edited 2006-05-05 14:15 in BASIC Stamp
I've had a BS1 rev. D for a couple years now and could never figure out what do with it. Now I have an idea for a project over the summer, but I've run into an issue. I have a limited knowledge of electronics right now, so i'm trying to come up with ways from what I know to overcome it. The basic stamp only has 8 input/output pins, but I need to be able to independantly control 27 different LEDs while leaving 1 or 2 pins open for inputs. I was thinking of using a demultiplexer, but I cannot find any 1:32 demultiplexers to do this. Does anyone have any ideas or solutions to this problem? I'm sure there is a simple solution to this.

Thanks in advance for the help!

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-02 02:11
    You could dasiy-chain four 74HC595's to get 32 outputs. Since there is no SHIFTOUT instruction you'll have to do it with code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • SSteveSSteve Posts: 808
    edited 2006-05-02 02:15
    You could use four 74HC595 shift registers with three pins. Download the StampWorks manual and check out experiment #23.

    Edit: I guess Jon and I were typing at the same time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • akudaikonakudaikon Posts: 10
    edited 2006-05-02 02:32
    Thanks for the quick replies!! I just looked at the stampworks manual and it gives a good explaination of how to do it.

    Thanks again for the help!!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-02 04:04
    Here's a·bit of code for sending data to a '595 with the BS1.· The byte to output is put in 'temp' and then the SHIFT_OUT subroutine is called:

    SYMBOL· SData·· = Pin0················· ' 74HC595 serial data· (14)
    SYMBOL· Clock·· = 1···················· ' 74HC595 shift clock· (11)
    SYMBOL· Latch·· = 2···················· ' 74HC595 output latch (12)

    SYMBOL· temp··· = B0··················· ' work variable for LCD routines
    SYMBOL· shift·· = B4··················· ' loop counter for SOut

    SHIFT_OUT:·····
    · FOR shift = 1 TO 8··················· ' shift 8 bits
    ··· SData = Bit7······················· ' MSB first
    ··· PULSOUT Clock, 1··················· ' clock the bit
    ··· temp = temp * 2···················· ' get next bit
    · NEXT
    · PULSOUT Latch, 1
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • akudaikonakudaikon Posts: 10
    edited 2006-05-04 23:56
    Thanks for the code! I didn't realize that BS1's didn't support SHIFTOUT so that will really help me out. I have another programming question for you though. I'm trying to come up with a way to generate unique random numbers within a range of numbers. For example, 4 unique random numbers within 1 to 10. The BS1 is so limited and i've been racking my brain for a long time now trying to think of a way to do it. Is there any solution or is it even possible to do?

    Thanks a lot again for the help!
  • akudaikonakudaikon Posts: 10
    edited 2006-05-05 11:19
    Nevermind. I thought of a way to do it. smile.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-05 14:15
    Here's how I usually do it -- let's say you want a random value between 5 and 30.· The code is:

    · target = rndValue // 26 + 5

    The divisor for modulus is the max value minus the min value plus one (30 - 5 + 1 = 26).· The reason for this is that the modulus operator always returns a value between zero and the divisor-1, so in the code above the modulus portion would always return a value between 0 and 25.· Then we add the minimum value to bias the output to it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.