Shop OBEX P1 Docs P2 Docs Learn Events
Need help using input switches and other stuff (For theater set at school) — Parallax Forums

Need help using input switches and other stuff (For theater set at school)

Tech-ManTech-Man Posts: 100
edited 2007-11-11 16:14 in BASIC Stamp
First,

I need to figure out how to use my BS1 for something but when I went to connect it to my computer it dose not identify. I have Vista and I got the USB driver installed. So I'm guessing it's something else. Worse comes to worse ill just code on another computer.

Second,

I'm a stage tech for our school theater. Were building a set right now with lighted steps, so when he steps on a step it lights then when he gets off, it turns off and the step hes on now lights. You get the point maybe.
So I can do this pretty easily by rigging up a low voltage stitch in each step then have that trigger the corresponding relays for the 120V lamp's.
But I was thinking about having it do some other stuff that would require implementing my BS1.
Things that id need help knowing how to do.


1. Use one pin for the inputs of 8-10 steps. I think this can be done using resisters but i don't know what the schematic is for that.

2. Using the inputs from the steps, to control the the state of the 7 pins that will trigger the relays.

3. Maybe just some knowledge on how to use inputs.

4. Any ideas of what to use as a trigger on the steps (that can be made cheaply or out of scrap materials).

5. Anything else I would need to know.


See he (the actor) gos up the stairs onto a platform that is 6' in the air and sings while dancing. So while hes singing going up the stairs my vision is to have the stair under him stay on then the next and the next so that when he reaches the platform at the top, all the steps are on then they go into chasing patterns or blinking (random stuff). After hes done singing the steps will start going off one by one as he gos down.

I'm pretty good with the electronics part of all this I'm just asking for help with the programing. I know all this can be done so it shouldn't be that hard.

I know this is asking allot but the set shure would look better if I could implement the BS1 and add animation instead of just having lamps that go on and off.

We still have a few weeks so theres no rush. But we would like to get it done so they can use the set for play practice.

Encase your wondering the musical were currently doing is The Wiz.

