and the program is given below Code explanation is below the code
complete project file can be downloaded with this link real time clock
What is real time clock
The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2 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
Uses of Real time clock
-It is generally used in computers, laptops, mobiles, embedded system devices etc.
-In many embedded system applications, we need to put time stamp while logging data i.e. sensor values, GPS coordinates etc. for getting timestamp we need to use RTC (Real Time Clock).
-In some microcontrollers like LPC2148, LPC1768 etc., have on-chip RTC but in ATmega16 / 32 microcontroller do not have on-chip RTC. So we have to use external RTC chip
Here I have used different concept of microcontroller
To learn about LCD please follow this link
To learn about I2C please follow this link
To learn about RTC DS1307 follow this link
after that you will able to understand this project 🙂 trust me
Programming of RTC DS1307
Initially, while using RTC first time, we have to set the clock and calendar values, then RTC always keep updating this clock and calendar values.
We will set the RTC clock and calendar values in 1st step and in 2nd step we will read these value.
Step1: Setting Clock and Calendar to RTC DS1307
- In RTC coding, we require first RTC device address (slave address) through which microcontroller wants to communicate with the DS1307.
- DS1307 RTC device address is 0xD0 (given in data sheet).
- Initialize I2C in ATmega16 /32.
- Start I2C communication with device write address i.e. 0xD0.
- If address is matched we get acknowledgement signal, this bit is ninth bit of address.
- Send the Register address of seconds which is 0x00, then send the value of seconds to write in RTC. RTC address gets auto incremented so next, we only have to send the values of minutes, hours, day, date, month and year.
- And then stop the I2C communication.
Step2: Reading Time and Date value from RTC DS1307
- In the second step we learn how to read the data from the RTC, i.e. second, minute, hours, etc.
- Start the I2C communication with device write address i.e. 0xD0.
- Then write the register value from where we have to read the data (we read from location 00 i.e. read the second).
- Then repeated start I2C with device read address i.e. 0xD1.
- Now Read the data with acknowledgement from location 00.
- For read the last location always read with the negative acknowledgement, then device will understand this is the last data read from the device.
- For read next location of register address will get auto incremented.