Shop OBEX P1 Docs P2 Docs Learn Events
Just a little more help — Parallax Forums

Just a little more help

ufadedufaded Posts: 8
edited 2005-01-26 15:29 in BASIC Stamp
I'm sure the BS2 can do this, but I just want to check before I get too deep into reading the manual on how to program. I have a 4-bit binary code that I want to input into an I/O of the BS2, and depending on the code that is·input , I want it to toggle 6 different outputs. Does anyone have any examples on how this code would look?

Thanks again,
Ufaded

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-25 18:54
    The question becomes: How are you going to get that 4-bit code into the BASIC Stamp? (How do you want to, that is.) Serial input?· Parallel input (that will require 4 pins)?· From a shift-register (will use 3 pins)?

    After you've got the code the rest is easy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • ufadedufaded Posts: 8
    edited 2005-01-25 19:41
    I'm sorry, I wasn't thinking. It will be input parallel. Would you by chance have an example of code for this?

    Thanks again
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-25 22:02
    You need to give more details. What pins will be used from inputs (if, for example, you select a contigous group like P0-P3, P4-P7, P8-P11, or P12-P15 then you can simplify the code by using the INx aliases). What is the output? Just turning a pin on or off? You said something about pulsing. You see, details count. My point is that you will probably not find a specific demo for your request unless you spell out more details.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • ufadedufaded Posts: 8
    edited 2005-01-26 05:31
    For the inputs P0-P3 would be fine (I haven't defined anything yet schematic wise - I have my block diagram, and the truth table for input/output). The inputs would be 0001, 0010, 0100, 1000, 0000. The corresponding output pins would go as follows (listed in the same order as the inputs) 00001, 11101, 00010, 11110, 00011 (only 5 outputs, not six as I stated earlier). The output will hold until the input changes. I don't believe I can make the outputs a contigious group due to the fact that I need 4 other output pins to drive leds which will change when the outputs change (the fifth output {00011} makes none of the LEDs illuminate). I am also dedicating one other I/O pin as an input which will have a momentary button attached to it that will scroll through all five of the outputs in sequence. It looks like I will be using a total of 14 I/O pins. I hope I am making sense, and really appreciate all the help I am receiving. Please If I can offer any other information to clarify this let me know and I will.

    Thanks,
    Ufaded
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-26 15:16
    First things first: You should probably download our "What's A Microcontroller?" text -- it's an excellent introduction to PBASIC programming.· When you go through that, the notes below will probably make more sense.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    Switch    VAR    INA
    Leds      VAR    OUTH
     
    idx       VAR    Nib
     
     
    Reset:
      DIRH = %00011111             ' make P8 - P12 outputs
     
     
    Main:
      idx = (NCD Switch) - 1
      LOOKUP idx, [noparse][[/noparse]%00011, %00001, %11101, %00010, %11110], Leds
      GOTO Main
    

    With this little program the outputs (LEDs) will only change when a matched input is made.· Note that you are using four pins to get four selections; you could use two.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • ufadedufaded Posts: 8
    edited 2005-01-26 15:26
    Could I please have a link for the "What's A Microcontroller?" text .

    Thanks for your help.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-26 15:29
    You'll find it under books at www.parallax.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.