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.
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.
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
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
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.
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.
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
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.