Interfacing DS1307 Real time clock with PIC16f877

In any advance project we need real time clock synchronize with our work and for this purpose the best option is DS1307 (RTC Ic). Interfacing DS1307 Real time clock with PIC16f877 is done by I2C communication. To know I2C protocol you may refer my previous post “Interfacing external EEPROM with PIC Microcontroller”.  To know about Interfacing DS1307 Real time clock with PIC16f877, we should know something about DS1307 IC.

Real time clock ( DS1307):

The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The DS1307 operates as a slave device on the I2C bus. Access is obtained by implementing a START condition and providing a device identification code followed by a register address. Subsequent registers can be accessed sequentially until a STOP condition is executed.

Interfacing DS1307 Real time clock with PIC16f877 schematic

Project Description:

In this project we will see how we interfaced DS1307 with pic16f877 via I2C protocol. After interfacing DS1307 we recive the data from DS1307 and display it on LCD. Weall ready know before that DS1307 is send data in full BCD format. So we have to convert this data in digit and send to display on LCD.

Now question is how we convert BCD number to 4 bit number?

For getting higher nibble we use command

return ((bcd >> 4) + ‘0’) : it means the number will be Binary Right Shift 4 times with loading zero on left side.

For getting Lower nibble we use command

return ((bcd & 0x0F) + ‘0’) : it means we did and operation 0F with BCD number.


For more detail: Interfacing DS1307 Real time clock with PIC16f877

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us: