Hex grief
Steve2381
Posts: 94
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?
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
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
time_adj = (oldValue DIG 1) << 4 + (oldValue DIG 0)
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.