Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Real-Time Clock (RTC) Using PIC Microcontroller

This document outlines a project to create a Real-Time Clock (RTC) using a PIC microcontroller and an external RTC module, detailing the necessary components, circuit diagram, and step-by-step implementation. The project includes interfacing with a 16x2 LCD display and using push buttons for time adjustment. It serves as an educational tool for understanding I2C communication and embedded systems applications.

Uploaded by

Jorge Oliveira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Real-Time Clock (RTC) Using PIC Microcontroller

This document outlines a project to create a Real-Time Clock (RTC) using a PIC microcontroller and an external RTC module, detailing the necessary components, circuit diagram, and step-by-step implementation. The project includes interfacing with a 16x2 LCD display and using push buttons for time adjustment. It serves as an educational tool for understanding I2C communication and embedded systems applications.

Uploaded by

Jorge Oliveira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Making Electronics Easy Sign in 0

Home Buy Electronics Products Services Training & Internships Find Jobs Career Guidance Free Plans Earn

Search... Internships Order Projects

Sanskruti Ashtikar Nov 15, 2024 5 min read

Real-Time Clock (RTC) Using PIC Microcontroller


Updated: Jan 6

Introduction

A Real-Time Clock (RTC) is an essential component in many embedded systems, providing accurate timekeeping for applications like digital clocks,
data loggers, and other devices that require precise time management. In this project, we’ll explore how to build a simple yet effective RTC using a
PIC microcontroller and an external RTC module.

System Overview

The system is designed to keep track of the current time (hours, minutes, and seconds), as well as the date (day, month, and year). We will use a
DS1307 or DS3231 RTC module for timekeeping, interfaced with a PIC microcontroller. The current time and date will be displayed on a 16x2 LCD
screen. Additionally, the time can be set or adjusted using push buttons.

Components Required

1. PIC Microcontroller (e.g., PIC16F877A) - The main controller for handling RTC data and interfacing with peripherals.
2. RTC Module (DS1307/DS3231) - Keeps accurate time and date, even during power outages.
3. 16x2 LCD Display - Displays the time and date.
4. Push Buttons - For setting or adjusting the time and date.
5. Pull-up Resistors - Required for the I2C communication lines.
6. Resistors, Capacitors, and Potentiometer - Basic components for interfacing and setting up the circuit.
7. Breadboard and Connecting Wires - For assembling the circuit.
8. Power Supply - To power the system.

