Digital clock ds1307 using PIC microcontroller

Digital clock using ds1307 and PIC microcontroller

Digital clock using ds1307 and pic16f877a microcontroller is designed in this project. Digital clock using ds1307 displays time and date on LCD. PIC16F877A microcontroller is used to design digital clock. I2C communication protocol is used to read time and date from digital clock ds1307. PIC16F877A microcontroller is interfaced with LCD to display time and date. Digital clock ds107 use I2C serial communication proctol to send data to microcontroller. pic16f877a microcontroller receives data from ds1307 through I2C serial communication protocol. I will discuss it detail in later part of this article. Before reading this article further, you should know how to interface LCD with PIC16F877A microcontroller. If you don’t know, I recommend you to read following article first.

Digital clock DS1307

DS1307 is an integrated circuit based real time clock. It counts minutes, seconds, hours, date of month, days and years. It also have functionality to include leap year compensation up to 2100. It is binary coded decimal clock (BCD). This clock operates in either in 12 hour or 24 hour format. Indication of Am and Pm can also be included on LCD display through programming. It also have automatic power failure circuit. Automatic power failure circuit detects power failure and switch to 3 volt battery to keep record of time. It have battery back up. Battery back up is used to keep record of time in case of main power failure. It have 56 bytes non-volatile RAM for data storage. DS1307 use two wire serial communication I2C. It consumes very less power and current in the order of 500nA.  It can operate in harsh temperature environment in the range of -40ºC to +85°C.

Digital clock DS1307 Pin configuration

It is 8-pin DIP IC. Pin configuration of DS1307 is given below:

DS1307 pin configuration

Description of each pin is given below:

  • SQW/OUT : Square wave and output driver pin
  • SCL: Serial clock used for I2C communication
  • SDA : Serial data pin for I2C serial communication
  • GND: Ground pin of power supply is connected with this pin
  • VBAT : It is 3 volt back up battery. It is use in case of main power failure
  • X1 and X2 : 32.768 crystal connects with these pins
  • Vcc : Main power supply connects with this pin

Digital clok DS1307 interfacing with microcontroller

Now I will discuss how to interface digital clock ds1307 with microcontroller. Basic block diagram of digital clock interfacing with microcontroller is given below:

Digital clock ds1307 interfacing with microcontroller


In I2C serial communication, one device acts as a slave and other device acts as a master. Slave only respond to instructions of master. Slave can not give instructions to master. Digital clock DS1307 acts as a slave and respond to instructions of microcontroller. Built in register in ds1307 is used to respond to instructions of microcontroller. As shown in above circuit diagram, SCL pin of ds1307 is connected to SCL pin of microcontroller. It is used to synchronize serial data on serial wire. SCL stands for serial clock input. SDA stands for serial data input/output.  SDA pin of ds1307 is connected with SDA pin of microcontroller. SDA is used as a serial data input or output for 2 wire serial communication. SDA pin of ds1307 is open drain that is why its required external pull up resistor as shown in figure above. Standard 32.876KHz quartz crystal is used with real time clock ds1307.

Circuit diagram of digital clock ds1307 using pic microcontroller

Circuit diagram of digital clock ds1307 using pic mirocontroller is given below. DS1307 real time clock is interfaced with PIC16F877A microcontroller. Instructions for interfacing real time clocl ds130 is given. 3 volt battery is used as back up which is used in case of main power supply faliure.PIC16F877A microcontroller fetch time and date values from DS1307 real time clock. After doing some calculations through programming, PIC16F877A microcontroller displays time and date on LCD.

Digital clock DS1307 using pic microcontrollerCode of digital clock DS1307 using pic microcontroller

Code for real time clock using DS1307 and pic microcontroller is written using Mikro C pro compiler. Necessary comments are also made in code for your understanding.[sociallocker]

digital clock code part1

digital clock code part2

digital clock part 3

digital clock part 4

digital clock part 5

digital clock part 6

digital clock part 7


digital clock part 8

digital clock part 9

[/sociallocker]If you need code for digital clock DS1307 using pic microcontroller, comment on this post with your email address. If you feel any issue while designing digital clock project, let me know with your comments.


  1. mohammad June 3, 2015
    • BILAL Malik June 3, 2015
      • mohammad July 3, 2015
        • ujong emmanuel February 7, 2016
  2. thong June 22, 2015
  3. thong June 22, 2015
  4. mourad June 22, 2015
    • mourad July 14, 2015
  5. mourad July 14, 2015
  6. Jorli July 20, 2015
  7. mani August 5, 2015
  8. Tengku Asyraf August 13, 2015
  9. Tengku Asyraf August 13, 2015
  10. nurul aina November 25, 2015
  11. Adnan Saood November 26, 2015
  12. Tarikul Islam December 7, 2015
  13. Michael Maged December 8, 2015
  14. Emperor December 12, 2015
  15. sharaf December 29, 2015
  16. anurag January 9, 2016
    • BILAL Malik January 10, 2016
      • SUJIN C March 19, 2017
  17. Mujib Rahaman January 10, 2016
  18. Joe January 21, 2016
  19. isaac January 21, 2016
  20. adam February 4, 2016
  21. bk February 21, 2016
  22. Matthew February 23, 2016
  23. ilyes February 23, 2016
  24. janix February 26, 2016
  25. abraham March 6, 2016
  26. Amos March 24, 2016
  27. nurul March 28, 2016
  28. shalu March 31, 2016
  29. EHle April 1, 2016
  30. youcef April 2, 2016
  31. SATHISH April 2, 2016
  32. Joshua April 3, 2016
  33. Yasmin Amru April 11, 2016
  34. abdallah April 12, 2016
  35. Rida April 15, 2016
  36. Joe April 22, 2016
  37. ahmed imraj May 5, 2016
  38. rami May 8, 2016
  39. shan May 8, 2016
  40. Adil May 12, 2016
  41. waheedullah May 18, 2016
  42. Abdul July 22, 2016
  43. Malik Saad August 9, 2016
  44. Umair sayed August 15, 2016
  45. Sajid August 16, 2016
  46. Abdelrhman Ehab Samir August 16, 2016
  47. Janie Starlix August 23, 2016
  48. sameera s ranasinghe August 31, 2016
  49. farees September 1, 2016
  50. RIYA October 16, 2016
  51. October 31, 2016
    • October 31, 2016
  52. omkar November 2, 2016
  53. omkar November 2, 2016
  54. Amirul November 14, 2016
  55. Renato November 18, 2016
  56. deepali pawar November 26, 2016
  57. Cate Stephen December 13, 2016
  58. dunk December 19, 2016
  59. adi suyahman December 31, 2016
  60. M IDREES KHAN February 15, 2017
  61. SUJIN C March 19, 2017

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 899 other subscribers