In this guide, we will demonstrate how to interface LED (Light Emitting Diode) with 8051 microcontroller. LED consists of two terminals: cathode and anode. Cathode is connected to the negative terminals of the battery and anode is connected to the positive terminal of the battery. It is one of the most widely used output device in any circuit.
The goal is to create a circuit to interface LED with 8051, & continuously turn it On and Off with a delay.
P89V51RD2
Breadboard
LED
Resistor (220-330 ohms)
Jumper wires
Circuit Diagram
Code
Copy and paste the following code into main.c or download it from here:
#include <reg51.h>
void delay(void);
sbit led = P0^0; //setting the bit P0^0 to led
void main()
{
while(1) //infinite loop
{
led = 0; //led off
delay();
led = 1; //led on
delay();
}
}
void delay() //delay function
{
int i,j;
for(i=0;i<500;i++)
{
for(j=0;j<1000;j++)
{
}
}
}
Led will turn on and off for a certain period of time in an infinite loop until you stop the program.In this tutorial you have successfully learned how to interface an LED with a P89V51RD2. You have wired the components, written the C code, and gained the ability to turn on and off the LED for the certain amount of period.
In this tutorial you have successfully learned how to interface an LED with a P89V51RD2. You have wired the components, written the C code, and gained the ability to turn on and off the LED for the certain amount of period.