Vous êtes sur la page 1sur 11

4/15/13

DS12887 RTC INTERFACING

Subscribe what-when-how In Depth Tutorials and Information

DS12887 RTC INTERFACING

Related Searches: HTML Page Adobe Photoshop Plugins Google Search Appliance New Business Applications Internet Search Engines

Ads by Google

Alarm Clock RTC Real Time Clock RTC

This chapter shows the interfacing and programming of the DS12C887 real-time clock (RTC) chip. In Section 16.1, we Internet Search describe DS12887 RTC pin functions and show its interfacing with the 8051. In Section 16.1, we also show how to program the DS12887 in Assembly language. The C programming of DS12887 is shown inKeyword Section 16.2. The alarm and Research SQW features of the DS12287 are discussed in Section 16.3. SECTION 16.1: DS12887 RTC INTERFACING
Keyword Analysis Ad Copy Adobe Photoshop Tutorials Plugin For Photoshop

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

1/11

4/15/13

DS12887 RTC INTERFACING

The real-time clock (RTC) is a widely used device that provides accurate time and date for many applications. Many systems such as the x86 IBM PC come with such a chip on the motherboard. The RTC chip in the IBM PC provides time components of hour, minute, and second, in addition to the date/calendar components of year, month, and day. The RTC chip uses an internal battery, which keeps the time and date even when the power is off. Although some 8051 family members, such as the DS5000T, come with the RTC already embedded into the chip, we have to interface the vast majority of them to an external RTC chip. One of the most widely used RTC chips is the DS 12887 from Dallas Semiconductor/Maxim Corp. This chip is found in the vast majority of x86 PCs. The original IBM PC/AT used the MC14618B RTC from Motorola. The DS 12887 is the replacement for that chip. It uses an internal lithium battery to keep 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 valid up 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 Savings Time option. The DS 12887 uses CMOS technology to keep the power consumption low and it has the designation DS12C887, where C is for CMOS. The DS12887 has a total of 128 bytes of nonvolatile RAM. It uses 14 bytes of RAM for clock/calendar and control registers, and the other 114 bytes of RAM are for general-purpose data storage. In the 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. Vcc Pin 24 provides external supply voltage to the chip. The external voltage source is +5V. When VC9 falls below the 3V level, 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 RTC function continues to operate, and all of the RAM, time, calendar, and alarm memory locations remain non-volatile regardless of the level of the Vcc input. However, in order to access the registers via a program, the Vcc must be supplied externally. In other words, when external Vcc is applied, the device is fully accessible and data can be written and read. When Vcc falls below 4.25 volts, the read and write to the chip are prevented, but the timekeeping and RAM contents are unaffected, since they are nonvolatile. It must also be noted that when Vcc is applied to the DS12887
what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/ 2/11

4/15/13

DS12887 RTC INTERFACING

and reaches a level of greater than 4.25V, the device becomes accessible after 200ms. GND Pin 12 is the ground. ADO-AD7

The multiplexed address/data pins provide both addresses and data to the chip. Addresses are latched into the DS 12887 on the falling edge of the AS (ALE) signal. A simple way of connecting the DS 12887 to the 8051 is shown in Figure 16-2. Notice that ADO AD7 of the DS 12887 are connected directly to PO of the 8051 and there is no need for any 74xx373 latches, since the DS 12887 provides the latch internally. To access the DS 12887 in Figure 16-2, we use the MOVX instruction since it is mapped as external memory. We will discuss this shortly. AS (ALE) AS (address strobe) is an input pin. On the falling edge it will cause the addresses to be latched into the DS 12887. The AS pin is used for demultiplexing the address and data and is connected to the ALE pin of the 8051 chip. MOT This is an input pin that allows the choice between the Motorola and Intel microcontroller bus timings. The MOT pin is connected to GND for the Intel timing. That means when we connect DS 12887 to the 8051, MOT = GND. DS Data strobe or read is an input. When MOT = GND for Intel timing, the DS pin is called the RD (read) signal and is connected to the RD pin of the 8051. R/W Read/Write is an input pin. When MOT = GND for the Intel timing, the R/W pin is called the WR (write) signal and is connected to the WR pin of the 8051. CS Chip select is an input pin and an active low signal. During the read (RD) and write (WR) cycle time of Intel timing, the CS must be low in order to access the chip. It must be noted that the CS works only when the external Vcc is connected. In other words when Vcc falls below 4.25V, the chip-select input is internally forced to an inactive level regardless of the value of CS at the input pin. This is called the write-protected state. When the DS 12887 is in write-protected state, all inputs are ignored.

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

3/11

4/15/13

DS12887 RTC INTERFACING

