Interfacing PIC16F84A with DS1307 real time clock

This topic shows how to interface DS1307 real time clock chip with PIC16F84A microcontroller, how to write data to the DS1307 RTC and how to read data from the DS1307 RTC.
Related topics:
Real time clock using PIC16F877A microcontroller and DS1307 serial RTC
Real time clock with PIC18F4550 and DS1307 RTC

The DS1307 is an 8-pin integrated circuit uses I2C communication protocol to communicate with master device which is in our case the PIC16F84A 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 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 PIC16F84A with DS1307 RTC:
The following image shows the interfacing circuit schematic diagram.
PIC16F84A DS1307 RTC circuit
The PIC16F84A must be supplied with 5V on pins VDD and VSS.
The circuit is clear and simple. The LCD is used to display the time as well as the date.

Interfacing PIC16F84A with DS1307 RTC CCS C code:
The following C code is the full code of this project.

software I2C is used at 100KHz because PIC16F84A does not have hardware I2C module.
First the microcontroller writes clock 18:35:00 and date 17/05/16 and after writing the time and date the microcontroller starts and endless loop (while(TRUE)) for reading time and date from DS1307.
If you want to understand the code read the DS1307 datasheet.

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

Leave a Reply

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