#include<reg52.h> 
#define uint unsigned int
#define uchar unsigned char
sbit key=P3^4;    //S2按键位定义
sbit relay=P0^6;   //继电器控制端口

void delay(uint ms)	   //延时函数
{	
	uchar i;					
	while(ms--)                             
	{
		for(i=0;i<120;i++);
	}
}

void main()    //主函数
{
	relay=0;  
	key=1;
	while (1)
	{
		if(!key)
		{
			delay(50);
			if(!key)
			{
				while(!key);
				relay=!relay;
			}
		} 
	}
}