Shop OBEX P1 Docs P2 Docs Learn Events
Converting decimal to BCD — Parallax Forums

Converting decimal to BCD

RacerXRacerX Posts: 6
edited 2006-05-26 06:50 in BASIC Stamp
I have a circuit set up with a BS2 driving a 74HC595.· The 595 is connected to two 74LS47 BCD to decimal converters each driving a seven segment LED.
I want to take a decimal number (counter) which can range from 0-99 and put it on the LEDs.
How would be the best way to get my 8 bits properly arranged into 2 BCD friendly nibbles to shift out to the 595?

·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-26 06:50
    Here are two routines I use for converting BCD to Decimal and Decimal to BCD.
    [size=2][code]
    BCD_Decimal:
      counter = (counter.NIB1 * 10) + counter.NIB0
      RETURN
                                    ' Convert BCD To Decimal
    Decimal_BCD:
      counter = (counter / 10 << 4) + (counter // 10)
      RETURN 
    


    [/code][/size]
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.