How to Interface RTC DS12C887 with 8051 microcontroller (AT89C51)

Summary

The purpose of an RTC or a real time clock is to provide precise time and date which can be used for various applications. RTC is an electronic device in the form of an Integrated Chip (IC) available in various packaging options. It is powered by an internal lithium battery. As a result of which even if the power of the system is turned off, the RTC clock keeps running. They play a very important role in the real time systems like digital clock, attendance system, digital camera etc.

 
The article presented here shows how RTC can be interfaced with the microcontroller AT89C51. It explores the basic operation of accessing the internal registers and extracting time from the RTC. The time is displayed on the hyper terminal using serial communication. The RTC used here is DS 12C887. 89C51 microcontroller is a very commonly used controller from the family of 8051 series of microcontroller.
 
Our forthcoming articles and projects on RTC DS12C887 and 8051 microcontroller will further explore RTC’s interrupts and help you in making applications based on RTC and microcontroller.
For more details on RTC12C887, click here.
 
 
How to Interface RTC DS12C887 with 8051 microcontroller (AT89C51)

Description

 

This project uses the method of polling to read the data from the RTC. In this method the data is continuously scanned and sent to hyper terminal for display. The connections of RTC DS 12C887 and serial port (RS232) with the 8051 microcontroller (AT89C51) are shown in the circuit diagram.

 
Note: This RTC is shipped with internal oscillator turned off to prevent the discharge of lithium battery. If you are interfacing the RTC for the first time i.e. the RTC is absolutely new, then you need to turn on the oscillator through your program. This is done by setting a pattern of 010 in bits 4-6 of register A. The code in this article shows how to set these bits. Once set the RTC will keep updating itself even if you are not using it and keeping it in store. Whenever you are using the RTC for the next time you need not turn on the oscillator. Hence in our future articles you will not find such steps in code. 
 
This code provides the way to interface an RTC with a microcontroller and extract data from it and send it to the computer through serial port.
 
The code uses the XBYTE macro which is defined in the header file ‘absacc.h’ to access external memory peripherals interfaced with the microcontroller. The use of macro simplifies the read and write operations of the RTC. The XBYTE macro takes care of the control signals needed to read and write data to the RTC thus making the interfacing easy for us.

The source code for interfacing RTC DS12C887 with 8051 microcontroller AT89C51 is written in C. First of all the clock is set, through XBYTE, with the time which we want (defined in microcontroller) to start the clock. Then the time kept in the clock is extracted through XBYTE and sent to PC’s hyper terminal through serial port.
 


Circuit Diagram

Video

Code

This Code is only visible to Registered users. Please Login/Register

 

Components

MAX232 | IC MAX232
MAX232
 
The MAX232 IC is used to convert the TTL/CMOS logic levels to RS232 logic levels during serial communication of microcontrollers with PC. The controller operates at TTL logic level (0-5V) whereas the serial communication in PC works...
AT89C51 Microcontroller, Atmel 89C51 Controller Image
AT89C51 Microcontroller

AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (...

RTC DS12C887 Image
RTC DS12C887

RTC DS 12C887 is widely used to provide exact time and date in many applications such as x86 IBM PC. This RTC provides time components hour, minute and second in addition to the date/calendar components of year, month and day. This chip uses an internal lithium battery, which keeps the time and da...