Shop OBEX P1 Docs P2 Docs Learn Events
Need help with converting base 10 (2 digits) to BCD code(8 bits) — Parallax Forums

Need help with converting base 10 (2 digits) to BCD code(8 bits)

matt_willmatt_will Posts: 1
edited 2014-12-20 09:04 in BASIC Stamp
I have 2 7 segment displays on which I need to show a double digit base 10 number that can vary from 50 -90. How do I convert the two digit number to the 8 bits for the BCD code? I am using 2 7447 decoder drivers and have them connected to pin 8 - 15. I know how to use the OUTH = % command.

Comments

  • SapphireSapphire Posts: 496
    edited 2014-12-19 15:03
    Break your double digit number (NUM) into two parts:

    NUMH Var Nib
    NUML Var Nib

    NUMH = NUM/10
    NUML = NUM//10

    Both NUMH and NUML will be 0-9. That can be written directly to your outputs, but use OUTC and OUTD:

    OUTC = NUML
    OUTD = NUMH
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2014-12-20 09:04
    Or, there is the DIG operator:

    OUTC = num DIG 0
    OUTD = num DIG 1

    Page 117 in the Stamp manual.
Sign In or Register to comment.