1. Arduino Program For Led
  2. 8051 Microcontroller Programs
  3. Program For Led Fan
This project/tutorial is about getting started with 8051 microcontrollers and keil ide. In this post i am going to explain a simple code on How to blink an Led using 8051(89c51,89c52) series microcontrollers. I am going to write code in c language. The tutorial is helpful for those that are going to practice 89c51 microcontroller programming in lab. I consider that you have previous academic knowledge of 8051(89c51,89c52) microcontrollers their ports, gpio pins, and registers etc. Let's begin and try to blink an led at random delay using 89c51 microcontroller and keil uvision ide.
You can program 8051 microcontrollers in assembly and c. I recommend to first know about the assembly instructions then move on to the c instructions. Assembly instructions gives in depth knowledge of each register and its individual bits functionality. While in c programming most of the configurations are hidden and they are cascaded with the code during compiling and linking process. However in c language we can use inline assembly code with c. This technique is utilized to properly configure and debug the code in case of unknown errors.
  1. Mar 30, 2018  Robotics and Microcontroller Class 01 How to make led blinking project using microcontroller bangla This is a step by step microcontroller bangla tutorial series. I will uploading a video everyday.
  2. Microcontroller - A Beginners Guide - Writing the First Program to Turn On an LED and Transferring the Program into the Microcontroller. And were also introduced to the programmer, the device that helps transfer the program into the microcontroller. In the next video and instruction, we will make the LED blink. We will investigate how to.
  • 89c51 or 89c52 microcontroller
  • One LED(Light Emitting Diode)
  • Crystal(11.0592 MHz)
  • Resistor 1k t0 4.7k ohm
  • Two 33-pf Capacitors
  • Power Supply
Embedded

In this tutorial we will blink LED using AVR Atmega32A Microcontroller. We will use simple delay function and play with LEDs to control. And also naming convention to instruct microcontroller to perform certain action by accessing those register through C Program. DDRx: Data Direction Register for Port x x- corresponds to port A, B, C or D. Program Explanation. Blinking Two LED’s Using ATmega328 – Download Program At the beginning of the program a pre-processor named “F_CPU” is defined.It is simply your way to tell some of the library code how many CPU cycles per second the processor is executing.

The circuit of the project is pretty straight forward. We are going to blink an led connected to pin#1 of 89c51 microcontroller. Pin#1 corresponds to microcontroller Port-1 pin#0. The pin is initialized as output pin in the code. External clock source ceramic crystal is connected to Pins 18 & 19 of 89c51 microcontroller. Crystal is connected to microcontroller in parallel to two 33-pf capacitors. 11.0592Mhz crystal is used in the project. Apply Vcc(+5v) to Pins 31 & 40 of 89c51. Ground pin#20. Now we are done all the necessary connections are made. Circuit Diagram of blinking led with 89c51 microcontroller is given at the right side.
Led polarity is anode facing the power supply and cathode is connected to port#1 pin#0.

Led is connected to port-1 pin#1. Led Anode is connected to an external +5v series with 510 ohm resistor. Resistor is used to limit the amount of current led is consuming. Led cathode is connected to 89c51 microcontroller pin directly. So when the microcontroller sources some voltage the led turns off and when it grounds the led turns on. Opposite polarity functionally by microcontroller pin.

Project Code

Download the project code from the links given at the bottom of the Post.

In the code above I first included the header file reg51.h. This header file is very important. When ever we are using 89c51 microcontroller in our project we have to include it. If we are using 89c52 than the file name changes to reg52.h. This library contains default function definitions and configuration for 8051 series microcontrollers.
Note: I am using keil software to write my code to blink an led. If you are using any other software to write code for 8051 microcontroller. Then first check which library that software made compulsory to be included for writing code of 8051 series microcontrollers. Keil made it compulsory to include the reg51.h header file in the codes that are written for 8051 series microcontrollers. Actually the compiler that is working with keil needs this header file to compile the code and generate Hex code for you.
Then the statement sbit Led=P1^0; is initializing port#1 pin#0. Now we can use Port-1 Pin#0 with the name of Led. Next delay(value) function here is actually generating some arbitrary delay for us. If Led switches on, we want it to remain in this state for some time so we give some delay before executing the off instruction. You can see the two for loops in the delay function. These two for loops are providing us random delay. The first loop runs number of times for the value which is given to it, and second loop runs 5 times for each iteration of the first loop. We usually pass some big number as parameter to the function and this huge number makes the for loop runs for some seconds to minutes depending on our given integer value. You can also use the internal timers of the 8051 for delays but since this tutorial is for the beginners so you should adopt the easy way.
In the main() function the instruction P1=0x00; is initializing our Port-1 as output. It is necessary to initialize each port as input our output before using it in the program. Since my Led is connected to Port-1 Pin#0 that's why I am initializing Port-1 as output.
0x00; is a hexadecimal command caring 8-bit instruction. If we translate it in binary it becomes P1=00000000. Since Port-1 of microcontroller consists of 8-Pins. This 8-bit instruction is written to each single pin of microcontroller. If 0 is written on Pin it initializes the pin as output. If 1 is written it initializes the pin as input. can easily be written to the microcontroller port and each bit represent a particular port pin of micro controller.
Initializing Port-1 of 8051(89c51,89c52) microcontroller.
While(1) Loop is continuously running the logic present in it. Led Blinking Logic is Present in While(1) Loop. The whole cycle is below.

Arduino Program For Led

  • First I made Led=1 which switches on my led.
  • Then Some Delay() Keeps Led in on state.
  • After Delay() I made Led=0 which switches off the led.
  • Then Some Delay() keeps led in switch off state.

8051 Microcontroller Programs

After the above cycle is completed while loop starts again and this makes the led to seem like blinking.

Program For Led Fan

Download the Project files, Code(Hex,C). Simulation is also present in the folder. Code is written using C language. Keil software is used to write and compile code. Simulation is made in Proteaus 8.0.