Professional Documents
Culture Documents
Real-Time Clock and Calendar Technical Brief
Real-Time Clock and Calendar Technical Brief
This technical brief describes briefly the RTCC The 1:16384 clock prescaler provides the half-second
module’s features, functionality, calibration, sample visibility to the user, and in turn allows the RTCC timer
initialization codes, and its low-power and to increment the appropriate second, minute, hour,
uninterrupted operation. It also gives an overview on weekday, day, month and year values as stored in the
what devices are suitable for the most common RTCVALx registers. These RTC values are compared
applications requiring precise timing such as digital with the user-set alarm values to trigger an alarm inter-
clocks and energy metering devices. rupt whenever a match occurs. The alarm values are
stored in the ALRMVALx registers. Alarm masks are
used to set the time interval between each alarm event
RTCC MODULE KEY FEATURES if ever multiple periodic alarm events are desired.
PIC® microcontrollers are an excellent choice for The RTCC pin can output either the seconds clock or
applications involving critical time-keeping operations an alarm pulse operating at half the frequency of the
because of the following key features of the RTCC alarm, depending on the configured settings.
module:
• Hardware Real-Time Clock and Calendar (RTCC)
• Provides hours, minutes and seconds using 24-
hour format
• Visibility of one-half second period
• Provides calendar – weekday, date, month and
year
• Alarm configurable for half a second, one second,
ten seconds, one minute, ten minutes, one hour,
one day, one week or one month
• Alarm repeat with decrementing counter
• Alarm with indefinite repeat–chime
• Year 2000 to 2099 leap year correction
• BCD format for smaller software overhead
• Optimized for long-term battery operation
ALMTHDY
Compare Registers
ALRMVALx ALWDHR
with Masks
ALMINSEC
Repeat Counter
RTCC Interrupt
RTCC Interrupt Logic Alarm Pulse
1s
RTCC Pin
RTSECSEL
RTCOE
EECON2 = 0xAA;
The RTCC Timer (RTCVALx) and Alarm Timer Example 2 shows sample code for writing to the RTCC
(ALRMVALx) registers can only be accessed through Timer registers via register pointers. RTCCON1 is
corresponding register pointers. Every write or read to named RTCCFG on some devices. Also, on some
the RTCVALH register decrements the RTCC Pointer PIC18 devices, the PADCFGx registers hold the RTCC
value (RTCPTR<1:0>) by ‘1’ until it reaches ‘00’. The Seconds Clock Output Select bits.
RTCVALH and RTCVALL Register Mapping is shown
in Table 2.
RTCCON1bits.RTCPTR = 3; //initial RTCC pointer value to prepare write to the YEAR value register
RTCVALH = 0x10; //set MONTH to October; this write will decrement pointer value by 1
RTCVALH = 0x00; //set WEEKDAY to Sunday; this write will decrement pointer value by 1
RTCVALH = 0x45; //set MINUTES to 45; RTCPTR is already 0 and can no longer be decremented
ALARM CONFIGURATION
In addition to the capability of the RTCC module to
count the time accurately, it also has an alarm feature
which is configurable from half a second to one year
and can be repeated as desired by the user.
Every write or read to the ALRMVALH register
decrements the Alarm Pointer Value (ALRMPTR<1:0>)
by ’1’. ALRMVALH and ALRMVALL Register Mapping
is shown in Table 3.
ALRMCFGbits.ALRMPTR = 2;//initial RTCC pointer value to prepare write to the ALRMDAY value register
ALRMVALH = 0x10; //set ALRMMONTH to October; this write will decrement pointer value by 1
ALRMVALH = 0x02; //set ALRMWD to Monday; this write will decrement pointer value by 1
ALRMVALH = 0x45; //set ALRMMIN to 45; ALRMPTR is already 0 and can no longer be decremented
Peripheral
Initialization
RTCC Synchronization.
RTCVALH, RTCVALL and
ALRMRPT registers change.
RTCPTR = 3
To other peripherals
®
8-Bit
RTCC in Digital Alarm Clocks Several demo boards by Microchip support RTCC
hardware and have a built-in LCD glass, which could
Figure 4 shows a sample implementation of the RTCC be good resources in developing applications using the
with the LCD Driver and the Capture/Compare/PWM RTCC with the LCD. These include the LCD Explorer
(CCP) modules for a digital alarm clock application. Demo Board (DM240314) and the PICDEMTM PIC18
The secondary oscillator (SOSC) provides the clock for Explorer Demo Board (DM183032). Several PIC
the RTCC module. Suppose that the RTCC pin is microcontrollers with RTCC also have an internal LCD
configured to output the seconds clock. This allows Driver module which could directly drive the LCD glass,
LED D1 to blink once every second. The values in the while others can use the MSSP module to
RTCVALx registers are manipulated by firmware to be communicate with the LCD while displaying the time
displayed on LCD1 through the LCD Driver module. and date.
The alarm interrupt triggers the CCP module to
generate a pulse-width modulated output which
activates the piezo buzzer (P1) on every alarm event.
The alarm duration is controlled through firmware. The
push-button switches (S1, S2, S3) are used to set the
initial RTCC time and date, as well as the alarm
settings, and one of the buttons can also be used to
trigger the start of the RTCC count.
TABLE A-1: WEB LINKS FOR 8-BIT PIC MCUs WITH RTCC MODULE
PIC18 Product Family Web Links
PIC18F46J11 http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F46J11
PIC18F47J13 http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F47J13
PIC18F47J53 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en548693
PIC18F87K22 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en546891
PIC18F87K90 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en547324
PIC18F87J50 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en027172
PIC18F87J72 http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en550260
PIC18F87J90 http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F87J90
PIC18F87J93 http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F87J93
PIC18F97J94 http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC18F97J94
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
QUALITY MANAGEMENT SYSTEM Microchip received ISO/TS-16949:2009 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
CERTIFIED BY DNV Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
== ISO/TS 16949 ==
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.