Shop OBEX P1 Docs P2 Docs Learn Events
Hex grief — Parallax Forums

Hex grief

Steve2381Steve2381 Posts: 94
edited 2009-07-24 00:54 in BASIC Stamp
Hello

This is driving me mad...

I have a clock, run on a basic stamp, using bs1302 timing ic and Max7219's running the led displays.

I obtain the time from the ds1302 in hex format, and that is what gets displayed.

However, in my program there is the facility to adjust the time. I have a simple routine that adjusts hours, minutes etc
This is a simple routine that is based on - this is the basis of the routine - not the code!!

Adjust_time:
upon hoursup keypress, hours=hours+1.
If hours=24, then hours=0
gosub the display routine using max7219
upon finish keypress exit loop
goto adjust_time

How do I get this decimal counting during time adjustment to convert to hex to enable the MAX7219 to display the time as I am adjusting it?
I don't see how I can count in hex using the hours+hours routine, so I surely have to count in decimal and convert it back.

am I being thick?

Comments

  • Steve2381Steve2381 Posts: 94
    edited 2009-07-23 13:44
    ok, basically this is where we are....

    I have a value in decimal (0-23), and I need to convert that figure to a variable called time_adj in hex format. How!!!

    Thanks
    Steve
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-23 14:57
    The DIG operator will help (look it up in the manual):

    time_adj = (oldValue DIG 1) << 4 + (oldValue DIG 0)
  • SRLMSRLM Posts: 5,045
    edited 2009-07-24 00:54
    In general, the way that I do mental conversion from decimal to hex is to follow this path:

    Decimal -> Binary -> Hex

    Converting this way is trivial (no dividing by multiples of 16) and it's easy to group four bits together to make a hex digit.
Sign In or Register to comment.