RTCC Alarm Configuration

When configuring the alarm feature of the RTCC, the first step is to ensure that the RTCWREN bit is set to allow RTCC register writes. The user should also verify that the alarm is in a disabled state before performing any register updates. The ALRMEN bit will be cleared every time an alarm is issued, if the ALRMRPT register has decremented to zero and the CHIME bit is configured to not allow rollovers. If the CHIME bit is enabled, the alarm repeat register (ALRMRPT) will be allowed to continuously roll over rather than stopping once it decrements to zero.The frequency which the alarm is repeated can be configured using the AMASK<3:0> bits of the ARMCON register and can be selected to be anywhere from every ½ second to once a year.

The ALRMRPT register is used to determine how many times the configured alarm is repeated. The user can set this to repeat anywhere from 0 to 255 times until the RTCC alarm is disabled. The CHIME bit of the alarm configuration register determines if the alarm repeat counter rolls over and restarts when it reaches zero. Similar to when initializing the time and date settings for the RTCC module start condition, there are several alarm specific registers that must be initialized to determine the date and time of the first alarm event. This information written to the alarm registers must be implemented using the Binary Coded Decimal (BCD) format that is explained in Section Reading/Writing RTCC Using Binary Coded Decimal (BCD) Format. Once all of the alarm configuration registers have been updated and initialized, the final step for the user is to enable the alarm by setting the ALRMEN bit of the ALRMCON register and clear the RTCC Write Lock bit. If the RTCC module is still disabled at this point, the user would need to enable the RTCC module by setting the RTCEN bit of the RTCCON register and then clear the Write Lock bit to prevent accidental writes to any of the RTCC registers. Example 2-1 demonstrates how to configure the alarm and shows the remainder of the initialization routine that was started in Example 1-1. Note that the RTCWREN bit was already set and the RTCC module was already disabled in the first part of the initialization routine.

RTCC Module Initialization (Part 2)

ALRMCONbits.ALRMEN = 0;	// Alarm is disabled;
ALRMRPT = 0xFF; // Alarm Repeat Register;

	// Set RTCC Alarm Time:05/22/2018 @ 12:30:10
	ALRMMTH = 0x5;	// month;
	ALRMWD = 0x2;	 // weekday;
	ALRMDAY = 0x22;   // day;
	ALRMHR = 0x12;	// hours;
	ALRMMIN = 0x30;   // minutes;
	ALRMSEC = 0x10;   // seconds;
	
ALRMCONbits.ALRMEN = 1;	// Re-enable the alarm
ALRMCON = 0xC8;	        // AMASK Every 10 Second; CHIME enabled;
RTCCONbits.RTCEN = 1;	  // RTCC Module is enabled
While(!RTCCONbits.RTCEN);
RTCCONbits.RTCWREN = 0;	// RTCC Registers Write Lockout;
PIR8bits.RTCCIF = 0;	   // Clear RTCC Interrupt Flag;
PIE8bits.RTCCIE = 1;	   // Enable RTCC Interrupt (Alarm);