i think the program should be some thing like this....
#include<stdio.h>
#include<reg51.h>
void delay(int);
sbit inp_pin=P1^0;
void main()
{
P0=P1=P2=P3=0x00;
for(;
{
if(inp_pin==0)
{
P2=0x01; // assuming that u have connected the LED to pin no.21 of 8051;
delay(500);
}
if(inp_pin==1)
{
P2=0x00;
delay(500);
}
}
}