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

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 Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

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

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

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