beautypg.com

3 using the rtc alarm, Tarting and, Topping the – Maxim Integrated High-Speed Microcontroller User Manual

Page 158: Etting and, Eading the, Egisters

background image

High-Speed Microcontroller User’s Guide

Rev: 062210

158 of 176

Writing to the clock registers sets the time on the DS87C530. The second, minute, hour, day of the week,
and day count can be set by writing to the respective registers. It is not possible to set the subsecond RTC
register (

RTCS

;FAh). This register is automatically reset to 00h when the RTCWE bit is cleared, either

through software or the automatic timeout of the 1.95ms write window. Writing an invalid time to these
registers (loading the

RTCM

register with 3Dh or 61 minutes, for example) will result in an inaccurate

count by the RTC. It is the responsibility of the software to ensure that only valid times are written to
these registers.

The procedure for setting an RTC time register is as follows:

1) Disable all interrupts by clearing the EA bit (

IE

.7).

2) Perform a timed-access procedure.
3) Set the RTCWE bit (

RTCC

.2).

4) Wait 4 machine cycles.
5) Write the appropriate register(s) within 1.95ms of RTCWE being set.
6) Perform a timed-access procedure.
7) Clear the RTCWE bit (

RTCC

.2).

8) Enable interrupts by setting the EA bit (

IE

.7).

14.3 Using the RTC Alarm

The RTC alarm function is used to generate an interrupt when the RTC value matches selected alarm
register values. An alarm can be triggered by a match on one or more of the following alarm registers:
subsecond (

RTASS

;F2h), second (

RTAS

;F3h), minute (

RTAM

;F4h), and hour (

RTAH

;F5h). Note that

there is no alarm register associated with the RTC day count or day of week registers. If an alarm is
desired on a specific date, an alarm can be executed once a day and user software can compare the current
date against the day register. It is not necessary to set the RTC write-enable bit, RTCWE, when setting
the alarm registers.

The alarm can be set to occur on a match with any or all of the alarm registers. An alarm can occur on a
unique time of day, or a recurring alarm can be programmed every subsecond, second, minute, or hour.
Alarms can occur synchronously, when the clock rolls over to match the alarm condition, or
asynchronously, if the alarm registers are set to a value that matches the current time. Note that only one
alarm may occur per subsecond tick. This means that if a synchronous alarm has already occurred during
the current subsecond, software cannot cause an asynchronous alarm in the same subsecond.

The specific alarm registers to be compared are selected by setting or clearing the corresponding
compare-enable bits (

RTCC

.7-4). Any compare bit that is cleared will result in that register being treated

as a don’t care when evaluating alarm conditions. Clearing all the compare enable bits will disable the
ability of the RTC to cause an interrupt, and will immediately clear the RTC interrupt flag (

RTCC

.1).

Unlike some interrupts, the RTC flag is not cleared by exiting the RTC interrupt service routine and must
be explicitly cleared in software.

The general procedure for setting the RTC alarm registers to cause a RTC interrupt is as follows:

1) Clear the ERTCI enable bit (

EIE

.5).

2) Clear all RTC alarm compare-enable bits (ANL

RTCC

, #0Fh).

3) Write one or more RTC alarm registers.
4) Set the desired RTC alarm compare-enable bits.
5) Set the ERTCI enable bit (

EIE

.5).