hi,
how to change the value of hex to decimal
For example from hex "0x15" to decimal 15 or in hex like 0x0f.
do we have any option in keil or any other way.
Thankyou
arun.
Thank you for the all
Thank you Mike Kleshov, i solved my problem from your reply.
Regards arun
Mike's post shows how to convert BCD to a numeric value.
If you just need to display the value, there isn't really any point in converting to a number - you could just extract the digits and then display them directly.
"have to write and read in hex only with the RTC."
Not at all. Hexadecimal is a presentation of a number. Something you may have in your source code. Or dispayed on the LCD. Or printed on a paper. But you do not program the RTC with any hexadecimal data, for the simple reason that the RTC want to see bytes without caring about the existence of any radix or numeric base you may have in your source code.
In this specific case, it's BCD-encoded data. When printing to display, you can use %02x to print it, giving a correct 2-digit presentation of the BCD-encoded value. Or you can use the previous source code to convert into a number and print it using %02u.
If you implement code to edit/input the time, then you can select if your code should use a number 0..59 for minutes and convert to BCD just before sending to the RTC. Or if the code should directly have a BCD value in a byte and (if you have up and down buttons) code that knows that 0x09 + 1 should be 0x10, i.e. that when low nibble increments from 9 it has to be reset to 0 while the high nibble must be incremented. And similar when low nibble is decremented while already being 0.