IRQ Interrupt request is an output pin and active low signal. To use IRQ, the interrupt-enable bits in register B must be set high. The interrupt feature of the DS12287 is discussed in Section 16.3. SQW Square wave is an output pin. We can program the DS 12887 to provide up to 15 different square waves. The frequency of the square wave is set by programming register A and is discussed in Section 16.3. RESET

Pin 18 is the reset pin. It is an input and is active low (normally high). In most applications the reset pin is connected to the Vcc pin. In applications where

this pin is used, it has no effect on the clock, calendar, or RAM if it is forced low. The low on this pin will cause the reset of the IRQ and clearing of the SQW pin, as we will see in Section 16.3. Address map of the DS12887 The DS12887 has a total of 128 bytes of RAM space with addresses 00 -7FH. The first ten locations, 00 09, are set aside for RTC values of time, calendar, and alarm data. The next four bytes are used for the control and status registers. They are registers A, B, C, and D and are located at addresses 10-13 (OA OD in hex). Notice that their hex addresses match their names. The next 114 bytes from addresses OEH to 7FH are available for data storage. The entire 128 bytes of RAM are accessible directly for read or write except the following: 1. Registers C and D are read-only.
what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/ 4/11

4/15/13

DS12887 RTC INTERFACING

2. D7 bit of register A is read-only. 3. The high-order bit of the seconds byte is read-only.

Figure 16-3. DS12887 Address Map Figure 16^3 shows the address map of the DS 12887. Time, calendar, and alarm address locations and modes The byte addresses 0-9 are set aside for the time, calendar, and alarm data. Table 16-1 shows their address locations and modes. Notice the data is available in both binary (hex) and BCD formats. Table 16-1: DS12887 Address Location for Time, Calendar, and Alarm

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

5/11

4/15/13

DS12887 RTC INTERFACING

Turning on the oscillator for the first time The DS12887 is shipped with the internal oscillator turned off in order to save the lithium battery. We need to turn on the oscillator before we use the time keeping features of the DS 12887. To do that, bits D6 D4 of register A must be set to value 010. See Figure 16-4 for details of register A.

The following code shows how to access the DS12887s register A and is written for the Figure 16-2 connection. In Figure 16-2, the DS 12887 is using the external memory space of the 8051 and is mapped to address space of 00 7FH since CS = 0. See Chapter 14 for a discussion of external memory in the 8051. For the programs in this chapter, we use instruction MOVX A, @RO since the address is only 8-bit. In the case of a 16-bit address, we must use MOVX A, @DPTR as was shown in Chapter 14. Examine the following code to see how to access the DS12887 of Figure 162.

Figure 16-4. Register A Bits for Turning on the DS12887s Oscillator Setting the time When we initialize the time or date, we need to set D7 of register B to 1. This will prevent any update at the middle of the initialization. After setting the time and date, we need to make D7 = 0 to make sure that the clock and time are updated. The update occurs once per second. The following code initializes the clock at 16:58:55 using the BCD mode and 24-hour clock mode with daylight savings time. See also Figure 16-5 for details of register B.

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

6/11

4/15/13

DS12887 RTC INTERFACING

Figure 16-5. Some Major Bits of Register B Setting the date The following shows how to set the date to October 19th, 2004. Notice that when we initialize time or date, we need to set D7 of register B to 1.

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

7/11

4/15/13

DS12887 RTC INTERFACING

RTCs setting, reading, displaying time and date The following is a complete Assembly code for setting, reading, and displaying the time and date. The times and dates are sent to the screen via the serial port after they are converted from BCD to ASCII.

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

8/11

4/15/13

DS12887 RTC INTERFACING

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

9/11

4/15/13

DS12887 RTC INTERFACING

what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/

10/11

4/15/13

DS12887 RTC INTERFACING

Ads by Google

Ads by Google

Micro Controller Interfacing Clock IC

All Datasheet Device Programming Chip Programming

Next post: DS12887 RTC INTERFACING AND PROGRAMMING Previous post: DS12887 RTC PROGRAMMING IN C
1

Related Topics
8051 Microcontroller PROGRAMMING EXTERNAL HARDWARE INTERRUPTS SERIAL PORT PROGRAMMING IN C I/O PORT PROGRAMMING INTERRUPTS PROGRAMMING IN ASSEMBLY AND C 8031/51 INTERFACING WITH EXTERNAL ROM

:: Search WWH ::
Search
Custom Search

Help Unprivileged Children Careers Privacy Statement Copyright Information


what-when-how.com/8051-microcontroller/ds12887-rtc-interfacing/ 11/11

Vous aimerez peut-être aussi