Reading/Writing RTCC Using Binary Coded Decimal (BCD) Format

The register interface for the RTCC module time and alarm values must be implemented using the Binary Coded Decimal (BCD) format. The BCD format is a system of representing numbers where a 4-bit wide binary code is assigned to represent the numerical value of a digit ranging from 0 through 9. Each of the corresponding time and date values are represented and contained within their own 4-bit values. For more information about writing to the Time Value and Alarm Value registers using the BCD format, refer to the RTCC section of the device data sheet. Each register in the data sheet will have specific information about the range of values of the specific time or date that the register accepts.

Figure 1-1 below illustrates the time digit and alarm digit format, along with the acceptable ranges for each numerical value. Using this format to represent the time and date values simplifies the firmware and allows for smaller software overhead. It is important to note that since the Time and Date registers for the RTCC and alarm feature are represented in the BCD format, the carry to the upper BCD digit always occurs on a count of 10 rather than a count of 16. For more information regarding the carry rules of this RTCC module, refer to the RTCC chapter of the device data sheet.

Figure 1. Time/Alarm Register Value Format (BCD)
Figure 2. Alarm Value Register Format (BCD)
Tip: When using the Microchip Code Configurator (MCC) to implement the RTCC module into a project, the APIs needed to convert from HEX to BCD and vice versa are automatically generated.