Shop OBEX P1 Docs P2 Docs Learn Events
show a nuber on leds — Parallax Forums

show a nuber on leds

marclamarcla Posts: 19
edited 2007-12-27 23:26 in Propeller 1
hello!
I want to show an number on 4 leds using bcd code.
how do i do it?
is ther any cod that i can giv a nuber Ex. 5 an di shows it on my leds.
Ex. 5 should lock like this:

PIN········ 16···· 17···· 18···· 19·· (Pin on the propeller)
Number··· 1······ 2····· 4······ 8··· (In the binary system)
Status···· high·· low···high···low· (Led Status)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-27 21:13
    Assuming you have your binary number in a variable called BCD and your pins are as stated,
    a "DIRA[noparse][[/noparse] 19..16 ] := %1111" will set pins 16 through 19 to output mode and a "OUTA[noparse][[/noparse] 19..16 ] := BCD"
    will set the pin states to the least significant 4 bits of BCD. In Spin, you can give a pin range with the
    highest pin number first or the lowest pin number first. The first number is the most significant bit and
    the last number is the least significant bit. Don't forget the current limiting resistors on the LEDs.
  • marclamarcla Posts: 19
    edited 2007-12-27 22:00
    Thank you! But
    I have the bcd string in normal nubers ex. 5 not in BCD code so my problem is not the showing part it's how i decode ex. number 6 in to bcd format
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-27 23:11
    Have you tried those explicite instructions Mike kindly gave you?
  • Nick MuellerNick Mueller Posts: 815
    edited 2007-12-27 23:26
    If you want to convert a binary number to BCD, you could convert it to a string, pick a character of the string, subtract "0" and the result is <drumroll>one digit in BCD.
    Do that in a loop, and you have all digits in BCD.


    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
Sign In or Register to comment.