Real time clock with PIC18F4550 and DS1307 RTC – CCS C

Interfacing PIC18F4550 with DS1307 RTC
PIC18F4550 DS1307 real time clock hardware circuit

After interfacing DS1307 real time clock chip with PIC16F877A microcontroller at the following link:
Real time clock using PIC16F877A and DS1307 RTC – CCS C

Now let’s see how to interface DS1307 with PIC18F4550 microcontroller with full adjustment of time and date.
The microcontroller PIC18F4550 has one I2C module (SDA: RB0, SCL: RB1) which we are going to use for interfacing with 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 PIC18F4550 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 PIC18F4550 with DS1307 RTC:
The following image shows the interfacing circuit schematic diagram.

PIC18F4550 DS1307 real time clock circuit
The DS1307 needs to be supplied with 5V on pins VCC and GND.
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.

In this project PIC18F4550 microcontroller internal oscillator is used (8MHz) and MCLR pin function is disabled.

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

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

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