
#include<reg51.h>
int DELAY;
void delay();
void main(void)
{
  	P1 = 0;		// Connected to LEDs
	P2 = 0xff;	// Input Control Port
	TCON = 0;	
	TMOD = 0x01;	// Timer 0 in 16-bit Mode. Not using Timer 1
	IE = 0x82;	// Enabling Timer 0 Interrupt only
	TH0 = 0x3c;	// Delay for a 50 milli Sec 
	TL0 = 0xaf;	
	TR0 = 1;	// Enable Timer 0 Interrupt
	while(1)
		delay();
}
void delay()
{
	int i;			// Wait for some time doing nothing.
	for(i=0;i<32700;i++);	// If I dont use this function, the
}				// program is hanging.
void T0_ISR (void) interrupt 1
{
	static int counter;
	static int val;

	if(counter == (255 - P2))	// Inverting P2 so that I
					// Ground only required pins.
	{
		if(val == 0)
		{
			P1 = 0xff;	// Switch on the LEDs
			val = 1;
		}
		else
		{
			P1 = 0;		// Switch off the LEDs
			val = 0;
		}
		counter = 0;
	}
	else
		counter++;
}

