Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Generating one second delay using internal timers of 8051(89c51,89c52) Microcontroller

By EG Projects April 20, 2019

In this tutorial i am going to teach you about how to generate one second delay using internal timer registers of 8051(89c51,89c52) series microcontrollers.  Normally we use for-loops to generate delay. The delay generated by running loops is arbitrary. No fixed time delay is generated by loops. Loops are only suitable if you want an arbitrary delay in your program and not a proper fixed time delay. In order to generate proper delays you have to use the internal timers of 8051(89c51,89c52) microcontroller. 8051 series microcontrollers have two build in timers(Timer-0 & Timer-1). Each Timer is 16-bit wide. You can use them for generating delays, as counters and to generate baud rate for UART(Universal Asynchronous Receiver Transmitter) of microcontroller. In order to become familiarize with the internal register’s dedicated for  timers and their functioning I recommend you to please first take a tutorial on

  • How to use internal timers of 8051 micrococntroller?

1 second delay with 8051 microcontroller – Diy project

I am going to blink an led after every 1 second using 89c51 microcontroller. 1 second delay is accurately generated by using the internal timers of 8051 micrococntroller. Below is a the code for blinking an LED(light emitting diode) after each second using 8051 microcontroller. Port-1 Pin#0 is declared as output and our led is connected to this pin. Code is very simple(If you are already familiar with the syntax of C-language used for 8051 series microcontrollers programming).

8051 microcontroller one second delay -Project code

First in code i included the header file <reg51.h>. reg51.h is the header file necessary to be included in every project which is using keil(software) for writing and compiling code. Then the statement sbit led=P1^0 is assigning Port-1 bit#0 a variable led. 

Coming to main function. Statement P1=0x00 is initializing Port-1 as Output. Then led=1 is making our led to glow. delay() function is something that is the topic of this tutorial.  led=0 is switching off our led after 1 second. This means led will glow for 1 second and then turn off for 1 second. Whole of this part is placed in while(1) loop making the Statements to execute for ever.
  
The main thing in the code is delay() function & how is it working? To understand it you should know about the internal timer registers and i hope you take the tutorial mentioned above. You can calculate the values for TH and TL registers by using the formula given in the tutorial. Also you will be able to know about the TMOD(Timer Mode) register bits. If you don’t go through the lesson then hurry up and take it

  • How to use internal timers of 8051 microcontroller for generating fixed delays.

Now if you took the tutorial you are thinking what’s going on in delay() function. Actually i calculated the delay values for 2 ms and loaded the calculated values for TH and TL registers in them. 

One Second Delay generating with Internal Timer Registers of 8051(89c51,89c52)

One Second Delay generating with Internal Timer Registers of 8051(89c51,89c52)

Now if i run 2 ms delay for 500 times it will generate 1-Second Delay. The same thing is written in delay function. While loop is running for 500 times and generates 1 second delay. This 1 second delay can further be used to generate 1 minute delay.

Circuit diagram of the project is given below.

8051 microcontroller one second delay blink led

8051 microcontroller one second delay blink led

Project Circuit Diagram

Project Circuit Diagram

In the while loop its not necessary to always initialize the TMOD, TH and TL registers. You can initialize these registers once in the main code and in the while loop you can only run and stop the timer using TR0 and TF0 interrupt flags. Again and again initialing the TMOD, TH and TL registers in while loop will increase the delay time by the factor of initialing the registers 500 times in each second. 
​ 
I further generated one minute delay on the same principle listed above. You can also check out the project below. Source code of the project is also open source.

1 minute delay with timers of 8051 microcontroller

Download the Project Files & code(C, Hex) compiled in keil u Vision-4 and if have any questions regarding Post or Code. Write your Queries Below
Generating Fixed Delay Using Internal Timers of 89c51


Filed Under: 8051 Microcontroller, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

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



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

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.

  • Industrial Network Market Analysis and Introduction to Common Bus Protocols
  • Op-Amp oscillating
  • rechargeable battery and simple alkaline battery in one single product
  • Phase shift full bridge with extra added dead time?
  • Looking for FEMM expert. Need help to assess my model.

RSS Electro-Tech-Online.com Discussions

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque
  • Anyone In The US Ordered From AliExpress Recently?
  • Calculation of A Class amplifier
  • strange laptop problem
  • restarting this Christmas project

Featured Tutorials

Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
    Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
    Practical application of hardware filters with real-life examples
  • A filter design example
    A filter design example
  • Types of filter responses
    Types of filter responses
  • What are the two types of hardware filters?
    What are the two types of hardware filters?
  • What are hardware filters and their types?
    What are hardware filters and their types?
More Tutorials >

Recent Articles

  • Stackpole introduces compact jumpers for high-current circuit routing
  • Ironwood Electronics launches near-device-footprint SMT elastomer socket for BGA264
  • Amphenol RF releases P67 FAKRA plugs for 6 GHz RF transmission
  • Microchip releases platform to deliver real-time specifications for AI assistants
  • GigaDevices introduces 32-bit MCUs with integrated DSP and FPU support

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • 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
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
  • Guest Post Guidelines
  • Advertise
  • Subscribe