Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Digital clock with 8051(89c51,89c52) microcontroller 16×2 lcd and 4×4 numeric keypad

By EG Projects May 3, 2019

Here is a simple project on how to make a digital clock with 8051(89c51,89c52) microcontroller. The clock is efficient and their is no difference in time even in milli seconds. You can verify it with the digital clock you have. In the project i utilized the 8051 microcontroller internal clock source to produce a delay exactly equal to 1 second. This delay is then used to build a efficient clock with 89c51 microcontroller. Usually digital RTC(real time clocks) are interfaced with microcontrollers to make a digital clock. But i utilized the internal timers of 89c51 microcontroller to generate a precise time for making a clock with 8051 microcontroller. 16×2 lcd is interfaced with 8051 microcontroller to display time on lcd. Time in minutes, hours and seconds will be displayed on 16×2 lcd. 4×4 numeric keypad is also part of the 8051 digital clock project. It is used to set time, user manually enters the minutes and hours by pressing the buttons of 4×4 numeric keypad. Buttons represents numbers on keypad. 
89c51 microcontroller digital clock

89c51 microcontroller digital clock

8051 microcontroller clock – Project requirements

  • 16×2 lcd                        (To display time)
  • 8051                              (89c51 or any of 8051 series microcontroller)
  • Potentiometer/variable resistor                (For setting LCD contrast)
  • Crystal(11.0592 MHz)    (For clock generation)
  • 4×4 keypad                     (For setting time)
  • 5 volts power supply for driving lcd and microcontroller.​

89c51 microcontroller digital clock – Project circuit diagram

Connect 4×4 keypad with Port-1 of 8051(89c51) microcontroller. Connect 16×2 lcd with Port-2 of microcontroller. The rs (register set) pin of 16×2 lcd is connected to Port-3 pin#5 and en(enable) pin is connected to Port-3 Pin#6 of microcontroller. Ground rw(Read-Write) Pin of 16×2 lcd. Attach crystal of frequency 11.0592 MHz to Pin# 18 and 19 of 8051 microcontroller. I used Crystal of frequency 11.0592 MHz.  For reset connect a push button to Pin#9 of microcontroller. To set contrast attach a potentiometer/variable resistor to contrast pin of lcd. ​​
digital clock with 8051(89c51,89c52) microcontroller

digital clock with 8051(89c51,89c52) microcontroller

The code of the project is very complex. If you are newbie it will be very hard to grab all the information in the code. I can not explain each and every statement of code here. I made separate tutorials on how to interface 16×2 lcd and 4×4 numeric keypad with 89c51 microcontroller? If you don’t know about keypad and lcd interfacing with microcontrollers i recommend to take all the tutorials. You have to take each tutorial to fully understand the code. Because each component programming is different with other. Lcd is interfaced in 8-bit mode with 8051 microcontroller. To understand the working of 16×2 lcd take the tutorials whose links are below.  Key-pad coding is very easy take the tutorial.

Note: These tutorials are very important because the coding in the project heavily depends on these tutorials. 

  1. How 16×2 lcd is programmed.
  2. Difference between 8-bit and 4-bit lcd interference.
  3. difference between commands and data send to 16×2 lcd.
  4. 4×4 numeric keypad programming.

​Time delay generation is also very difficult using 8051(89c51,89c52) microcontroller. You have to be familiar with the internal timer registers of the 8051. For delay generation take the following tutorials.

  1. How to give one second delay using 8051.
  2. How to give one minute delay using 8051.​

89c51 digital clock – Functions used in code

int scan_key();       Used to set time initially at the beginning when power is supplied.
int scan_key1();     Used to set time if 1 is pressed.
The difference between the above two functions is one is used to set time initially when you power on the hardware. The second one is used to set time when clock is operational. For example clock is running and you want to set time again so pressing ‘1‘ on keypad will lead you into scan_key1() function and you can set time according to your desire.

void display();        Used to check increments in seconds, hours and minutes and display time.
void start();            Used to check increments in seconds , hours and minutes and display time.

void tochar(unsigned int value);  Used to display time by converting integer in character.
To display a numeric character on 16×2 lcd we have to convert it in character form. The above function is used to achieve this task.

void onemintdelay();                    Used to start the internal timer till one second.
One minute delay is generated with the above function. For knowing how to generate one second delay with 89c51 microcontroller? You have to take the tutorial mentioned above.
8051 microcontroller digital clock time setting

8051 microcontroller digital clock time setting

digital clock 8051 microcontroller minutes settings

digital clock 8051 microcontroller minutes settings

8051 digital clock – Working

When you are done with all the above circuit building and code compilation. Then burn the code in your 8051 microcontroller with a good burner and now its time to test the code. At the start of the circuit triggering/powering you will see a message “SET 1 CLOCK” displayed on the first line of the 16×2 lcd and on second line you will see time in hours, minutes and seconds. Hour increments after every 60 minutes, minute is incremented after 60 seconds. When hour, minute and seconds reaches 12, 60, 60 they are again initialized with 0 for next reading. 

Note: You can also set the time at any instance just press 1 and you can see settings , set the time, and your clock starts running from updated time.
​
Important note:  The seconds starts from 3 and goes to 60. This is not an error in coding simply just because after each second i have to check some readings like hour minutes etc in which three seconds are required from each minute.  Time displayed on the 16×2 lcd is perfect their is no error in it.

Download the project files, code(C++,Hex) compiled in keil Uvision 4 compiler. Just download the hex Code in your microcontroller. MaKe the circuit and enjoy your digital clock. And one thing more don’t forget to write comments about the post and project below. Project video is also given below.
Watch the Project video here

Digital-Clock with 8051(89c51,89c52) Microcontroller


Filed Under: 8051 Microcontroller, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • mosfet driver problem in regeneration mode
  • What is the purpose of this relay?
  • Industrial Relay Board Design for Motorcycle Use
  • ADEM III ECM — No CAN Signal & Power Supply Issue
  • Snooping Around is All

RSS Electro-Tech-Online.com Discussions

  • Pic18f25q10 osccon1 settings swordfish basic
  • Sump pit water alarm - Kicad 9
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe