Need decimal integer to be BCD
Posted: Mon Dec 09, 2024 12:58 am
I have time values that are retrieved and stored as decimal values. But the same value needs to be written as BCD to the registers of an external RTC.
For example
uint8_t year = 19; //year is 2019, value in decimal
spi_rtcc_wr(rtcc reg: RTCYEAR, time_var: 0x19); //but external RTC needs that 19 to be in BCD (0x19) to represent 2019
How can I convert the decimal 19 to a BCD value of 0x19?
If I insert year as the time_var it accepts it but stores the value as BCD 13.
For example
uint8_t year = 19; //year is 2019, value in decimal
spi_rtcc_wr(rtcc reg: RTCYEAR, time_var: 0x19); //but external RTC needs that 19 to be in BCD (0x19) to represent 2019
How can I convert the decimal 19 to a BCD value of 0x19?
If I insert year as the time_var it accepts it but stores the value as BCD 13.