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.