Decimal to hex clock conversion
Steve2381
Posts: 94
Hi
I have a remote·keypad with a scanning·routine that allows you to enter 3 sets of values - temp_hours, temp_mins and temp_secs.
This is to 'set' the correct time on a clock that is being tracked using a DS1302 ic.
To send the digits to the DS1302, these values need to be in Hex format... its driving me mad this whole hex/decimal converting.... any ideas how to write the above values to EEPROM and then recover them·in hex format?
Write 1,temp_hours - stores it in decimal
Then...
Read 1,hours·· - how do I convert this to Hex?
Thanks
Steve
·
I have a remote·keypad with a scanning·routine that allows you to enter 3 sets of values - temp_hours, temp_mins and temp_secs.
This is to 'set' the correct time on a clock that is being tracked using a DS1302 ic.
To send the digits to the DS1302, these values need to be in Hex format... its driving me mad this whole hex/decimal converting.... any ideas how to write the above values to EEPROM and then recover them·in hex format?
Write 1,temp_hours - stores it in decimal
Then...
Read 1,hours·· - how do I convert this to Hex?
Thanks
Steve
·
Comments
Decimal to BCD:
· bcdVal = ((decVal DIG 1) << 4) + (decVal DIG 0)
BCD to Decimal
· decVal = (bcdVal.NIB1 * 10) + bcdVal.NIB0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Steve
Sorry to be a pain, my understanding of hex - decimal conversion isn't up to scratch yet!
The formula you gave me works fine for the 2 digit variables, but I now need·to convert the 4 digit year from decimal to hex.
I have had a go, but can't seem to suss that one out either.... perhaps I have been staring at this screen too long!
Many thanks
Steve
·· The year is only 2 digits in the clock, so that is all you need to convert.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
· bcdYr = ((year DIG 3) << 12) | ((year DIG 2) << 8) | ((year DIG 1) << 4)·| (year DIG 0)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I was trying to convert the 4 digit dec variable to hex - just to see if I could.
Even with the manual, too long on the laptop and being rubbish at maths doesn't help!
thanks again
Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·