#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit K8=P1^7;
sbit led=P0^0;
uchar a,n=0,b=0;
void delay(uchar a)
{
uint i;
while(a--){
for(i=0;i<123;i++);
}
}
void readkey() {
if(K8==0)
{
delay(200);
if(K8==0)//按键消抖//
{
n++;
b=n%3;
}
}
}
void main()
{
while(1){
switch(b){
case(0):led=1;readkey();break;//灯亮//
case(1):led=0;readkey();break;//灯灭//
case(2):led=~led;delay(250);readkey();break;//闪烁//
}
}
}
|