I solved it like this:
Greetings and happy new year.
- Code:
if( m_addrPtr < 8 ){
if ( m_addrPtr < 3 ) updtTime(m_addrPtr);
else if( m_addrPtr < 7 ) updtDate(m_addrPtr);
else updtCtrl();
}
void DS1307::updtTime(unsigned char reg)
{
if (reg == 0) {
m_time.setHMS( m_time.hour(), m_time.minute(), bcdToDec(m_data[0]/* & 0b01111111*/) );
}
else if (reg == 1) {
m_time.setHMS( m_time.hour(), bcdToDec(m_data[1]), m_time.second() );
}
else if (reg == 2) {
int hour;
if( m_data[2] >= 0x40 ) // 12 hour
{
hour = bcdToDec( m_data[2] & 0b00011111 );
if( m_data[2] & (1<<5) ) hour += 12; // PM
}
else hour = bcdToDec( m_data[2] & 0b00111111 ); // 24 hour
m_time.setHMS( hour, m_time.minute(), m_time.second() );
}
}
void DS1307::updtDate(unsigned char reg)
{
if (reg == 4) {
m_date.setDate( m_date.year(), m_date.month(), bcdToDec(m_data[4]) );
}
if (reg == 5) {
m_date.setDate( m_date.year(), bcdToDec(m_data[5]), m_date.day() );
}
if (reg == 6) {
m_date.setDate( 2000+bcdToDec(m_data[6]), m_date.month(), m_date.day() );
}
}
Greetings and happy new year.
Last edited by arcachofo on Mon Jan 09, 2023 10:00 am; edited 1 time in total (Reason for editing : Mark as solved (green color))