/* retrieve time over I2C in BCD from the DS3231M real-time clock module */ int get_Time(void) { int time; time = get_Hours(); time <<= 8; time += get_Minutes(); return time; }
/* Increment the hours on the DS3231M Clock */ void inc_Hours(void) { byte temp; temp = get_Hours(); if (temp & 0x40) { // if in 12H mode increment 1-12 if ((temp & 0x1F) <= 0x11) temp++; // increment if 1-11 else temp = (temp & 0xE0) + 1; // if 12 then clear 5lsb, and add 1 } else { // if in 24H mode increment 0-23 if ((temp & 0x3F) <= 0x22) temp++; // increment if 0-22 else temp = temp & 0xC0; // if 23 then clear 6lsb } if ((temp & 0x0F) >= 0x0A) temp = (temp & 0xF0) + 0x10; // if lower nibble too high set_Hours(temp); }
void Value_time_imp::Increment( void ) { // Used in tests only so make it just for our datetime parser be happy. if( mValue == 0 ) { Init(); return; } vuint16 hours = get_Hours(); vuint16 minutes = get_Minutes(); vuint16 seconds = get_Seconds(); vuint16 ms = get_Milliseconds(); if( ms < 999 ) { put_Milliseconds( ++ms ); } else if( seconds < 59 ) { put_Milliseconds(0); put_Seconds( ++seconds ); } else if( minutes < 59 ) { put_Milliseconds(0); put_Seconds(0); put_Minutes( ++minutes ); } else if( hours < 24 ) { put_Milliseconds(0); put_Seconds(0); put_Minutes(0); put_Hours( ++hours ); } else { // no nore time which makes parser happy. Actually we rarelly get here. Init(); } }
void Value_datetime_imp::Increment( void ) { // Used in tests only so make it just for our datetime parser be happy. if( mValue == 0 ) { Init(); return; } vuint16 day = get_Day(); vuint16 month = get_Month(); vint32 year = get_Year(); vuint16 hours = get_Hours(); vuint16 minutes = get_Minutes(); vuint16 seconds = get_Seconds(); vuint16 ms = get_Milliseconds(); if( ms < 999 ) { put_Milliseconds( ++ms ); } else if( seconds < 59 ) { put_Milliseconds(1); put_Seconds( ++seconds ); } else if( minutes < 59 ) { put_Milliseconds(1); put_Seconds(0); put_Minutes( ++minutes ); } else if( hours < 24 ) { put_Milliseconds(1); put_Seconds(0); put_Minutes(0); put_Hours( ++hours ); } else { // no nore time which makes parser happy. Actually we rarelly get here. if( day < 31 ) { put_Day( ++day ); } else if( month < 12 ) { put_Day( 1 ); put_Month( ++month ); } else if( year < 9999 ) { put_Day(1); put_Month(1); put_Year( ++year ); } else { // no nore date which makes parser happy. Actually we rarelly get here. Init(); } } }