# Interfacing DS1307 RTC with PIC16f882

I am trying to interface DS1307 RTC with the MCU mentioned. I want to make a lifetime timer which tells the time this project has worked in field, and display this timer on an LCD.

I am new to microcontrollers but using LCD and I2C libraries already built-in in the MikroC pro for PIC compiler will I hope save me from low-level programming.

Now if I understand correctly, the steps to write or read something from the RTC would be:

1) I2C_Start();
4) I2C_Write(Data to be written);
5) I2C_Stop();


1) I2C_Start();
4) I2C_Repeated_Start();
6) I2C_Rd();
7) I2C_Stop();


My issue is that what will the DS1307_Address be, if it is the only device on the Bus?

My approach will be to set the BIT7 of 00h or CH bit of the DS1307 low whenever the device is running, and set it high just before shutting down. I do not want the RTC to count the project off time as well. Is this approach feasible?

My schematic is as following:

• The addresses of I2C devices are usually given in their datasheet. – Eugene Sh. Aug 8 '16 at 14:29
• Your read sequence needs another step between 3 and 4 - an "I2C Restart". – brhans Aug 8 '16 at 14:31
• Page 12. Reading datasheets is one of the most essential skills for one dealing with electronics. With assistance of Ctrl-F it takes like 20 seconds. – Eugene Sh. Aug 8 '16 at 14:35
• There is a I2C_Repeated_Start function. Tak a look at the examples on this page – Eugene Sh. Aug 8 '16 at 14:42
• You can't modify a single bit. You need to read, mask, write. But I can see a small problem here. The seconds can be updated (not more than once, though, but still) during this sequence, so you will loose one second. If you don't really care about the slowly accumulated error, you can ignore it. – Eugene Sh. Aug 8 '16 at 14:55