——————————————-

8051 Program to “On” LED

——————————————-

#include<reg51.h>

sbit led=P3^0;

void main()

{

while(1)

{

led=1;

}

}

——————————————-

8051 Program to “On” and “Off” LED

——————————————-

#include<reg51.h>

sbit led=P2^0;

void delay()

{

unsigned int i , j;

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

{

for( j=0 ; j<100 ; j++ );

}

}

void main()

{

while(1)

{

led=1;

delay();

led=0;

delay();

}

}

——————————————————–

8051 Program to “On” and “Off” LED using switch

——————————————————–

#include<reg51.h>

#define PORT P2

sbit sw=P0^0;

void main()

{

while(1)

{

if(sw==0)

{

PORT=0xFF;

}

else

{

PORT=0x00;

}

}

}

——————————————————–

8051 Program for 7 Segment Display

——————————————————–

#include<reg51.h>

#define PORT2 P2

void main()

{

unsigned char value[10]={0x3f,0x06,0x5B,0x4F, 0x66,0x6d,0x7d,0x07,0x7f,0x67};

unsigned char x;

unsigned int i,j;

PORT2=0x00;

while(1)

{

for(x=0;x<10;x++)

{

PORT2=value[x];

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

{

for(j=0;j<1000;j++);

}

}

}

}