Shop OBEX P1 Docs P2 Docs Learn Events
BS2 as a bcd to decimal converter — Parallax Forums

BS2 as a bcd to decimal converter

pataypatay Posts: 2
edited 2011-05-26 22:30 in BASIC Stamp
i have a 4 bit binary input and i want 12 decimal independent outputs.

i'm new in this and i don't know how can i configure the I/O pins to make this work?

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-05-26 12:24
    Hi, under Memory and Variables in the Pbasic help file it talks about the registers OUTS, INS and DIRS. These registers are used to configure or control the 16 Stamp I/O pins, either individually or simultaneously. If the first 12 pins were configured as outputs an instruction as simple as OUTS=16 would make P4 high. How you configure this is dependent on whether you want several ouputs high or only one at any one time. The 4 bit binary input follows the same rules, if the inputs are P12 through P15 your instruction might look like this :- MyVariable=IND, MyValue would then contain a number that reflected the binary state of P12-P15 (0 through 15 decimal). This will become much clearer once you have read the section on DIRS ,OUTS and INS.

    Jeff T.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-26 12:33
    This has very little to do with how you configure the I/O pins. First of all, you should get a copy of the "What's a Microcontroller?" tutorial and the Stamp Basic Syntax and Reference Manual. If you have the Stamp Editor, they're included in the help files. If not, go to the main Parallax webpage and click on the Downloads button. The first is under Stamp Tutorials and the second is under Stamp Documentation.

    The Manual's section on memory allocation discusses how the Stamp I/O pins work and how to use them.

    How do you want this to work? With a 4 bit binary input, you've got 16 possible codes. How do you want them to work with 12 outputs? Do you want this to work like a BCD to decimal selector IC where only one output is on at a time and that's the one selected by the 4 bit input value?

    The Stamp can handle sets of I/O pins together, so groups of 4 pins (starting at multiples of 4) can be used as "nibbles" and groups of 8 pins (starting at multiples of 8) can be used as bytes. Again, the Manual goes into detail on this.

    You'll need to write a program that inputs a "nibble" value from some group of 4 I/O pins (like 12-15), then makes up a value with a 1 bit in one bit position and 0s elsewhere. You then write this value to the output register where it affects I/O pins 0-11. It actually affects all the output pins, but you will only set I/O pins 0-11 to output mode and leave I/O pins 12-15 in input mode. Again, read the Reference Manual for details.
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-05-26 12:42
    Welcome to forum.
    Here is one way brute force to convert BCD to individual output bits.
    As Jeff said, make sure your I/O pins are indeed configured for output.

    In hardware implementation you may see term "1 out of 16" selector.
    I am sure there is a smarter way to accomplish this.


    Index VAR Nib
    BinaryNumber VAR Word

    Main:
    DO
    DEBUG "BCD to Binary Bit conversion",CR
    DEBUG "BCD in decimal = "
    DEBUGIN DEC Index
    DEBUG CR
    LOOKUP Index-1, [1,2,4,8,16,32,64,128,512,1024 ], BinaryNumber
    DEBUG ? Index
    DEBUG ? BinaryNumber
    DEBUG BIN16 ? BinaryNumber
    LOOP


    END

    Happy programming
    Vaclav

    Addendum - let the mashine do the work using binary math

    'Main:
    DO
    DEBUG "BCD to Binary Bit conversion",CR
    DEBUG "BCD in decimal = "
    DEBUGIN DEC Index
    DEBUG CR
    'LOOKUP Index-1, [1,2,4,8,16,32,64,128,512,1024 ], BinaryNumber

    BinaryBit = 1 << (Index - 1)

    DIRS = 0 ' set all I/O to input
    DIRS = BinaryBit ' selected pin I/O direction - output
    DEBUG BIN16 ? DIRS
    DEBUG ? Index
    DEBUG ? BinaryBit
    DEBUG BIN16 ? BinaryBit

    HIGH BinaryBit ' set I/O pin

    LOOP
  • pataypatay Posts: 2
    edited 2011-05-26 22:30
    Thank you for the fast answer... i'll try all the posibilities and also i'm reading bs2 manuals and guides
Sign In or Register to comment.