Fazendo padrão piscante de leds com microcontrolador 8051

Making blinking pattern of LEDs with 8051 microcontroller

LEDs blinking/blinking or making a special pattern of LEDs blinking through the microcontroller is not a big task. It is necessary to know the programming syntax of the specific microcontroller through which the blinking LED pattern is required. Several microcontrollers are available on the market and each has its own programming IDE (integrated development environment). In this tutorial we will blink several LEDs with the 8051 microcontroller. The LEDs blink in a pattern. As you see the LED strip in stores that appears and disappears, it starts to flash on one side and goes to the other. We will try to do the same thing in this DIY 89c51 microcontroller tutorial. The IDE used to write and compile code for the 8051 microcontroller is Keil Uvision. Before starting, I assume you guys know about keil uvision ide for 8051 microcontroller and its code syntax etc.

Pattern of 8 flashing LEDs with 89c51 microcontroller

Pattern of 8 flashing LEDs with 89c51 microcontroller

Flashing LED pattern with 8051 microcontroller – Project circuit diagram

I'm using port 1 of the 8051 microcontroller to make a pattern of LEDs flashing from left to right, right to left, middle to both ends, ends to middle. I'm using 8 LEDs for my pattern. 89c51 port-1 is an 8-bit port. Therefore, port 1 of the 8051 microcontroller is fully occupied and busy making the LEDs blink.

Flashing LED pattern using 89c51 microcontroller

Flashing LED pattern using 89c51 microcontroller
The commands you see in the code are in hexadecimal format and represent 8-bit values ​​in binary format, such as 0x24 binary equivalent is 00100100 . This 8-bit value appears on port 1. Each port 1 pin represents one bit. So the above command makes pins 2 and 5 of port 1 high, the rest are at 0 low. Then the LEDs connected to pins 2 and 5 will be turned on and the rest will be turned off. Count variable is used to repeat each pattern twice and the entire code is placed in while(1) loop to blink the LEDs forever. Now make the circuit and write the code to your 8051 and see the output.

Flashing LEDs/Multiple LEDs with 8051 microcontroller – Project code

Coming to the code first, I included the reg51.h file in the project code. This library is required to be part of the project if you are using the keil uvision tool for programming 8051 microcontrollers. The library contains the configuration settings of the 89c51 microcontroller. After importing the header file, I defined the delay function which is used to generate some arbitrary delay. The delay will stop the main code from executing for some time whenever it is called. The two for loops in the delay function are actually producing delay. The first for loop will run for various times depending on the parameter passed to it and the second will run 5 times for each iteration of the first. We pass an integer value as a parameter to the function, usually the value is so large that it creates a perfect delay. You can also provide a delay using the microcontroller's internal timers.

Now coming to the main code of flashing LEDs with 89c51 microcontroller. In the main code all logic is executed in a while(1) loop. While(1) loop means the logic in it will run forever as long as power is supplied. An eight-bit command is written to port 1 of the 8051 microcontroller to turn the LED on or off. For example P1=0x01 is a hexadecimal command that turns on the LED connected to pin 0 of port 1 and all other LEDs will remain off. If we translate the above command into binary, the result will be 00000001. If we write this command on port 8051 1, the output on the LEDs will be

8051 microcontroller port 1 LEDs flash status

8051 microcontroller port 1 LEDs flash status

I created the LED blinking pattern by manipulating the commands. You can translate the commands in the same way as above and see what LED pattern it is generating.

I am displaying four patterns on LEDs.

  • The first pattern will flash the LEDs one by one. It starts on one side, reaches the other and then comes back.
  • In the second pattern, 8 LEDs are divided into two halves. Each half now contains four LEDs. The above logic, one by one, is then repeated on the individual halves at the same time.
  • The third pattern illuminates the LEDs starting in the middle.
  • The fourth pattern is the random blinking of the LED

The flashing pattern of each LED is placed in a while loop and repeats twice before moving on to the next pattern. You can check the pattern by translating the individual commands present in each pattern. The translation figure is given above.

More tutorials on interfacing LEDs with 8051 microcontroller (89c51,89c52). Each project is best suited for beginners who are just starting out with learning and programming the 89c51 microcontroller. Code statements and tutorial circuits are explained in depth. The projects are open source. You can modify them according to your desire.

How to blink an LED with an 89c51 microcontroller?

Button and LED with 8051 microcontroller.

Faded LEDs with 89c51 microcontroller

Download the blinking pattern of multiple LEDs with the 89c51 microcontroller code compiled in the keil uvision compiler and its hexadecimal file. If you feel any problem in the code, please leave a comment below. I will definitely solve your problem.
LED code flashing pattern

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.