Interfacing of PIC16F877 with DS1307 (RTC) code and Proteus simulation

This post provides the code for interfacing DS1307 RTC with PIC16F877 microcontroller. This DS1307 RTC has i2c based interface. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

Interfacing of PIC16F877 with DS1307 (RTC)
It is assumed that you know how to interface LCD with PIC16F877 microcontroller in 4bit mode. If you don’t then please read this page first, before proceeding with this article. It is also assumed that you know how to use i2c module in PIC16F877, if you don’t then please read this page first.

The result of simulating the code in Proteus is shown below.

Interfacing of PIC16F877 with DS1307 (RTC) code schematic

In the above circuit[1], RC4 pin is being used as SDA pin and RC3 pin is the SCK pin. Both of these pins are pulled up using 10K resistors as required for i2c protocol. DS1307 RTC is the slave device, while PIC16F877 is configured to be the master. LCD is also attached with PIC16F877, just to show the values received from the RTC, otherwise it is not required in this circuit. Proteus provides an ‘I2C Debugger Tool‘ which is attached on the SDA and SCK pins in the above circuit, this debugger shows all the activity on i2c bus[2]. It is attached in the circuit just for debugging purposes.

Code

The code for the main function is shown below.

Downloads

DS1307 RTC interfacing with PIC16F877 code was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

 

For more detail: Interfacing of PIC16F877 with DS1307 (RTC) code and Proteus simulation

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter