
Please read the DS3231 datasheet to understand the code.Hi everyone! This is my first instructable! After reading hundreds of instructables, I decided to make one myself.Ĭlock is one of the most essential house hold things. The C code below is for CCS PIC C compiler (tested with version 5.051). Interfacing DS3231 with PIC16F887 microcontroller CCS C code: The internal oscillator of the PIC16F887 is used and MCLR pin function is disabled.

The circuit can work without this battery but its pin (#14) has to be grounded.

The 3V cell battery is used as a backup to keep time and date running in case of main power failure. The two buttons which are connected to pins RB0 and RB1, these buttons are used to set the time as well as the date as shown in the videos below. Two pull-up resistors of 10K are needed for the SCL and SDA lines, if these two resistors are not connected to whole circuit will not work at all and the LCD may not display any thing. The SCL and SDA pins of the DS3231 are connected to SCL (RC3) and SDA (RC4) pins of the PIC16F887 microcontroller. Interfacing DS3231 with PIC16F887 microcontroller circuit:Īs we can see in the circuit there is a 16x2 LCD to display time and date, this LCD is connected to PORTD. 0.1♟ capacitor (decoupling capacitor needed for the DS3231).The PIC16F887 has a hardware I2C module where the SCL and SDA pins are mapped to RC3 and RC4 respectively. Like the DS1307, the DS3231 uses I2C protocol which uses two lines SCL and SDA. This topic shows the interfacing of the DS3231 RTC with PIC16F887 microcontroller with full adjustment of time and date parameters. The DS3231 RTC comes with an internal oscillator which means there is no need for a 32.768KHz crystal oscillator. The DS3231 is much better than the DS1307 which means that it is a very good choice for persons who sell real time clock products.

The datasheet of DS3231 RTC (real time clock) says that it is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperature compensated crystal oscillator (TCXO) and crystal.
