#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char counter;
sbit K1=P2^1;
sbit K2=P2^2;
sbit K3=P2^3;
sbit LED1=P0^2;
sbit LED2=P0^1;
sbit LED3=P0^3;
sbit RELAY=P0^4;
sbit RELAY1=P0^5;
/********延时********/
void DelayMS(uint ms)
{
uchar t;
while(ms--)
for(t=0;t<120;t++);
}
/********主程序********/
void main()
{
P0=0x100;
P2=0xff;
LED2=K2;
LED3=K3;
while(1)
{
if(K1==0)
{
while(K1==0);
counter++;
if(counter>=20)
RELAY=1;
LED1=~LED1;
if(counter>=10)
RELAY1=1;
DelayMS(10); //延时20MS
{
}
}
}
}
|