This project demonstrates interfacing a DS1307 Real-Time Clock (RTC) module with a PIC16F877A microcontroller and displaying the current time and date on a 16x2 LCD. The communication with the RTC is handled through I2C protocol using the MSSP module of PIC.
-
Microcontroller: PIC16F877A (PIC16 Series)
-
Features:
- Real-time Clock functionality using DS1307 RTC
- Display Time (HH:MM:SS) and Date (DD/MM/YY) on 16x2 LCD
- I2C Communication (MSSP Module)
- BCD to ASCII conversion for LCD display
- Supports Proteus Simulation and Real Hardware Implementation
-
Application: Digital Clock Systems, Embedded Real-Time Applications, Academic Projects.
- PIC16F877A Development Board
- 16x2 LCD (HD44780 Compatible)
- DS1307 RTC Module with Battery Backup
- Pull-up Resistors (4.7kΩ) for I2C Lines
- Crystal Oscillator (20 MHz)
- Capacitors (22pF for oscillator)
- Power Supply (5V regulated)
- Breadboard, Jumpers, Resistors
- MPLAB X IDE + XC8 Compiler (for code compilation & HEX generation)
- Proteus Design Suite (for circuit simulation)
- PICkit2/3 Programmer (if flashing to hardware)
pic-rtc-clock/
├── src/
│ └── main.c # C Source Code for RTC & LCD Interfacing
├── simulation/
│ └── project.pdsprj # Proteus simulation file
└── README.md # Project Overview & Instructions
-
Open MPLAB X IDE.
-
Create a New Project:
- File > New Project > Standalone Project
- Select Family: Mid-Range 8-bit MCUs (PIC16)
- Device: PIC16F877A
-
Add Source File:
- Right-click 'Source Files' > Add Existing Item.
- Select
main.c
from/src/
.
-
Configure Compiler Settings:
- Go to Project Properties.
- Set XC8 Compiler options if needed.
-
Build the Project:
- Click Build Project (Hammer Icon).
- HEX file will be generated in the
/dist/
folder.
-
Proteus component libraries:
- PIC16F877A Microcontroller
- DS1307 RTC Module
- HD44780 LCD (16x2)
- Pull-up Resistors for I2C lines
- Crystal Oscillator (20MHz) + Capacitors
-
Open Proteus Design Suite.
-
Open the Provided Simulation File:
- Navigate to
/simulation/
folder. - Open
rtc-clock.pdsprj
.
- Navigate to
-
Load HEX File to PIC16F877A:
- Double-click PIC16F877A symbol.
- In Program File field, browse and select the compiled HEX file.
-
Run Simulation:
- Click Play (Run Simulation).
- LCD will initially display “Time:” on Line 1 and “Date:” on Line 2.
- After setting initial time via code, the RTC will maintain timekeeping.
- LCD will continuously update current time in HH:MM:SS and date in DD/MM/YY format every half second.
- LCD is interfaced in 8-bit mode via PORTD (Data lines) and PORTB (Control lines RB0-RB2).
- DS1307 communicates over I2C using MSSP Module on PORTC (SCL/SDA).
- The code initializes the RTC with a default time/date and continuously reads current values.
- Data from RTC (in BCD) is converted to ASCII and displayed on LCD.
- I2C start, stop, read, write sequences are handled using SSPCON2bits for reliable communication.
Start
|
|---> Initialize LCD Display
|---> Initialize I2C (MSSP Module)
|---> Write Default Time & Date to DS1307
|
Main Loop:
|
|---> Generate I2C START Condition
|---> Send RTC Slave Address with Write Bit
|---> Send Register Address to Read From (Seconds)
|---> Generate Repeated START Condition
|---> Send RTC Slave Address with Read Bit
|---> Sequentially Read 7 Bytes (Time & Date)
|---> Generate I2C STOP Condition
|
|---> Convert BCD Values to ASCII
|---> Display Time on LCD Line 1 (HH:MM:SS)
|---> Display Date on LCD Line 2 (DD/MM/YY)
|
Repeat Main Loop
- The LCD operates in 8-bit mode, connected to PORTD.
- The RS, RW, EN control signals are connected to RB0, RB1, RB2 respectively.
- I2C Lines (SCL/SDA) on RC3/RC4 require external 4.7kΩ pull-up resistors.
- The initial time is set in code via DS1307_write() function.
- The RTC maintains time using its onboard battery, even if PIC is powered off.
-
LCD Not Displaying?
- Check contrast potentiometer and LCD wiring.
- Ensure correct control pins (RB0, RB1, RB2).
-
RTC Not Communicating?
- Verify pull-up resistors on SCL/SDA lines.
- Check crystal oscillator stability.
-
Incorrect Time/Date Displayed?
- Ensure initial time values are correctly written to DS1307.
- Verify BCD to ASCII conversion logic.
-
Simulation Lags/Freezes?
- Reduce simulation speed or increase system clock in Proteus.
This project is licensed under the MIT License. You are free to use, modify, and distribute this code and simulation files.
- Simulation Circuit Diagram (RTC + LCD + PIC16F877A)
- LCD displaying Real-Time Clock Interface
- Close-up of I2C connections with pull-up resistors
GOKUL KRISHNA K S