Shop OBEX P1 Docs P2 Docs Learn Events
74HC165 with two decimal Push swithces — Parallax Forums

74HC165 with two decimal Push swithces

RinoRino Posts: 15
edited 2009-01-20 18:13 in BASIC Stamp
The circuit with the 74HC165 shift register and the two decimal push switches works fine with the BS2.· I can read the·switch positions 0 to 9 each.· The 4 bits of each switch is combined into an 8 bit word when I read it with DEBUG.·· I want to get mumbers 0 to 99, I have to multiply this number with another number but when I set·the switches to 99, the number I·get·is 153.·· The ten switch gives me 16, 32 and so on.· I probably have to separate the 8 bit word and recombine it to get the number I need.·
Is there a better way to do it?

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-01-19 22:21
    In your DEBUG command, use the HEX descriptor before the value you want to display.

    Decimal 153 equals 99 Hex.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • RinoRino Posts: 15
    edited 2009-01-19 22:33
    That was a quick response!
    Yes I get that but when I multiply it with another number, it is 153 that is used.

    Thanks for the quick reply.

    Rino
  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2009-01-19 23:08
    Rino,

    You need to convert your BCD Hex number into a Decimal number first before you can perform any math operations to it.

    Here is an example:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    Number  VAR Word
    Temp    VAR Word
    
    Number = 153
    
    'Convert BCD Hex number into Decimal number
    Temp.HIGHBYTE = Number / 16
    Temp.LOWBYTE = Number - (Temp.HIGHBYTE * 16)
    Temp.HIGHBYTE = Temp.HIGHBYTE * 10
    
    Number = Temp.LOWBYTE + Temp.HIGHBYTE
    
    MainLoop:
      DEBUG DEC Number,CR
      GOTO MainLoop
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • RinoRino Posts: 15
    edited 2009-01-19 23:42
    Thanks again.
    I am going to try that.

    Rino
  • RinoRino Posts: 15
    edited 2009-01-20 18:13
    It works just fine.
    Thank you
    Rino
Sign In or Register to comment.