4/15/13 DS12887 RTC INTERFACINGwhat-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/ 2/11
The real-time clock (RTC) is a widely used device that provides accurate time and date for many applications. Manysystems such as the x86 IBM PC come with such a chip on the motherboard. The RTC chip in the IBM PC providestime components of hour, minute, and second, in addition to the date/calendar components of year, month, and day. TheRTC chip uses an internal battery, which keeps the time and date even when the power is off. Although some 8051family members, such as the DS5000T, come with the RTC already embedded into the chip, we have to interface thevast majority of them to an external RTC chip. One of the most widely used RTC chips is the DS 12887 from DallasSemiconductor/Maxim Corp. This chip is found in the vast majority of x86 PCs. The original IBM PC/AT used theMC14618B RTC from Motorola. The DS 12887 is the replacement for that chip. It uses an internal lithium battery tokeep operating for over 10 years in the absence of external power. According to the DS 12887 data sheet from Maxim,it keeps track of “seconds, minutes, hours, days, day of week, date, month, and year with leap-year compensation validup to year 2100″. The above information is provided in both binary (hex) and BCD formats. The DS 12887 supports both 12-hour and 24-hour clock modes with AM and PM in the 12-hour mode. It also supports the Daylight SavingsTime option. The DS 12887 uses CMOS technology to keep the power consumption low and it has the designationDS12C887, where C is for CMOS. The DS12887 has a total of 128 bytes of nonvolatile RAM. It uses 14 bytes oRAM for clock/calendar and control registers, and the other 114 bytes of RAM are for general-purpose data storage. Inthe x86 IBM PC, these 114 bytes of NV-RAM are used for the CMOS configuration, where the system setups are kept before the operating system takes over. Next we describe the pins of the DS 12887. See Figure 16-1.
Pin 24 provides external supply voltage to the chip. The external voltage source is +5V. When V
falls below the 3Vlevel, the external source is switched off and the internal lithium battery provides power to the RTC.This nonvolatile capability of the RTC prevents any loss of data. According to the DS12887 data sheet “the RTCfunction continues to operate, and all of the RAM, time, calendar, and alarm memory locations remain non-volatileregardless of the level of the V
input.” However, in order to access the registers via a program, the V
must besupplied externally. In other words, when external V
is applied, the device is fully accessible and data can be writtenand read. When V
falls below 4.25 volts, the read and write to the chip are prevented, but the timekeeping and RAMcontents are unaffected, since they are nonvolatile.
It must also be noted that “when V
is applied to the DS12887