8051 – RTC Interfacing (Alarm Clock)

In this project, we are going to see RTC Interfacing with 8051. Before that we should know about the RTC (DS1307) operations. Let’s start.

Prerequisites

RTC (DS1307)

Introduction

The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I²C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.

Features

  • Completely Manages All Timekeeping Functions
    • Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
    • 56-Byte, Battery-Backed, General-Purpose RAM with Unlimited Writes
    • Programmable Square-Wave Output Signal
  • Simple Serial Port Interfaces to Most Microcontrollers
    • I2C Serial Interface
  • Low Power Operation Extends Battery Backup Run Time
    • Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running
    • Automatic Power-Fail Detect and Switch Circuitry
  • 8-Pin DIP and 8-Pin SO Minimizes Required Space
  • Optional Industrial Temperature Range: -40°C to +85°C Supports Operation in a Wide Range of Applications
  • Underwriters Laboratories® (UL) Recognized

VCC, GND: These pins are used to provide the power to the chip. When 5V is applied within normal limits, the device is fully accessible and data can be written and read. When a 3V battery is connected to the device and VCC is below 1.25 x VBAT, reads and writes are inhibited. However, the timekeeping function continues unaffected by the lower input voltage. As VCC falls below VBAT the RAM and timekeeper are switched over to the external power supply (nominal 3.0V DC) at VBAT.

X1-X2:Pins to connect the external 32.768kHz oscillator that provides the clock source to the chip.

Vbat: A 3.3v Lithium battery can be connected to this pin in order to provide the power source when the external supply voltage is not available. Battery voltage must be held between 2.0V and 3.5V for proper operation.

SCL: This pin must be connected to SCL pin of the I2C Bus/Master.

SDA: This pin must be connected to SDA pin of the I2C Bus/Master.

SQW/OUT: When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square wave frequencies (1Hz, 4kHz, 8kHz, 32kHz).

  • Note: The SCL,SDA and SQW are open drain and must be pulled up with appropriate pull up resistors

Connection circuit

DS1307 requires very less number of components to operate. One of the mandatory component is the crystal oscillator of 32.768kHz. The battery backup is optional as you can connect power source to Vbatt pin. But It is good to have battery connected. When running on battery it only consumes 500 nA of current just for the operation of clock and to maintain content of NV RAM. Your can use a coin cell type battery as backup source for DS1307.

Following image shows typical connection diagram for DS1307 RTC.

DS1307 Memory

All the registers of DS1307 stores value as BCD, i.e. if clock is at 49 seconds then register 0x00 will show 0x49 as binary coded decimal value of 49. This makes it easy for programmer to read and display number on LCD or serial terminal. So if you want to use register values of RTC then first convert the value from BCD to decimal and then use it.

The RTC keeps the date and time arranged in it’s memory as shown below:

Register 0x07 is control register for square wave output pin. RS0 and RS1 bit selects the output frequency as per table below:

You can also use SQW/Out pin as GPO pin, when SQW function of DS1307 is not used. Bit 7 controls the output level of the pin. If OUT bit is 1 then OUT pin is high and when 0 OUT pin will be low.

RTC Interfacing with 8051

DS1307 uses I2C Protocol and act as a slave device and I2C Master can read/write register of RTC. To communicate with the slave device, master need the slave address of device connected on bus. DS1307 has fixed slave address which makes it impossible to connect two RTC devices on same bus, don’t worry occurrence of such a scenario is close to zero.
Slave address for I2C Write: 0b11010000 = 0xD0
Slave address for I2C Read: 0b11010001 = 0xD1

Components Required

  • 8051 Development board
  • LCD Module
  • Keypad
  • RTC DS1307
  • Buzzer

Circuit Diagram

EXPLANATION

  • The RTC is connected to the Port 3.

  • The LCD data lines are given to the Port2. RS is given to port pin P0.0, RW to P0.1and enable to P0.2.

  • Keypad is connected in to P1.

  • Buzzer is connected into P0.7.

Programming

In this code, I’m printing the Time, Date in LCD Module. There are two switches. One is for set alarm and another one is for set time and date. Keypad is used to enter the time and date. Whenever time is matching to alarm, buzzer makes sound to indicate us. Here i have posted only main code. If you want to download the full project, please click Here .

Hardware Setup

RTC Interfacing with 8051Output

EXPLANATION

  • Here RTC DS1307 is connected into 8051 with help of I2C.

  • The details of time and date are given into the micro controller

  • Keypad is used to set the time, date and alarm.

  • LCD is used to display the time and date.

  • If alarm occurs buzzer will be activated.

Watch On Youtube : Digital Alarm Colock

[sociallocker]                                      [Download this Project ][/sociallocker]

If you want PPT and Report for this Project Please contact us. In subject please mention the project name. Contact Us.

Download our new Android app. You can learn all Embedded Tutorials from your Android Phone easily.

Click Here to Download App!