Real Time Clock with Alarms Using PIC16F877A and DS1307 – CCS C

Real time clock with alarms using PIC16F877A and DS1307

This topic shows how to make a real time clock and calendar with 2 alarms using PIC16F877A microcontroller, 2004 LCD and DS1307 serial RTC.
The following video shows what I’m going to do:

To see how to interface the DS1307 RTC chip with PIC16F877A to make a real time clock read the following topic:
Real time clock using PIC16F877A microcontroller and DS1307 serial RTC

About DS1307 RTC IC:
The DS1307 is an 8-pin integrated circuit uses I2C communication protocol to communicate with master device which is in our case the PIC16F877A microcontroller. This small chip can count seconds, minutes, hours, day, date, month and year with leap-year up to year 2100.
The DS1307 receives and transfers data (clock data and calendar data) as BCD format, so after receiving data we have to convert these data into decimal data, and before writing data to the DS1307 we have to convert this data from decimal to BCD format. For example we have the BCD number 33, converting this number into decimal gives 21.
The following image shows the DS1307 pin configurations:

DS1307 RTC pin configuration

And the following circuit is typical operating circuit for the DS1307 RTC:

DS1307 RTC basic circuit

A 3V battery can be connected between VBAT and GND as a backup supply input which keeps the DS1307 oscillator running when the main power supply of the circuit is off.
The DS1307 uses an external 32.768KHz crystal and there is no need to add any resistors or capacitors with it.
More informations in the DS1307 RTC datasheet.

RTC with 2 alarms using PIC16F877A and DS1307 circuit:
Project circuit schematic is shown below.
PIC16F877A DS1307 alarm circuit with buttons

Hardware Required:

  • PIC16F877A Microcontroller
  • DS1307
  • 2004 (20×4) LCD
  • 3V Cell Battery
  • 8MHz and 32.768KHz crystal oscillators
  • 2 x 22pF capacitors
  • 3 x 10K resistors
  • 10K Potentiometer
  • 470Ohm resistor
  • 3 Buttons
  • LED (For Alarm 1)
  • Buzzer (For Alarm 2)
  • +5V Power Supply
  • Protoboard
  • Jumper Wires

Real Time Clock with 2 Alarms using DS1307 RTCC and PIC16F877A CCS C code:
This is the full code of this project…..It is easy! be patient!

8 thoughts on “Real Time Clock with Alarms Using PIC16F877A and DS1307 – CCS C”

  1. An error occurred in line 19 while compiling. Error 44: Internal Error – Contact CCS PPUSE. How do I correct it?
    comment corrige le problème

  2. RECEP METHAN ORHAN

    An error occurred in line 19 while compiling. Line 17(6,56)Error 44:Internal Error – Contact CCS PPUSE. How do I correct it?

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top