Rev. 5.00, 09/03, page 424 of 760
13.3.4 Alarm Function
Figure 13.4 shows how to use the alarm function.
Alarms can be generated using seconds, minutes, hours, day of the week, date, month, or any
combination of these. Set the ENB bit (bit 7) to 1 in the register to which the alarm applies, and
then set the alarm time in the lower bits. Clear the ENB bit to 0 in registers to which the alarm
does not apply.
When the clock and alarm times match, 1 is set in the AF bit (bit 0) in RCR1. Alarm detection can
be checked by reading this bit, but normally it is done by interrupt. If 1 is placed in the AIE bit (bit
3) in RCR1, an interrupt is generated when an alarm occurs.
Disable interrupts for preventing error
interrupts (clear the AIE bit in RCR1 to 0).
Then write 1 to the AIE bit in RCR1.
Clock running
Set alarm time
Set whether to use
alarm interrupt
Always reset, since the flag may have
been set while the alarm time was being
set (clear the AF bit in RCR1 to 0).
Clear alarm flag
Monitor alarm time
(wait for interrupt or
check alarm flag)
Figure 13.4 Using the Alarm Function