Shop OBEX P1 Docs P2 Docs Learn Events
HEX to DEC conversion question (BCD?) — Parallax Forums

HEX to DEC conversion question (BCD?)

T&E EngineerT&E Engineer Posts: 1,396
edited 2007-05-18 18:48 in General Discussion
As many of you know I have been working on updating my 16x16 tricolored LED Matrix RTC.

I have added a 74HC165 to my 16x16 tricolored LED Matrix RTC circuit because there was only 3 I/O lines left on my SX52 and I needed at least 4 pushbuttons to set the date and time on this.

However, as it stands at the moment I can increment and decrement a hex number on the display and even watch it scroll by while updating it. I'm not sure if I want to have it scroll while updating the time or date but for now it is ok.

The problem I need help in understanding or need a solution to is as follows:

If I start with a TIMESET = 34 variable declaration, the display routine keeps it in·hex so that·when incrementing the TIMESET variable it·gets displayed as 34 35 36 37 38 39 3A 3B ....

Currently I have tried JonnyMac's DEC2BCD routine which I have seen good results on in the past. However, in this application I don't know how to link them together right. I·have tried and only get the last digit scrolled like 4 5 6 7 8 9 A B ... so something on my end is not right.

What do I have to do to get past this·so that it gets incremented as 34 35 36 37 38 39 40 41 .. ?

I looks like I need to increment a decimal (or maybe BCD) number·but the display routine needs a hex number.

I have attached my code for anyone to follow.

Thanks.



Post Edited (T&E Engineer) : 5/18/2007 6:49:40 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2007-05-18 16:49
    ' Increment timeSet (BCD)
    temp = timeSet AND $0F
    IF temp = 9 THEN
    · timeSet = timeSet + 7
    ELSE
    · INC timeSet
    ENDIF


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-05-18 18:44
    Here's Bean's code wrapped up in a function so that it can be called from anywhere and applied to any [noparse][[/noparse]byte] variable -- this also checks for and handles 10's rolloever.

    FUNC INC_BCD
      tmpB1 = __PARAM1                              ' save parameter
      tmpB2 = tmpB1 & $0F                           ' extract low nib
      IF tmpB2 < $9 THEN
        INC tmpB1                                   ' inc ones
      ELSE
        tmpB1 = tmpB1 + 7                           ' clear ones, inc tens
        tmpB2 = tmpB1 & $F0                         ' extract high nib
        IF tmpB2 > $90 THEN                         ' check for 10s rollover
          tmpB1 = $00
        ENDIF
      ENDIF
      RETURN tmpB1
      ENDFUNC
    
    
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2007-05-18 18:48
    Thanks to both of you. I will look at this tonight.
Sign In or Register to comment.