How to interface LEDs with 8051 Microcontroller

CIRCUIT DIAGRAM
Graphic1

DESCRIPTION

This post is related to basic operation of 8051 microcontroller with LEDs. LEDs are connected with P2 port & 6 switches are connected with P1 port of 8051. By pressing different switches, LEDs will glow in different manners. This post may be very helpful for 8051 microcontroller beginners.

CODE

#include < reg51.h >

sbit switch1=P1^0;
sbit switch2=P1^1;
sbit switch3=P1^2;
sbit switch4=P1^3;
sbit switch5=P1^4;
sbit switch6=P1^5;

int i,j,l;
int n=7;

void delay(int k) //This function produces a delay in msec.
{
for(i=0;i=0;l–)
{
P2=arr[l];
delay(50);
}
}

if(switch3==0)
{
P2=0x7E;
delay(50);
P2=0xBD;
delay(50);
P2=0xDB;
delay(50);
P2=0xE7;
delay(50);
}

if(switch4==0)
{
P2=0xE7;
delay(50);
P2=0xDB;
delay(50);
P2=0xBD;
delay(50);
P2=0x7E;
delay(50);
}

if(switch5==0)
{
P2=0xAA;
delay(50);
P2=0x55;
delay(50);
}

if(switch6==0)
{
P2=0x00;
delay(50);
P2=0xFF;
delay(50);
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s