Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • Engineering Deep Dives
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Making blinking pattern of leds with 8051 microcontroller

By EG Projects April 26, 2021

Blinking/flashing leds or making a special pattern of blinking leds through microcontroller is not a big task. One must know about the programming syntax of the particular microcontroller through which blinking led pattern is required. Numerous microcontrollers are available in market and each has its own programming ide(Integrated development environment). In this tutorial we are going to blink multiple leds with 8051 microcontroller. Leds blink in a pattern. Like you see led strip on stores which fades in and out, starts blink from one side and go to other. We will try to make the same stuff in this diy 89c51 microcontroller tutorial. The ide used to write and compile code for 8051 microcontroller is keil uvision. Before beginning any further i assume you people know about keil uvision ide for 8051 microcontroller and about its code syntax etc.

8 leds blinking pattern with 89c51 microcontroller

8 leds blinking pattern with 89c51 microcontroller

Blinking leds pattern with 8051 microcontroller – Project circuit diagram

I am using port 1 of 8051 microcontroller to make a pattern of leds blinking from left to right, right to left, mid to both ends, ends to mid. I am using 8 led’s for my pattern. 89c51 port-1 is an 8-bit port. Hence port 1 of 8051 microcontroller is fully occupied and is busy in making led’s blink.

Blinking leds pattern using 89c51 microcontroller

Blinking leds pattern using 89c51 microcontroller
The commands that you see in the code are in hexadecimal form and are representing 8-bit value in binary form, like 0x24 binary equivalent is 00100100. This 8-bit value is appearing on the port 1. Each pin of port-1 represent one bit. Thus the above command makes pin 2 and 5 of port 1 high, rest are at 0 low. Hence the leds connected to pin2 and 5 will switch on and rest will be switched off. Count variable is used to repeat each pattern two times and whole of the code is placed in while(1) loop to blink the leds for ever. Now make the circuit and burn the code in your 8051 and see the output.   

Leds flashing/Multiple Led’s with 8051 microcontroller – Project code

Coming to the code first i included the reg51.h file in project code. This library is necessary to be part of the project if you are using keil uvision tool for 8051 microcontroller programming. The library contains the 89c51 microcontroller configuration settings. After importing header file i defined the delay function it is used to generate some arbitrary delay. Delay will halt the execution of main code for some time when ever it is called. The two for loops in delay function are actually producing delay. First for loop will run for numbers of time depending on the parameter passed to it and the second one runs 5 times for each iteration of the first one. We pass an integer value as parameter to the function, usually the value is so big to make a perfect time delay. You can also provide a time delay by using the internal timers of the microcontroller.

Now coming to the main code of blinking leds with 89c51 microcontroller. In the main code all the logic runs in a while(1) loop. While(1) loop means that the logic in it will run for ever as long as the power is supplied. An eight bit command is written to 8051 microcontroller port-1 to switch led on or off. For example P1=0x01 is a hexadecimal command it switches on led connected to port-1 pin#0 and all the other leds will remain off. If we translate the above command in binary it comes out 00000001. If we write this command to 8051 port 1 the output at led’s will be  

8051 microcontroller port-1 leds blink status

8051 microcontroller port-1 leds blink status

I made the led’s blink pattern by manipulating the commands. You can translate the commands same like above and see what led pattern it is generating.

I am displaying four patterns on led’s.

  • First pattern will blink leds one by one. It starts form one side and reaches the other and then comes back.
  • In second pattern 8-leds are divided in to two half’s. Each half now contains four led’s. The above one by one logic is then repeated on the individual half’s at the same time.
  • Third pattern illuminates led’s starting from the middle.
  • Fourth pattern is random led’s blink  

Each led’s flashing pattern is placed in a while loop and it repeats two times before moving to the next pattern. You can verify the pattern by translating the individual commands present in each pattern. Translation figure is given above. 

More tutorials on interfacing led’s with 8051(89c51,89c52) microcontroller. Each project is best suited for newbies who are just getting started with 89c51 microcontroller learning and programming. Code statements and circuits of tutorials are deeply explained. Project are open source. One can modify them according to his/her desire.   

How to blink an led with 89c51 microcontroller?

Push button and led with 8051 microcontroller.

Fading led’s with 89c51 microcontroller

Download the multiple leds flashing pattern with 89c51 microcontroller code compiled in keil uvision compiler and its hex file. If you feel any problem in code then leave a comment below.I will definitely resolve your problem.
Leds code flashing pattern

You may also like:


  • What are different types of industrial robots?

  • What are LoRa gateways and what types are available?

  • How does LoRa modulation enable long-range communication?

  • What are the different types of EV charging connectors?

  • What types of motors are used in electric vehicles?

  • What is Wireless Electric Vehicle Charging System (WEVCS)?

Filed Under: 8051 Microcontroller, Electronic 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

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

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.

  • 230VAC Relay can safely withstand DC Voltage
  • min length
  • Please help me understand how to design a dual band antenna on hfss software
  • SMPS noise reduction
  • Hv rescue help

RSS Electro-Tech-Online.com Discussions

Featured Tutorials

Learn - AWS IoT Tutorials

  • Arduino compatible coding 03: Basics of Arduino sketches and Embedded C
    Arduino compatible coding 03: Basics of Arduino sketches and Embedded C
  • Arduino compatible coding 04: Interfacing and driving LED by digital output
    Arduino compatible coding 04: Interfacing and driving LED by digital output
  • Arduino compatible coding 05: Interfacing buttons for digital input
    Arduino compatible coding 05: Interfacing buttons for digital input
  • Arduino compatible coding 06: Analog output (PWM) on Arduino and LED fading
    Arduino compatible coding 06: Analog output (PWM) on Arduino and LED fading
  • Introduction to batteries and their types
    Introduction to batteries and their types
  • Controlling IoT Devices through Emails over IMAP Protocol – IOT Part 48
    Controlling IoT Devices through Emails over IMAP Protocol – IOT Part 48
More Tutorials >

Recent Articles

  • Acromag releases 6U VMEbus SBC
  • Bourns adds LTCC diplexer for GNSS front ends
  • Raltron expands SAW filters for GPS and Wi-Fi
  • TDK adds flat-wire chokes for EMI filtering
  • DigiKey and Arduino launch edge AI project challenge

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 © 2026 Arrowfly 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 Arrowfly
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
      • Engineering Deep Dives
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertise
  • Subscribe