The last interfacing of the PIC16F887 microcontroller and DS3231 RTC is the building of a simple real time clock and calendar with two buttons for setting time and date. Project link is the one below:
Interfacing DS3231 with PIC16F887 microcontroller
In this topic I’m going to add 2 alarms and temperature monitor to the previous project since the DS3231 has 2 alarm functions and temperature sensor with an accuracy of ±3°C (for more information read the DS3231 datasheet).
- PIC16F887 microcontroller
- 20×4 LCD screen
- 10K ohm variable resistor
- 330 ohm resistor
- 3 x push button
- 5V supply source
- Jumper wires
DS3231 board contains the following components:
- DS3231 RTC – datasheet
- 3 x 4.7K ohm resistors
- 0.1uF ceramic capacitor
- 3V coin cell battery
Circuit schematic diagram is shown below.
In this project I used the DS3231 board, this board basically contains the main chip which is the DS3231, pull-up resistors (4.7K) of SCL, SDA and INT/SQW lines and coin cell battery holder. There is also 24C32 EEPROM and some other resistors (not used in this project).
The DS3231 board is supplied with 5V as the microcontroller and the 2004 LCD, there are 3 data lined connected between this board and the PIC16F887 MCU, SCL line is connected to pin RC3, SDA is connected to pin RC4 and INT line is connected to pin RB0 which is the external interrupt pin of the PIC16F887 MCU. The DS3231 interrupts the microcontroller when there is an alarm.
In the circuit there are 3 push buttons: B1, B2 and B3. These buttons are used to set time, calendar and alarms. Time and calendar can be adjusted with B1 and B2, button B1 selects time or date parameter (time parameters: hours and minutes; calendar parameters: day, date, month and year) and B2 increments the selected parameter. The button B3 and B2 adjust alarm1 and alarm2 parameters (hours, minutes and ON/OFF), button B3 selects the parameter and B2 increments the selected parameter.
There is an LED connected to pin RB4, this LED is used as an alarm indicator (alarm1 or alarm2), so if there is an alarm the DS3231 pulls down the INT pin which interrupts the microcontroller and the microcontroller turns the LED ON, here button B2 turns both the LED and the occurred alarm OFF.
In this project the PIC16F887 MCU uses its internal oscillator and MCLR pin function is disabled.
Read more: Real time clock and temperature monitor using PIC16F887 and DS3231