The read_minute and the read_second output perfectly but the read_hours is outputting "70" at 10PM.
Can anyone help me and explain what I am doing wrong?
The top 4 bits of the hour byte are:
Zero
12-hour mode flag
PM flag
Tens of hours
Since you get 0111 0000 at 10:00 that means the clock is in 12-hour mode, it's PM, and the hour is > 9 which is all correct.
if (read_hour & 0b01000000) // 12-hour mode
{
if (read_hour & 0b00100000) // PM flag
read_hour = (((read_hour & B00010000)>>4)*10 + (read_hour & B00001111)) + 12; // convert BCD to decimal and add 12 for PM
else
read_hour = (((read_hour & B00010000)>>4)*10 + (read_hour & B00001111)); // convert BCD to decimal
}
else
{ // 24-hour mode
read_hour = (((read_hour & B00110000)>>4)*10 + (read_hour & B00001111)); // convert BCD to decimal
}