You are currently viewing How to Interface LEDs with 8051 Development Board

How to Interface LEDs with 8051 Development Board

Spread the love

The 8051 Development board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through serial port.

NXP’s 8051 (AT89V51RD2), 8051 Development Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of speed 8-bit Microcontrollers.

LED (Light Emitting Diodes)

Light Emitting Diodes (LED) is the most commonly used components, usually for displaying pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of user input such as a mouse click or keystroke.

Interfacing LED with 8051

Fig. 1 shows how to interface the LED to microcontroller. Anode is connected through a resistor to GND & the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is OFF & when the Port Pin is LOW the LED is turned ON.

interfacing LED to microcontroller
Fig. 1 Interfacing LED to Microcontroller


Interfacing LED with 8051

We now want to flash a LED in 8051 Development Board. It works by turning ON a LED & then turning it OFF & then looping back to START. Operating speed of microcontroller is very high so the flashing frequency will also be very fast to be detected by human eye.

The 8051 Development board has eight numbers of point LEDs,connected with I/O Port lines (P0.0 – P0.7) to make port pins high.

Pin Assignment with 8051

Pin Assignment with 8051

Circuit Diagram to Interface LED with 8051

Circuit diagram for Interface LED with 8051

Source Code

The program is very simple and straight forward, that uses a delay procedure loop based software delay. In C programs you cannot be sure of delay, because it depends on compiler how it optimizes the loops as soon as you make changes in the options the delay changes.

C Program to switch ON and OFF LED using 8051

#include 

#include 

#define LED P0

//define prot P0 for LED void delay(void);

//Delay function void led_left(void);

//LED_Left void led_right(void);

//LED_Right unsigned int j;

//----------------------------------

//LED LEFT FUNCTIONS

//----------------------------------

void led_left()

{

for (j=0x01; j<=0x80; j<<=1)

{

LED = j;

delay();

}

}

//----------------------------------

//LED RIGHT FUNCTIONS

//----------------------------------

void led_right()

{

for (j=0x40; j>=0x01; j>>=1)

{

LED = j;

delay();

}

}

//----------------------------------

//Delay Functions

//----------------------------------

void delay(void)

{

unsigned int i;

for (i=0;i<10000;i++);

}

//----------------------------------

//Main Program Starts

//----------------------------------

void main (void)

{

LED = 0x00;

//Initialize to 0x00 while (1)

//Loop forever { led_left();

//scroll left delay();

led_right();

//scroll right

}

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.