Epson S1C33L03 User Manual

Page of 631
III PERIPHERAL BLOCK: CLOCK TIMER
B-III-7-2
EPSON
S1C33L03 FUNCTION PART
Control and Operation of the Clock Timer
Initial setting
At initial reset, the clock timer's counter data, setup contents of alarms, and control bits including RUN/STOP,
are not initialized. (This does not include the CPU core power on/off flag TCHVOF or OSC1 auto-off flag
TCAOFF.)
Therefore, when using the clock timer, initialize it as follows:
1. Before you start setting up, stop the clock timer and disable the clock timer interrupt.
2. Reset the counters.
3. Preset the minute, hour, and day data (only when necessary).
4. Select an interrupt factor.
5. Select the alarm function.
6. Enable the interrupt.
7. Start the clock timer.
The following shows how to set and control each of the above. For details on interrupt control, refer to
"Interrupt Function".
Resetting the counters
Each counter of the clock timer can only be reset to "0" in the software. Note that they are not reset by an
initial reset or the auto-off function.
To reset the clock timer, write "1" to TCRST (D1) / Clock timer Run/Stop register (0x40151). Note, however,
that this reset input is accepted only when the clock timer is inactive, and is ignored when the timer is
operating.
Notes: • The clock timer reset bit TCRST and the clock timer RUN/STOP control bit TCRUN are located
at the same address (0x40151). However, the clock timer cannot be reset at the same time it is
set to RUN by writing "1" to both. In this case, the reset input is ignored and the timer starts
counting up from the counter values then in effect. Always make sure TCRUN = "0" before
resetting the timer.
• When the counters are cleared as the clock timer is reset, an interrupt may be generated
depending on the timer settings. Therefore, first disable the clock timer interrupt before resetting
the clock timer, and after resetting the clock timer, reset the interrupt factor flag, interrupt factor
generation flag, and alarm factor generation flag.
Presetting minute, hour, and day data
The clock timer's minute, hour, and day counters have a data preset function, enabling the desired time and
day to be set.
Table 7.1  Presetting the Counters
Counter
Data register
Preset value
Minute counter
TCHD[5:0] (D[5:0]) / Clock timer minute register (0x40155)
0 to 59
Hour counter
TCDD[4:0] (D[4:0]) / Clock timer hour register (0x40156)
0 to 23
Day counter
TCND[15:0](D[7:0]) / Clock timer day (high-order) register (0x40158)
(D[7:0]) / Clock timer day (low-order) register (0x40157)
0 to 65535
When using the clock timer as an RTC, be sure to set these counter values before starting operating of the
clock timer. For the day counter, set a number of days starting from the reference day (e.g., January 1, 1990).