Interfacing DS3231/DS1307 with PIC12F1822 and I2C LCD | Electronics Developer

Опубликовано: 24 Декабрь 2024
на канале: Electronics Developer
274
like

-------------------------
📌Introduction
-------------------------
This post shows how to make a real time clock using PIC12F1822 microcontroller and DS3231 RTC chip (or DS1307 RTC) where time and date are displayed on 16×2 LCD. The DS3231 as well as the 16×2 LCD are connected to the same I2C bus with the PIC12F1822 microcontroller. The LCD is provided with PCF8574 I/O expander which makes it an I2C LCD. In this project the DS3231 (DS1307) and the I2C LCD share the same I2C bus which means the SDA lines of the two devices are connected together and the SCL lines also, that minimizes number of pins used.
Time and date are displayed on the 16×2 LCD and they can be set with two push buttons connected to the PIC12F1822 microcontroller. With two pins for the I2C bus and two other pins for the push buttons, the microcontroller will use 4 pins

-------------------------
📌 Designing and Working
-------------------------
(All grounded terminals are connected together)

The PIC12F1822 microcontroller has one hardware I2C module with SDA on pin RA2 (#5) and SCL on pin RA1 (#6).The I2C LCD and the DS3231 (or DS1307) board share the same I2C bus which means the SDA line of the I2C LCD (presented by PCF8574) and the DS3231 RTC chip are connected together with RA2 pin of the PIC12F1822 MCU, the SCL line of the I2C LCD and the SCL line of the DS3231 are connected together with RA1 pin of the PIC12F1822 MCU.

The two push buttons in the circuit are used to set time and date of the real time clock, button 1 (B1) is connected to RA5 pin (#2) and button 2 (B2) is connected to RA4 pin (#3) of the PIC12F1822 MCU.PIC12F1822 internal oscillator is used (@8MHz) and MCLR pin (RA3) is configured as an input pin.
-------------------------
📌 Tags
-------------------------
#PIC12F1822 #DS1307 #digital_clock

-------------------------
📌 The Code
-------------------------
Given In Comment Section
The code below works with DS3231 and DS1307 without any modification. It was tested with CCS C compiler version 5.051.To be able to compile the C code below, a driver for the I2C LCD is required,
I2C LCD driver

I2C LCD and DS3231 (DS1307) share the same I2C bus and the PIC12F1822 MCU communicates only with 1 device at a time depending on the address, the I2C LCD address is 0x4E and the DS3231 (the DS1307 also) address is 0xD0.

📌 Tune With us so you never miss any update
-------------------------------------------------------------------------------------------------------------------------------------------------------------
🏷️Telegram : https://t.me/electronicsdeveloper
🏷️Facebook :   / electronicsdeveloper  
🏷️Instagram :   / electronics_developer  
🏷️Tweeter : https://twitter.com/Electronics_Dev?s=09
🏷️LinkedIn :   / electronics-with-shreyash  
🏷️Pinterest :   / electronics_developer  

Copyright Disclaimer under Section 107 of the copyright act 1976
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Copyright Disclaimer under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favour of fair use.

---------------------------------------------------------------------------------------------------------------------------------------------------------------
About Electronics Developer : YouTube certified creative essentials and asset monetization
---------------------------------------------------------------------------------------------------------------------------------------------------------------