Getting Started with the RTCC on the PIC16F19176
Check out this project's MPLAB Xpress Webpage to view the complete code example along with a detailed step by step write-up and description, or visit the PIC16F19176 Device Product Page for more information.
About this Code Example
The objective of this example is to demonstrate how to get started with the Real Time Clock & Calendar Module that is found on the PIC16(L)F191xx family of devices using MCC.
This project will show how to configure the time and calendar settings of the RTCC module, and will configure a basic alarm. The PIC16F19176 was used for this example. LED D2 blinks every every time the SECONDS value within the RTCC module changes, and LED D5 will blink whenever an alarm condition is met. In addition to LED D5 blinking with every alarm condition, an audible tone will be played using the Piezo Buzzer Click Board.
Board Connection & Setup:
The development board used for this example was the Curiosity HPC Development Board. The MikroElektronika Buzz Click board was also used to provide an audible tone for the alarm conditions generated by the RTCC module. The hardware used for the USB to EUSART serial conversion was the Microchip MCP2200 Breakout Module. The RTCC module clock source in this example was configured to be the SOSC module, and the Citizen CFS-206 32.768kHz crystal was tied to the SOSCI and SOSCO pins along with two 10 pF capacitors (as seen in the screen shot below).
Curiosity HPC Development Board Setup:
RTCC Module Setup & Configuration:
The RTCC module is an integrated 100-year clock and calendar with automatic leap year detection and correction. The range of the clock is from 00:00:00 (midnight) on January 1st, 2000 to 23:59:59 on December 31st, 2099. The RTCC module uses the 24-hour time format (military time). It offers VBAT battery backup to allow the RTCC and SOSC modules to continue running from an external power supply (battery or supercapacitor) in the event of a VDD failure.
The RTCC module was initialized with the current time in this example within the MCC generate initialization routine, and the RTCC alarm was configured to repeat every 10 seconds. The RTCC clock source was configured as the secondary oscillator (SOSC), and an interrupt service routine was created to blink an LED and sound the Piezo Buzzer whenever an alarm condition is detected (RTCCIF = 1). Below are the key registers used when configuring the RTCC module on the PIC16F19176.
- RTCC Current Time & Date information (These each have their own respective registers)
- RTCC Alarm Time & Date information (These each have their own respective registers)
- RTCC Write Enable Bit (RTCWREN) - This determines whether registers are locked out from writes
- RTCC Enable Bit (RTCEN) and Alarm Enable bit (ALRMEN)
- RTCC Clock Selection Bits - RTCCLKSEL<1:0>
- Alarm Repeat Register (ALRMRPT) - Determines how many times alarm repeats
- Alarm Chime Bit (CHIME) - Determines whether alarm repeat register rolls over
- Alarm Mask Config Bits (AMASK<3:0>) - Determines frequency of alarm once condition is met
The RTCC module was added into this example using MCCr. The screenshot below shows the configuration settings used for this module.
VBAT Backup Setup & Configuration:
The PIC16(L)F191xx family of devices allow the user to utilize a "VBAT" pin that enables the user to connect an external battery or power supply. This can help ensure that the SOSC and RTCC modules continue running in the event of a VDD power supply failure, and that the RTCC data is not lost. The VBAT pin on this device is located on RA5. Battery backup functionality is enabled by setting the VBATEN bit of Configuration Word 1 (VBATEN = ON).
Driving the MikroElektronika Buzz Click Board:
The MikroElektronika Buzz Click board that was used in this example is driven using a PWM signal, with the tone and volume dependent on frequency and duty cycle. The PWM4 and TIMER2 modules were both added to this project using MCC so that we could drive the Buzz Click board to produce an audible tone with each alarm event from the RTCC module. The screenshot below shows the configuration settings that were used within MCC. Please note that the duty cycle for the PWM output signal was initiazlied to be 0%, and will be updated within the RTCC interrupt service routine as the RTCC alarm is triggered.
EUSART Module Setup & Configuration:
The EUSART module is implemented in this example to display the current time and date information from the RTCC module. In addition to continually updating with the current time and date information via serial port, a message will be sent via serial port to the PC whenever an alarm condition has been triggered. The USART2 module was added into the project using MCC. The screenshot below shows the configuration settings used for this module in MCC.
PPS Setup & Configuration (MCC)
The screenshot below shows the pin assignments / PPS settings that were configured in MCC using the Pin Manager View for each respective module in this example.
This example demonstrates how to use the RTCC module to keep accurate track of time and date in an application. It also demonstrates how to initialize and use the alarm feature, and is configured to drive the MikroElektronika Buzz Click to play an audible alarm tone every 10 seconds. In addition to the alarm tone, LED D5 on the Curiosity HPC Development Board will also light up whenever an alarm is detected. The code that handles the alarm event can be found in the RTCC ISR function in the "rtcc.c" file of the project.
RTCC Interrupt Service Routine:
The EUSART module was used in this example to display the RTCC time and date information from a PC. The RTCC information is sent to the PC via serial port and updated every second. Whenever an alarm event is detected the code will jump into the RTCC Interrupt Service Routine, and a message will be sent to the PC via serial port that signifies an alarm condition has been detected. The screenshot below shows an example of what the EUSART output should look like on your PC.
EUSART Output on PC:
For more information about the PIC16F19176, or the Real Time Clock and Calendar Module, please refer to the device datasheet linked at the bottom of this example. In addition to the datasheet, refer to the RTCC + VBAT Technical Brief for more information. Comment below with any questions!
- Dec 4, 2018