Real time clock using PIC16F877A and DS1307 RTC – CCS C

Interfacing PIC16F877A with DS1307 RTC

This topic shows how to build a real time clock (RTC) using PIC16F877A microcontroller and a low cost chip which is DS1307.
The DS1307 is an 8-pin integrated circuit uses I2C communication protocol to communicate with master device which is in our case the PIC16F877A microcontroller. This small chip can count seconds, minutes, hours, day, date, month and year with leap-year up to year 2100.
The DS1307 receives and transfers data (clock data and calendar data) as BCD format, so after receiving data we have to convert these data into decimal data, and before writing data to the DS1307 we have to convert this data from decimal to BCD format. For example we have the BCD number 33, converting this number into decimal gives 21.
The following image shows the DS1307 pin configurations:
DS1307 RTC pin configuration

And the following circuit is typical operating circuit for the DS1307 RTC:

DS1307 RTC basic circuit

A 3V battery can be connected between VBAT and GND which can be used as a backup supply input.
The DS1307 uses an external 32.768KHz crystal and there is no need to add any resistors or capacitors with it.
More information are in the DS1307 RTC datasheet.

Interfacing PIC16F877A with DS1307 RTC: 
The following image shows the interfacing circuit schematic diagram.
PIC16F877A DS1307 RTC with buttons circuit
The circuit is clear and simple. The LCD is used to display the time as well as the date. There are two push buttons to adjust time and date as shown in the video below.

Interfacing PIC16F877A with DS1307 RTC CCS C code:
The following C code is the full code of this project.
PIC16F877A hardware I2C module is used at 100KHz.

Interfacing PIC16F877A with DS1307 RTC video:
The following video shows a hardware circuit of this project with some details about the circuit.


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top