Skip to content

Interfacing LED with P89V51RD2

Introduction

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.

Problem Statement

The goal is to create a circuit to interface LED with 8051, & continuously turn it On and Off with a delay.

Requirements

  1. P89V51RD2
  2. Breadboard
  3. LED
  4. Resistor (220-330 ohms)
  5. Jumper wires

Circuit Diagram

Getting Started Image

Code

  • Copy and paste the following code into main.c or download it from here:
c

#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++)
    {
    }
  }
}

Output

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.

Conclusion

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.