void RTCC_Enable(void) { RTCC_SetWriteEnable(); //RTCCON |= (1 << 15); RTCCONSET = 0x8000; // turn on the RTCC while (!(RTCCON & 0x40)); // wait for clock to be turned on RTCC_SetWriteDisable(); }
void RTCC_Disable(void) { RTCC_SetWriteEnable(); //RTCCON |= !(1 << 15); RTCCONCLR = 0x8000; // turn off the RTCC // TODO: RTCCON.RTCSYNC, RTCCON.HALFSEC and RTCCON.RTCOE while (RTCCON & 0x40); // wait for clock to be turned off // bit 6 RTCCLKON: RTCC Clock Enable Status bit RTCC_SetWriteDisable(); }
void RTCC_SetDate(unsigned long dt) { RTCC_SetWriteEnable(); RTCCONCLR = 0x8000; // turn off the RTCC //Delayus(50); while (RTCCON & 0x40); // wait for clock to be turned off RTCDATE = dt; // Set date RTCCONSET = 0x8000; // turn on the RTCC //Delayus(50); while (!(RTCCON & 0x40)); // wait for clock to be turned on RTCC_SetWriteDisable(); }
void RTCC_SetTime(unsigned long tm) { RTCC_SetWriteEnable(); RTCCONCLR = 0x8000; // turn off the RTCC //Delayus(50); while (RTCCON & 0x40); // wait for clock to be turned off RTCTIME = tm; // Set time RTCCONSET = 0x8000; // turn on the RTCC //Delayus(50); while (!(RTCCON & 0x40)); // wait for clock to be turned on RTCC_SetWriteDisable(); }
void RTCC_SetCalibration(int cal) { rtccTime t0; if (cal < -512) cal = -512; if (cal > 511) cal = 511; if (RTCCON & 0x8000) // if RTCC is ON { t0 = RTCC_GetTime(); if ((t0.seconds & 0xFF) == 00) // we're at second 00, wait auto-adjust to be performed while(!(RTCCON & 0x2)); // wait until second half... } RTCC_SetWriteEnable(); RTCCONCLR = 0x03FF0000; // clear the calibration RTCCONbits.CAL = cal; RTCC_SetWriteDisable(); }
void RTCC_SetAlarmTime(u32 alTime) { rtccTime t0; u8 dummy; t0.l = alTime; RTCC_SetWriteEnable(); RTCC_Wait(); ALRMCFG = 0x00; // clear the ALRMEN, CHIME, AMASK and ARPT; ALRMRPT = 0; // clear Alarm repeat counter ALRMCFGbits.ALRMPTR1 = 0; ALRMCFGbits.ALRMPTR0 = 1; // ALRMPTR = 01 = Weekday/Hours ALRMVALL = t0.hours; dummy = ALRMVALH; // dummy read of RTCVALH to auto-decrement RTCPTR // ALRMPTR = 00 = Minutes/Seconds ALRMVALL = t0.seconds; ALRMVALH = t0.minutes; RTCC_SetWriteDisable(); }
void RTCC_SetAlarmDate(u32 alDate) { rtccDate d0; u8 dummy; d0.l = alDate; RTCC_SetWriteEnable(); RTCC_Wait(); ALRMCFG = 0x00; // clear the ALRMEN, CHIME, AMASK and ARPT; ALRMRPT = 0; // clear Alarm repeat counter ALRMCFGbits.ALRMPTR1 = 1; ALRMCFGbits.ALRMPTR0 = 1; // ALRMPTR = 11 = Reserved/Year ALRMVALL = d0.year; dummy = ALRMVALH; // dummy read of RTCVALH to auto-decrement RTCPTR // ALRMPTR = 10 = Month/Day ALRMVALL = d0.dayofmonth; ALRMVALH = d0.month; // ALRMPTR = 01 = Weekday/Hours ALRMVALH = d0.dayofweek; // ALRMPTR = 00 = Minutes/Seconds RTCC_SetWriteDisable(); }