On the behalf of the entire drama department and I thanks for any help.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are no Undo buttons in life.
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-26 04:32
    The main references for the sort of thing you want to do are:
    1) The "What's a Microcontroller?" tutorial downloadable from the Stamps in Class webpage under the Downloads menu item on Parallax's main page.

    2) The "Nuts and Volts Columns" also downloadable under the Downloads menu on Parallax's main page.

    As is usual, these come with schematics and sample programs. Some of the earlier Nuts and Volts columns deal with the BS1. A lot of What's a Microcontroller? deals with the BS2 series of Stamps, but a lot of the simpler stuff is directly applicable to the BS1. There's also a set of BS1 Application Notes that give great examples of things to do with a BS1. This is downloadable from the Parallax webstore page for the BS1.

    Make sure you have the current version of the Stamp Editor. Some of the older versions did not support the BS1. Make sure the BS1 has power applied and you have the serial programming adapter for the BS1 plugged in properly.
  • MorrolanMorrolan Posts: 98
    edited 2007-10-26 13:06
    Can you post a diagram or flow-chart of what it is you want to achieve with the stairs? Just a simple flow chart will do, with each block being the next "step" and then the programming becomes much easier, as the programming after all is just an electronic flow-chart that responds to the environment... scool.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-26 20:21
    I drew this up reall quick not to complex but you will should be able to understand it. Thanks for helping out we can use as much as we can get.



    starirs.jpg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • D FaustD Faust Posts: 608
    edited 2007-10-26 22:08
    I think whay you need is a shift register (parallel to serial) This will let you get data from many lines (steps) and if you use a serial to parallel converter you can control all of the outputs. Thsi would require a total of 4 pins (I think, 1 shared data line, 1 shared clock line, and a Chip select line per chip) Do you have the proper sensors installed in the floor already? If not, you could be less by mounting a small IR emitter and detector on the sides of the steps. Parallax sells the products (they would work by sensing a broken beam. There is a circuit with the 555 timer that will let a BS1 make modulated (with a certian frequency, so the system is less sensitive to ambient light) IR in the back of the "IR remote with the Boe bot" book. As for a pot, I am fairly sure that that is a variable resistor and wouldn't do what you are looking for.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-26 23:10
    I think I may know what your saying about the shift registry. If i recall correctly that is sort of what I used last year to build a parallel port controlled 64 channel Christmas light controller. But i did not know you can do the same thing for collecting inputs.

    At the time i ordered extras so i have about 8 more of each. Would any one of these two parts be of any use to me.

    I have some M74HC595
    and some ULN2803A


    I hope you can spare some time to help me through this project, we would just love to have these steps light up. Now I have not come up with an idea for a sensers yet. But I'm thinking about just putting push buttons under thin pieces of wood. i had thought about using inferred light but like you said the stage lights would interferer.

    If you have taken a look at the drawing (above) you may have noticed that I will have three pairs of steps that have to be run off the same pin since I only have 7 open for outputs. But now that you bring up the registers do you think there is any way we could run all 10 steps using only 4 channels.

    I hope you or someone else can hep with the code side of all this, the only thing i have be able to code so far is a servo and an LED.

    I think i need to get a BS2 since there seems to be more documentation out there.

    Thanks again from everyone here and myself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 00:05
    It looks to me as if the ULN2803A is just a set of transistors, can you explain to me what they are used for?· The serial in, parallel out register could help you turn on/off the light circuitry.··I think you should run the wire s fot the lights (AC, right?) throught an optoisolator, and have the optoisolator turned on by the shift register.· I have a BS2 and the 74HC165 that I have to try so I will post the code when I get around to it. If you use modulated IR you shouldn't have too much of a problem with stage lighting because the stage lighting shouldn't be at the same frequency.· Do you have an IR setup from parallax?· They are quite inexpensive, so I would suggest that you try it and see if you get interference.· Look up the part of the book that I mentioned for the proper circuit.· (If you get a BS2, it can control the IR directly)·A switch under a board might be a little awkward/fragile for a stage.· Hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-27 00:59
    You can use the 74HC595 using 3 pins on the BS1 and that will give you 8 or more outputs for the SSRs.
    If these are standard SSRs with 5V inputs that take about 10ma to drive, you could connect them directly to the 74HC595 outputs.
    You could also use a 74HC165 serial input shift register that would provide 8 inputs for each 74HC165.
    Like the 74HC595, these are cascadable to give you multiples of 8 bits and they use 3 I/O pins on the BS1.
    You could attach a pushbutton to each 74HC165 input with the other terminal of the pushbutton connected to ground.
    The 74HC165 inputs would each need a pullup of about 10K to +5V.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 01:06
    Mike or anybody, isn't there a special way to hook up an AC device with some/an SSR?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 01:15
    The ULN2803A would only be needed if i were to use mechanical relays. But since I'm using some that i built myself i wont need to, they require about the same amount of electricity as an LED would. Here is the schematic for them

    http://computerchristmas.com/christmas/link-how_to/HowToId-68/4-channel_SSR_to_go_with_the_controller_in_the_How_To


    So you think its possible to control the M74HC595 with my BS1? I thank you for actual going and testing that out. I feal like were getting somewhere on this.

    About the switches, they should be real sturdy. This is how I'm going to do it there will be the stair tread then on top of that there will be a piece of 1/4'' ply the same size that is hinged on the front. This will trigger one of the two switches on either side under the hinged board.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 01:57
    Have you used the M7HC595 before, and have the code for it? If you do, that is half of it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-27 02:29
    Look at the BS1 App Notes. It has sample code for talking to various ADCs which are all SPI-based and the 74HC595 is similar in that it has a clock and data line for getting information into the shift register, then there's a load line that's clocked once to move the shift register data into the output register.
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 03:09
    I have used the M7HC595 before, but it was conected trough the printer port and i did not right the software that controlled it. Im looking at a few diagrams rigt now just trying to under stand this chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 12:48
    I have a project that is going to use the 74HC595 so I will have that code too, btu I bought and SM version and I can't solder surface mount stuff so I have to reorder it.· I will probably have the code in a few weeks.· Mike thanks for the reference, I would have asked for soemthing like that soon.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 14:34
    Well we only have about 2 weeks till the show. Do you have a schematic or anything. So i could build it over here since i have that part, then maybe you could help me through the code. Or is that to hard to teach someone over the Internet. Either way i thank you for being willing to help. There is this How To that sort of explains the chip but i don't know if its any help.

    http://computerchristmas.com/christmas/link-how_to/HowToId-89/Understand_the_74HC595



    Als i downloaded a new vesion of software so now i can program the thing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.

    Post Edited (Tech-Man) : 10/27/2007 3:01:54 PM GMT
  • D FaustD Faust Posts: 608
    edited 2007-10-27 14:52
    Okay, do you have·lighting system in place?· Check out the part of the manual that Mike is talking about.· if you get the register you have working, you could make some code that would light up the next step when a button is puched by someone in the control booth.

    Here it is http://www.parallax.com/dl/appnt/stamps/bs1appnotes.pdf·go to page 8 and 9 and see if you can get the code to work.
    Here is the data sheet : http://www.st.com/stonline/books/pdf/docs/1989.pdf

    I don't think that I can help you much more becuase I am using a BS2 with the SHIFTIN/OUT commands.· This seems like quite a large task for two weeks!· Maybe someone with more (some)·BS1 experience can help you more.· Sorry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 15:37
    This seems like a good discription http://www.parallax.com/dl/docs/books/sw/exp/sw23a.pdf but i don't know if i can do it with a BS1, also this http://forums.parallax.com/showthread.php?p=531435 I have to go to town now, but i hope i get some time tonight to really just set down and think about all this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-27 18:16
    Here's a fragment of code, part of your initialization, and a subroutine to copy a variable "value" to a 74HC595 wired as in the StampWorks writeup. The BS1 doesn't have the SHIFTOUT statement.
    symbol data = 1  ' 74HC595 pin 14 wired to BS1 pin 1
    symbol dataPin = pin1 ' same thing in different form
    symbol clock = 0 ' 74HC595 pin 11 wired to BS1 pin 0
    symbol latch = 2 ' 74HC595 pin 12 wired to BS1 pin 2
    
    symbol temp = b0 ' a temporary byte variable
    symbol temp7 = bit7 ' most significant bit of b0
    symbol i = b2 ' another temporary used as a counter
    symbol value = b3 ' just a byte variable
    
    ' part of your initialization routine
    low clock ' initialize clock line to output low
    low latch ' initialize latch line to output low
    low data ' initialize data line to output low
    
    ' subroutine to transfer a byte from "value" to the register
    send:
      let temp = value   ' make a temporary copy of value
      for i = 1 to 8   ' 8 bits to transfer
        let dataPin = temp7   ' put most significant bit on data line
        let temp = temp * 2  ' shift to next bit in temporary value
        pulsout clock,1   ' put out clock pulse
      next i
      pulsout latch,1   ' put out latch pulse to copy to output register
      return
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-27 18:36
    If you want to use the 74HC165, here's the code to read the input lines and transfer the value into "value".
    symbol inData = 3 ' 74HC165 pin 9 wired to BS1 pin 3
    symbol inDataPin = pin3 ' same thing in different form
    symbol inLoad = 4 ' 74HC165 pin 1 wired to BS1 pin 4
    symbol inClk = 5 ' 74HC165 pin 2 wired to BS1 pin 5
    
    ' part of your initialization routine
      low inClk ' initialize clock line to output low
      low inLoad ' initialize shift/load line to output low
      input inData ' make sure data line is input
    
    ' subroutine to transfer a byte to "value" from the register
    recv:
      high inLoad ' change to shift mode
      for i = 1 to 8  ' 8 bits to transfer
        let temp = temp * 2 + inDataPin ' read next data bit
        pulsout inClk,1 ' put out clock pulse
      next i
      low inLoad ' back to load mode
      let value = temp
      return
    
    


    Note that in both examples, it's easy to modify them to allow for more than 8 bits. Simply cascade two registers (74HC595 or 74HC165), change the for loop to go for a count of 16, and change the definition of "temp" to w0 rather than b0 (and temp7 becomes temp15 = bit15). "value" would have to become a word variable as well. In the output example, the most significant bit of the value is sent out last. In the input example, the most significant bit of the value is received first. Keep that in mind when wiring the switches.

    Post Edited (Mike Green) : 10/27/2007 6:41:04 PM GMT
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 20:48
    Well i thank you for this, but unfotenetly it looks as though i cant do any of this without a BS2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 21:07
    Why?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-27 22:38
    Maybe i made a mistake. Wassent all that code above for a BS2? I hope im rong and its for a BS1. Id really like to get this to work, i went and bought some more parts to build some solid state realys.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-27 22:41
    Yeah. For sure a BS2 has more pins available and could make this work without any extra chips, but a BS1 could do it with only the 74HC595 and the 75HC165 which are certainly cheap and easy to use.

    By the way, for contacts, you could use home-made switches using copper foil where there's a little play in a portion of the step ... like make each step of 3 pieces of wood and have the middle one with some kind of compressible spacer on one end ... maybe 1/8 inch. When there's weight put on the step, the "loose" end of the board goes down 1/8 inch and the copper foil on the loose piece and on the brace on the side touch each other and voila! Remove the weight and the springiness of the wood breaks the contact.

    The two examples of code are specifically for the BS1.
  • D FaustD Faust Posts: 608
    edited 2007-10-27 23:20
    The BS2 just condenses most of that into a Shiftin / shiftout command.· Hope you can get this too work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --DFaust
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-28 00:54
    Ok my bad im really sorry about that and it even says BS1 right there in the first line. I feal so dumb. So it tells me what pins to huck up to the BS but do any of them need power. And also what will this program actualy make the thing do.

    This is realy dumd but about the only thing i know how to do on the BS is asign a High Low comand to a pin. But i really am trying to make an effort to lean what you two are telling me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.

    Post Edited (Tech-Man) : 10/28/2007 1:08:53 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-28 01:14
    You really really really need to read through the What's a Microcontroller, the BS1 App Notes, and some of the Nuts and Volts columns (that look they apply). We cannot teach you how to use a Stamp whether a BS1 or a BS2. These references show you how to hook up switches, LEDs, and other stuff to any kind of Stamp, carefully explain stuff and give examples. You are unlikely to get this project to work in the time you have left unless you invest some time in going through these guides and making notes as you go along.
  • Tech-ManTech-Man Posts: 100
    edited 2007-10-28 01:38
    Yes your right in every since i do need to just set down and read the material. I just hate reading that much stuff on a computer screen but ill try my best to go through some of it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • kelvin jameskelvin james Posts: 531
    edited 2007-10-28 03:18
    This is pretty interesting for your app. The same pin is used as an input and output, it is called pin sharing, and is a idea created by Jon W. With the right code and circuit, it would give you 8 inputs and outputs off the BS1. An example of the code here for those understanding the idea, NV attached for viewing.






    ' Program Listing 38.1
    ' Nuts & Volts: Stamp Applications, April 1998
    GetPin: Dirs = %00000000 ' all pins are inputs
    IF Pin0 = 1 THEN GetPin ' wait for pin to go low
    Blink: Dirs = %00000001 ' make pin 0 an output
    FOR B0 = 1 TO 5
    PAUSE 500
    Pin0 = 0 ' LED on
    PAUSE 500
    Pin0 = 1 ' LED off
    NEXT
    GOTO GetPin ' do everything again
    nv38.pdf 414.4K
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-09 00:09
    Iv looked over the application notes but i feal as though iv gotten know where, I did learn a bunch of things that i never before knew i could even do with a BS1. But the problem is that they never really talked about using a shift register. And some of the links that others have given seem to be dead must be from them switching there site around (looks good) and one of them links had allot of information about the 74hd595 specifically.

    Well last weekend i spent all day up at the school working on the sets for The Wiz they came out great and the steps are awesome but of course i need to figure out this code. Its really nice to see somthing that you have spent hours designing come together, here is a picture of the steps i built.

    1880232955_43b54e6bb6.jpg?v=0

    1880237761_85e7bf6def.jpg?v=0


    For about the past hour iv been working on just getting some form of input to work so·I hooked up the switches so it looks like the schematic on page 155 (BASIC Stamp I Application Notes) and then used this code just to see if i could get some readings and i got some, and they were right for once [noparse]:)[/noparse]


    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    Clear:
    LET B0 = 0


    Again:
    · POT 0, 116, B2
    · IF B2 >= 231 THEN clear
    · GOTO ID_sw
    Display:
    DEBUG B3
    GOTO clear:

    ID_sw:
    · IF B0 > 8 THEN skip
    · B0 = B0+1
    · GOTO again
    Skip:
    · FOR B3 = 0 TO 7
    ····· LOOKUP B3,(7,41,75,109,141,172,201,230),B4
    ····· IF B2 <= B4 THEN done
    ··· NEXT

    done:·· GOTO Display
    ________________________________________________________


    I·run the program and it works! Iv never done anything with the BS1 past lighting an LED and making weird sounds with a speaker so I'm proud of myself so fare. It displays a value of 0-7 depending on which switch was pressed. Will this set up do the same thing if i use 11 switches instead of 8 one would think so but just checking.



    Now that i have the inputs working how do i·send this value (the value it displays) to the 74hc595, well i actually need to use 2 of the 74hc595 chips since i need to control 11 steps. But I can use the same three pins to run that chip to right?


    You gave me this code but i do have a few questions i hope you don't mind.

    symbol data = 1· ' 74HC595 pin 14 wired to BS1 pin 1
    symbol dataPin = pin1 ' same thing in different form
    symbol clock = 0 ' 74HC595 pin 11 wired to BS1 pin 0
    symbol latch = 2 ' 74HC595 pin 12 wired to BS1 pin 2··· <<<<<<<<<<I get whats going on up to here then ya lose me, i understand some of the other
    ···································································································· stuff but not enough to use it to my own benefit, maybe you could add some
    ···································································································· side notes like this to further explain thing. Its essayer for me to use code
    ···································································································when·i·know·it·means.··········································································································································································································· symbol temp = b0 ' a temporary byte variable
    symbol temp7 = bit7 ' most significant bit of b0
    symbol i = b2 ' another temporary used as a counter
    symbol value = b3 ' just a byte variable
    ' part of your initialization routine
    low clock ' initialize clock line to output low
    low latch ' initialize latch line to output low
    low data ' initialize data line to output low
    ' subroutine to transfer a byte from "value" to the register
    send:
    · let temp = value·· ' make a temporary copy of value
    · for i = 1 to 8·· ' 8 bits to transfer
    ··· let dataPin = temp7·· ' put most significant bit on data line
    ··· let temp = temp * 2· ' shift to next bit in temporary value
    ··· pulsout clock,1·· ' put out clock pulse
    · next i
    · pulsout latch,1·· ' put out latch pulse to copy to output register
    · return

    ________________________________________________


    Once i figure out how to have the corresponding pins on the register chips light an LED as a switch is pressed ill huck it all up to the SSRs to control the high power lights insted of the LED. Then ill need to figure how to have each light stay on once there pressed till there pressed again and stuff like that.
    I just hope i can figure out how to send stuff to the 74hc595 chip,· i think this could be used for so many other projects. Im fealling good about this just getting the switches to provide input has been hard but I'm farther then i was a week ago. Its looking like it can be done in time with a bit of help. The show starts this next Thursday so i only have about· 5 days. Everything is wired so pretty much all i need to do is upload some code to the BS1 then conect it to my SSRs.
    here are some more pics of the progress iv made to break you free from all this text. Like i said i understand how to wire all this stuff its just the code thats stopping me.

    1924113532_00c2a2ecf8.jpg?v=0·1924109824_12b4f2f48d.jpg?v=0

    1924106064_6d3da28243.jpg?v=0·1796780150_c6b311086e.jpg?v=0

    1796777374_67acf5d38a.jpg?v=0·1923271455_8a9295a149.jpg?v=0

    Thanks!








    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.

    Post Edited (Tech-Man) : 11/9/2007 8:49:29 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-09 21:40
    Here's the sample code modified for two 74HC595 in series. It copies 16 bits
    from the variable "value" with bits 8 through 15 transferred into the 74HC595
    furthest from the BS1 and bits 0 through 7 transferred into the 74HC595
    closest to the BS1. You connect all of the clock pins (11) together and
    all of the latch pins (12). The data pin (14) of the 2nd 74HC595 is
    connected to the Q7' output pin (9) of the 1st 74HC595. You have to be
    sure to connect the "not output enable" pins (13) of both devices to
    ground through a 4.7K to 10K resistor and the "not master reset" pins
    (10) of both devices to Vdd (+5V) through a 4.7K to 10K resistor.
    symbol data = 1  ' 74HC595 pin 14 wired to BS1 pin 1
    symbol dataPin = pin1 ' same thing in different form
    symbol clock = 0 ' 74HC595 pin 11 wired to BS1 pin 0
    symbol latch = 2 ' 74HC595 pin 12 wired to BS1 pin 2
    
    symbol temp = w0 ' a temporary word variable
    symbol temp15 = bit15 ' most significant bit of w0
    symbol i = b2 ' another temporary used as a counter
    symbol value = w2 ' just a word variable
    ' part of your initialization routine
    low clock ' initialize clock line to output low
    low latch ' initialize latch line to output low
    low data ' initialize data line to output low
    ' subroutine to transfer a word from "value" to the register
    send:
      let temp = value   ' make a temporary copy of value
      for i = 1 to 16   ' 16 bits to transfer
        let dataPin = temp15   ' put most significant bit on data line
        let temp = temp * 2  ' shift to next bit in temporary value
        pulsout clock,1   ' put out clock pulse
      next i
      pulsout latch,1   ' put out latch pulse to copy to output register
      return
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-09 21:48
    Notice that the send subroutine uses variables W0 (same as B0/B1), B2, and W2 (same as B4/B5) with the value coming from W2.
    You have to make your input routine (which uses B0,B2,B3,B4) work with this. Since the send routine has to use B0/B1, change the
    variables in your input routine so B0 becomes B3, B2 becomes B6, B3 becomes B7, and B4 becomes B8. That way, the two routines
    won't conflict.

    Your display routine, instead of DEBUG B3, becomes value = b7 (since B3 becomes B7), followed by GOSUB send. Since your input routine only provides an
    8 bit value, the send routine will output all zeros to the extra bits of the 74HC595 pair.
Sign In or Register to comment.