Real Time Clock with 2 Alarms Using PIC18F4550 and DS1307 – CCS C

Real time clock with two alarms using DS1307 RTCC and PIC18F4550 microcontroller

We have seen how to make a simple real time clock and calendar using PIC18F4550 microcontroller and DS1307 RTC chip at:
Real time clock with PIC18F4550 and DS1307 RTC

Now let’s see how to add 2 alarms to the previous project with some changes.
About DS1307 RTC:
The DS1307 is an 8-pin integrated circuit uses I2C communication protocol to communicate with master device which is in our case the PIC18F4550 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.
The DS1307 uses an external 32.768KHz crystal and there is no need to add any resistors or capacitors with it.
The time and calendar information is obtained by reading the appropriate register bytes. The time and calendar are set or initialized by writing the appropriate register bytes. The contents of the time and calendar registers are in the BCD format. The following table shows the DS1307 RTC registers:

DS1307 registers

More details in the DS1307 RTC datasheet.

Real time clock with 2 alarms using PIC18F4550 and DS1307 circuit:
PIC18F4550 DS1307 alarms circuit

Required Components:

  • PIC18F4550 Microcontroller
  • DS1307
  • 2004 (20×4) LCD
  • 3V Cell Battery
  • 32.768KHz crystal oscillator
  • 2 x 10K resistors
  • 10K Potentiometer
  • 470Ohm resistor
  • 3 Buttons
  • LED (For Alarm 1)
  • Buzzer (For Alarm 2)
  • +5V Power Supply
  • Protoboard
  • Jumper Wires

In this project PIC18F4550 microcontroller internal oscillator is used (8MHz) and MCLR pin function is disabled.

Real time clock with 2 alarms using PIC18F4550 and DS1307 C code:
Tested with CCS PIC C compiler version 5.051.

Project video:

1 thought on “Real Time Clock with 2 Alarms Using PIC18F4550 and DS1307 – CCS C”

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