Shop OBEX P1 Docs P2 Docs Learn Events
BS1 newbie questions — Parallax Forums

BS1 newbie questions

JackPollackJackPollack Posts: 8
edited 2004-09-03 21:24 in BASIC Stamp
Hi, am a newbie and have several BS1 questions:

1. I am using· lookup to build a table of binary coded decimal data
eg:
27 Really represents 010 (binary 2) and 111 (binary 7)
54 Really represents 101 (binary 5) and·010 (binary 4)

If b0 is my BDC number (54)
I am unsing· b0/10//10·to get digit 1 and· b0//10 to get digit 2

How can I output to 3 specific bits based on my decimal number without effecting the other bits?

2. I screwed up on the bit order. I used ABCD... instad of ...DCBA. So if there is a simple answer to question 1 (I am thinking some type of bit mask, but don't really know how to create it) I think that the numbers I output are going to need to be flipped.

Sorry if this is hard to understand, but I am REALLY CONFUSED.

Thanks for your help

Comments

  • JackPollackJackPollack Posts: 8
    edited 2004-09-03 20:31
    I want to output parallel

    eg

    00 111 111
    unused bits Digit 1 Digit2

    But remember for me the unused bits are pin 6 & 7
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-03 20:34
    Why are you only using three bits? BCD numbers use four bits, and you can't represent the digits 8 and 9 without the fourth bit.

    How do you want to do your output? If, for example you were going to use P0-P3 for the one's digit, and P4-P7 for the ten's digit, you could do this:

    Pins = decVal / 10 * 16
    Pins = decVal // 10 | Pins

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • JackPollackJackPollack Posts: 8
    edited 2004-09-03 20:40
    My output is driving 2 seperate demultiplexers that only count to 7 (3 bits)

    >How do you want to do your output?

    I want bits 5,4,3 to be digit 1 (remember bit 5 is my 1 bit)
    I want bits 2,1,0 to be digit 2 (2 is my 1 bit for this pair)
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-03 21:01
    You can use LOOKUP to correct the bits.

    d1 = decVal / 10 
    LOOKUP d1, (%000, %100, %010, %110, %001, %101, %011, %111), d1 
    Pins = d1 * 8 
    d2 = decVal // 10 
    LOOKUP d2, (%000, %100, %010, %110, %001, %101, %011, %111), d2 
    Pins = Pins | d2
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • JackPollackJackPollack Posts: 8
    edited 2004-09-03 21:24
    I think that did the trick :-)

    Thanks, and have a nice holiday.
Sign In or Register to comment.