Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

LCD based clock using RTC DS12C887 and 8051 microcontroller (AT89C51) using update interrupt

Summary

Developed By: 
Himanshu Choudhary

This article is an improved variant of Digital clock using RTC DS12C887 and 8051 with time set. In the earlier article, we discussed the basics of extracting data from the RTC DS12C887 using the 8051 microcontroller (AT89C51). This article is in continuation to the above article and introduces you to the concept of handling interrupts for extracting time and other information from the RTC.

 
Interrupts offer a great flexibility to handle RTC. Interrupts have several advantages over the method of polling as discussed in the previous article. It reduces the unnecessary usage of microcontroller’s memory and processing powers, thereby keeping the processor free for other use. RTC 12C887 has three interrupts, namely, Alarm interrupt, Periodic interrupt & Update ended interrupt. For detailed information, check RTC interrupts. The free source code for the program is available in C.
 
 
LCD based Digital Clock with 8051 Microcontroller & RTC DS12C887

Description

This article assumes that the user is aware of real time clock and the basic interfacing of DS12C887 with 8051 microcontroller (AT89C51) including the pin description, memory and registers of RTC DS 12C887.

 

 
RTC 12C887 has three interrupts, namely, Alarm interrupt, Periodic interrupt & Update ended interrupt. For detailed information, check RTC interrupts.  All the three interrupts works independent of each other.
 
Whenever an interrupt of DS12C887 occurs the following events take place:
1.      The bit 7 and the corresponding interrupt flag of the Register C is set to 1.
2.      The IRQ pin goes low only if the enable bit of the corresponding interrupt is set in Register B.
 
Steps to handle interrupt:
1.      Connect the IRQ pin of the RTC to external hardware interrupt input pin of the microcontroller.
2.      Initialize the external hardware interrupts in the microcontroller to receive interrupt from the RTC.
3.      Initialize the interrupt(s) of the RTC to be used by configuring the corresponding bits of the Register B.
4.      Whenever an interrupt occurs read the value of Register C to check which interrupt has occurred.
 
Register B and C are used to handle interrupts. Register B is used to enable the interrupts. By setting the bits 4-6 in this register the corresponding interrupt is enabled.
 
Register C is a read only register which tells as to which interrupt has occurred by setting the corresponding flag to high whenever an interrupt has occurred. Check DS12C887 for more details on Register C. Whenever an interrupt occurs, the bit 7 of this register gets set along with the corresponding flag bit of the interrupt which has occurred. The values of flag bits get cleared either by giving a low to the RESET pin or simply reading the value of Register C.
 
The Register C is updated every time an interrupt occurs irrespective of whether we are using the interrupt or not. In case this Register C is not cleared after the first interrupt and the second interrupt has occurred than in that case the value of the flag corresponding to the first interrupt is retained in the Register C.
 
The pin 19 (interrupt request output, IRQ pin) of the RTC is used to indicate the occurrence of an interrupt. This is an output pin of the RTC and it goes low only when the following conditions are matched simultaneously:
1.      Any of the three interrupt occurs.
2.      The enable bit of the corresponding interrupt is set in Register B.
 
This pin can be used to provide external hardware interrupt to the microcontroller. This pin is multiplexed to all the three interrupts i.e., it goes low whenever any of the interrupt occurs and hence indicates that an interrupt has occurred. However to identify which interrupt has occurred it is required to read the value of the Register C. The IRQ pin will remain low, until the flag bit of the interrupt remains high in the Register C and the corresponding enable pin in Register B is set. Once an interrupt has occurred it is required to clear the IRQ pin so that the RTC is ready to serve the next interrupt. The IRQ pin can be cleared by either of the two ways:
1.      A low signal on reset pin will clear the IRQ pin.
2.      By reading the Register C, the IRQ pin will be cleared by the processor.
 
In this code we have used the second method to clear the IRQ pin. Reading the register C will also tell as to which interrupt has occurred.
 
The connection of the RTC DS12C887 with the microcontroller is shown in the circuit diagram. This article uses update interrupt to keep the track of the time. Every time the update interrupt comes, the clock is incremented by one second. The output is displayed on the LCD. The clock presented in this article also has the provision of setting the time. The clock uses external interrupt 2 of the microcontroller AT89C51 for setting the time. A user can set time by pressing the switch connected to pin 13 of the microcontroller, which is interrupt 2. The hour and minutes can be set using pin 5 and pin 6 of the controller AT89C51 respectively. Once the time is set, the user needs to press the start pin (pin 8 of controller) to start the clock. The code for interfacing RTC DS12C887 is written in C.

 

Circuit Diagram

Video

Code

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

 

Components

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 (...

16 x 2 LCD | 16x2 Character LCD Module
LCD

 

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments...

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...

Browse 4m+ Electronic Products


 
Pick the right product for your next design project with "Mouser Store". Mouser Electronics brings broadest range of semiconductors and electronic components from over 500 industry leading suppliers. 
 
Mouser specializes in the rapid introduction of new products and technologies for design engineers and buyers that includes semiconductors, interconnects, passives, and electro-mechanical components. Providing the best possible service with the flexibility of not requiring a minimum order and same-day shipping, Mouser has it all.
 
 
 
 
When you need the right part right now, think of Mouser
 
Thank you
Team EG

 

You are here