I am reading seconds from a real time counter as BCD data, the 7th bit isn't used for this.
Using similar samples online I was able to convert the uint8_t
BCD data to human readable (0 - 59) seconds.
#define PCF8563_BCD_LOWER_MASK 0x0f
#define PCF8563_BCD_UPPER_MASK_SEC 0x70
#define PCF8563_BCD_UPPER_SHIFT 4
uint8_t raw_seconds = get_raw_seconds();
int seconds = (raw_seconds & PCF8563_BCD_LOWER_MASK) + (((raw_seconds & PCF8563_BCD_UPPER_MASK_SEC) >> PCF8563_BCD_UPPER_SHIFT) * 10);
I'd like to do the same for minutes, hours, etc, (they're all also in BCD format). I feel like I know what to do; shift/remove the 7th bit (for minutes) and convert BCD to Decimal - but I can't figure how to do this in code.
Converting from BCD to decimal isn't exactly the problem (there's a function for that), the shifting/removing of unused bits is throwing me off.