Circuit Diagram
We use cookies and similar technologies to enable services and functionality on our site and to understand
Get in Touch AskAccept
Us!!
your interaction with our service. By clicking on accept, you agree to our use of such technologies for Cookie Settings
marketing
Below is aand analytics.
basic circuit See Privacy
diagram Policy how the components are connected to the PIC microcontroller:
illustrating
[Insert a circuit diagram here showing connections:

- SDA and SCL pins of the RTC module connected to the I2C pins of the PIC microcontroller (e.g.,
RC3 and RC4).

- LCD connected to PORTD for data and control signals.

- Push buttons connected to digital I/O pins with pull-up resistors.

Working Principle

The RTC module (DS1307/DS3231) communicates with the PIC microcontroller via the I2C protocol. The microcontroller reads the current time and
date from the RTC module and displays it on the LCD. Users can set or adjust the time using push buttons, with the updated time being written
back to the RTC module.

Step-by-Step Implementation

Step 1: Setting Up the Development Environment

Before starting with the hardware, ensure you have the necessary software tools installed:
MPLAB X IDE - Integrated Development Environment for writing and debugging code for PIC microcontrollers.
XC8 Compiler - A compiler for converting C code into a hex file that the PIC microcontroller can understand.

Step 2: Writing the Code

Start by initializing the PIC microcontroller, setting up the I2C communication, and configuring the LCD.

Code Outline:

#include <xc.h>

#include "lcd.h" // Include LCD library

#include "i2c.h" // Include I2C library for PIC

#include "rtc.h" // Include RTC library for DS1307/DS3231

#define _XTAL_FREQ 20000000 // Define the crystal frequency (20MHz)

// Configuration bits for PIC16F877A

#pragma config FOSC = HS // High-Speed Oscillator

#pragma config WDTE = OFF // Watchdog Timer Disabled

#pragma config PWRTE = OFF // Power-up Timer Disabled

#pragma config BOREN = ON // Brown-out Reset Enabled

#pragma config LVP = OFF // Low Voltage Programming Disabled


We use cookies and similar technologies to enable services and functionality on our site and to understand
Get in Touch
#pragma
your interaction withconfig CPDBy=clicking
our service. OFF on// DatayouEEPROM
accept, agree toMemory
our use ofCode ProtectionforDisabled
such technologies
marketing and analytics. See Privacy Policy
#pragma config WRT = OFF // Flash Program Memory Write Enable

#pragma config CP = OFF // Flash Program Memory Code Protection Disabled

void main(void) {

// Initialize LCD

Lcd_Init();

Lcd_Clear();

// Initialize I2C communication

I2C_Init();

// Initialize RTC (DS1307/DS3231)

RTC_Init();

// Variable declarations

unsigned char sec, min, hour, day, date, month, year;

while(1) {

// Read the time from the RTC

sec = RTC_Get_Second();

min = RTC_Get_Minute();

hour = RTC_Get_Hour();

day = RTC_Get_Day();

date = RTC_Get_Date();

month = RTC_Get_Month();

We use cookies andyearsimilar=technologies to enable services and functionality on our site and to understand
RTC_Get_Year();
Get in Touch
your interaction with our service. By clicking on accept, you agree to our use of such technologies for
marketing and analytics. See Privacy Policy
// Display time on LCD

Lcd_Set_Cursor(1, 1);

Lcd_Write_String("Time: ");

Lcd_Write_Char((hour / 10) + '0');

Lcd_Write_Char((hour % 10) + '0');

Lcd_Write_Char(':');

Lcd_Write_Char((min / 10) + '0');

Lcd_Write_Char((min % 10) + '0');

Lcd_Write_Char(':');

Lcd_Write_Char((sec / 10) + '0');

Lcd_Write_Char((sec % 10) + '0');

// Display date on LCD

Lcd_Set_Cursor(2, 1);

Lcd_Write_String("Date: ");

Lcd_Write_Char((date / 10) + '0');

Lcd_Write_Char((date % 10) + '0');

Lcd_Write_Char('/');

Lcd_Write_Char((month / 10) + '0');

Lcd_Write_Char((month % 10) + '0');

Lcd_Write_Char('/');

Lcd_Write_Char((year / 10) + '0');

Lcd_Write_Char((year % 10) + '0');

__delay_ms(1000); // Update every second

Step 3: Interfacing the RTC Module

DS1307/DS3231 RTC Module : Connect the SDA and SCL pins of the RTC module to the corresponding I2C pins on the PIC microcontroller
(e.g., RC4 for SDA and RC3 for SCL). Ensure pull-up resistors (typically 4.7kΩ) are connected to the SDA and SCL lines.
Power the RTC module by connecting the VCC and GND pins to the appropriate power rails.

Step 4: Interfacing the LCD


We use cookies and similar technologies to enable services and functionality on our site and to understand
Get in Touch
your interaction
Connect with our service.
the LCD By(D4-D7)
data pins clicking to
onthe
accept, you agree to PORTD.
microcontroller’s our use of such technologies for
marketing and analytics. See Privacy Policy
Connect the RS, RW, and E control pins to the appropriate digital I/O pins on the PIC (e.g., RD0, RD1, and RD2).
Use a potentiometer to adjust the contrast of the LCD.

Step 5: Push Button Interface

Connect push buttons to digital I/O pins on the PIC microcontroller (e.g., RB0, RB1) with pull-up resistors. These buttons will be used to set or
adjust the time and date.

Step 6: Compiling and Uploading the Code

Write the code in MPLAB X IDE and compile it using the XC8 compiler to generate a hex file.
Upload the hex file to the PIC microcontroller using a programmer (e.g., PICkit 3).

Step 7: Testing and Adjusting the System

Power up the circuit. The current time and date should be displayed on the LCD. Use the push buttons to set the correct time and date, if
necessary. Ensure that the time updates every second and the date rolls over correctly at midnight.

Applications

Digital Clocks : Use this project as the basis for a standalone digital clock.
Data Loggers : Integrate the RTC with sensors to timestamp data readings.
Home Automation : Schedule tasks or events based on the time.

Conclusion

Creating a Real-Time Clock using a PIC microcontroller is an excellent way to learn about I2C communication, LCD interfacing, and timekeeping in
embedded systems. The project can be expanded with additional features like alarms, event scheduling, or even wireless synchronization with
other devices. The skills and concepts learned in this project are applicable in various fields, making it a valuable addition to your portfolio of PIC
microcontroller projects.

Want us to guide you through your project or make the project for you ?

Order Projects

Create Various Projects


Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check
We out our Free
use cookies NodeMCu
and similar Projects to
technologies Playlist
enable- NodeMCu Projects
services and functionality on our site and to understand
Get in Touch
your interaction with our service. By clicking on accept, you agree to our use of such technologies for
marketing and analytics. See Privacy Policy
Related Posts See All

50+ Instrumentation 60+ Interview 60+ Interview Question


Engineer Interview… Questions and Answer… and answers for Data…

11 0 8 0 3 0

Home Order a Project Certified Courses


Order Projects Embedded Projects Arduino Basics Course
Blogs IoT/Wi-Fi Projects IoT for Beginners
Courses VLSI Projects Embedded Systems using 8085
Trainings FPGA Projects Introduction to Raspberry Pi - Pico
Interview Q & A Home Automation Projects Introduction to Electronics
Find Jobs Place Customized Order More Courses
Career Guidance

Trending Projects Buy Projects Interview Q&A


Digital Piano using Ardui… IoT based Robo Car Proje… Electronics Engineer Interview Quest…
Arduino based Alarm Clo… IoT Controlled Robotic Arm P… PCB Designer Interview Questions
Digital Voltmeter using Ar… Home Automation Project Embedded Engineer Interview Quest…
Smart Parking System Pr… Smart Farming Project Robotics Engineer Interview Questio…
Smart Home Project More Paid Projects
We use cookies and similar technologies to enable services and functionality on our site and to understand
Electrical Engineer Interview Questi…
Get in Touch
your interaction with our service. By clicking on accept, you agree to our use of such technologies for More Interview Questions
marketing and analytics. See Privacy Policy
Trending Articles Events Training Programs
Top 50 Arduino Projects Project Competition Arduino Training
Top 50 IoT Projects Workshops Embedded Systems Traini…
Top 50 Home Automation… Webinar IoT Training
Top 50 FPGA Projects Quiz Competition FPGA Training
Top 50 VLSI Projects Hackathon Other Customized Training

Other Services Buy Circuits Buy Project Code


Order Project Code Smart Lighting System Ci… Gas Leakage Detection Project Co…
Order Project Circuits Attendance System Project Ci… Line Follower Robot Proje…
Order Proteus Projects Fire Alert using SMS Projec… RC Car Project Code
Order DIY Projects Object Detection Project Ci… Home Automation Project…
Order More More Project Circuit Diagr… More Project Codes

Social Policies More Links


LinkedIn Shipping Policy Bundles
Instagram Privacy Policy Memberships
Facebook Terms of Use Loyalty Programs
Youtube Refund Policy Electronics Forum
WhatsApp Cookie Policy FAQs
Email

Contact & Connect with us Where are we located?


learnelectronicsindia.com@gmail.com We are a Virtual Company founded in
Silvassa, D&NH - 396230

+91-7600948607

We use cookies and similar technologies to enable services and functionality on our site and to understand
Get in Touch
your interaction with our service. By clicking on accept, you agree to our use of such technologies for
marketing and analytics. See Privacy Policy

You might also like