Interfacing the 8051 microcontroller with the LED 

8051 microcontroller

We are very familiar with Basic program code in the initial stage of any programming language to learn some basic things. Likewise to begin with the 8051 Microcontroller, the LED interface is an essential thing in microcontroller interface programming. Each microcontroller is different in its architecture, but the interface concept is nearly the same for all microcontrollers. This tutorial will give you the LED interface with the 8051.

Communication is a method that provides communication between a microcontroller and an interface device. An interface is either an input device, an output device, a storage device, or a processing device.

Input interface devices: push-button switch, keyboard, infrared sensor, temperature sensor, gas sensor, etc. These devices provide some information to the microcontroller, this is called input data.

Output interface devices: LED, LCD, Buzzer, Relay driver, DC Motor Driver, 7-Segment Display etc.

Storage interface devices: used to store/keep data, for example, SD card, EEPROM, DataFlash, Real Time Clock, etc.

MicroController interface model

LED interfaces with 8051

The interface consists of hardware (interface device) and software (the source code for communication, which is also called a driver). Simply put, to use the LED as an output device, the LED must be connected to the microcontroller port and the MC must be programmed on the inside to make the LED ON, OFF, blink or dim. This software is called as driver/firmware. The driver can be developed using any programming language like Assembly, C, etc.

8051 microcontroller

The 8051 microcontroller was invented in 1980 by Intel Corporation. It is based on Harvard architecture and this microcontroller was developed primarily for use in embedded systems. We have previously discussed the history and basics of the 8051 microcontroller. It is a 40-pin PDIP (Plastic Double Packet Included).

8051 has an on-chip oscillator, but requires an external clock to power it. A quartz crystal is connected between the XTAL pins on the MC. This crystal needs two capacitors of the same value (33pF) to generate a clock signal at the desired frequency. The features of the 8051 Microcontroller were explained in our previous article.

microcontroller crystal connectors



LED (Light Emitting Diode)

LED is a semiconductor device used in many electronic devices, mostly used for signal/power indication purposes. It is very cheap and easily available in a variety of shapes, colors and sizes. LED lights are also used in design message display boards, traffic control signal lights, etc.

It has positive and negative terminals as shown in the figure.

LED polarity

The only way to know the polarity is to either test it with a multimeter or by carefully monitoring the inside of the LED. The larger end inside the LED is -ve (cathode) and shorter is +ve (anode), this is how we detect LED polarity. Another way to find out the polarity is, to connect the leads, the length of the positive terminal is longer than the negative terminal.

LED interface up to 8051

There are two ways we can connect the LED to the 8051 microcontroller. But the connections and programming techniques will be different. This article provides information about the LED interface with the 8051 code blinking LED for the AT89C52 / AT89C51 microcontroller.

LED Facades for 8051 

Note carefully that the LED 2 interface is forward biased because the 5V input voltage is connected to the positive terminal of the LED, so here the microcontroller pin must be at the low level. And vice versa with interface connections 1.

A resistor is important in the LED interface to limit the flowing current and avoid damaging the LED and/or MCU.

The interface 1 LED will glow, only if the PIN value of the MC is high as the current flows towards ground.

Interface 2 LED's will glow, only if the PIN value of the MC is low as current flows towards the PIN due to its low potential.

The circuit diagram is shown below. The LED is connected to pin 0 of port 1.

Proteus simulation circuit

I will explain the program code in detail. Furthermore, please refer to this link "Inline C Programming Tutorials in Keil Language". An 11.0592MHz crystal connected to generate the clock. As we know that the 8051 Microcontroller executes instructions in 12 CPU cycles[1], hence this 11.0592MHz crystal makes this 8051 run at 0.92 MIPS (one million instructions per second).

In the code below, the LED is defined as pin 0 of port 1. In the main function, the LED switches after every half second. The 'delay' function executes empty statements every time when it is executed.

A value of 60000 (compiled using Keil micro-vision4) generates about 1 second (delay) time to execute an empty statement when using the 11.0592MHz crystal. This way the LED connected to pin P1.0 is set to blink using the code given below.

cipher

# Include <reg51.h>

LED sbit = P1^0; // pin0 from port 1 is named LED

// job declarations

cct_init void(void);

void delay(int a);

int main (void)

cct_init(),

while (1)

LED = 0;

delay (60000);

LED = 1;

delay (60000);

cct_init void (void)

P0 = 0x00;

P1 = 0x00;

P2 = 0x00;

P3 = 0x00;

void delay (int a)

you are me

for (i = 0; i <a; i++) // Execute the empty statement, i.e. delay time

This article provides information on how LEDs interact with the 8051. This is the basic interaction concept for 8051 microcontroller projects.

I hope by reading this article you got the basic knowledge about how the LED module interfaces with the 8051. If you have any queries regarding this article or about microcontroller projects, feel free to comment in the section below.