PIC16F84A based digital clock using LCD display (Code+Proteus simulation)

This post provides a simple digital clock implementation using PIC16F84A microcontroller and an LCD display. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

PIC16F84A based digital clock using LCD display

In this article, it is assumed that you know,

  • How to interface LCD with PIC16F84A microcontroller. If you don’t then please read this page.
  • How to configure timer0 of PIC16F84A microcontroller.  If you don’t then please read this page.

The result of simulating the code in Proteus is shown below.

The above figure was taken after 1 minute and 6 seconds of code simulation in Proteus. In the code, timer0 is used as the base for digital clock generation. Timer0 is used here to generate 1msec interrupts. After every 1msec a global variable named msCounter increments. When msCounter reaches a value of 1000 then another global variable named secCounter increments and this process repeats itself. Similarly, when secCounter reaches 60, then  minCounter increments. And when minCounter reaches 60 then hrCounter increments. This process continues until hrCounter reaches 24 then all of these variables reset their values. LCD is updated with the new values of hrCounterminCounter and secCounter after every second.

A crystal of 4MHz value is used in this circuit, which makes this PIC16F84A run at a speed of 1MIPS (Million of instructions per second).


The main function code is shown below.

In the main function, firstly LCD is initialized using InitLCD() function. Then Timer0 is initialized to generate 1msec interrupts. After that, in the while(1) loop, whenever msCounter reaches a value of zero[1], then new values of hrCounterminCounter and secCounter are updated on the LCD. UpdateTimeCounters() function is called every time and it corrects the values of every counter variable depending upon the value of msCounter, which is incremented in the ISR function of timer0 (shown below).

 PIC16F84A based digital clock using LCD display schematic


Digital clock display code using PIC16F84A was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation, and engineering. I have a clear and simple writing style and am skilled in using infographics and diagrams. I am a great researcher and is able to present information in a well-organized and logical manner.