//******************************
//time:2014/3/5
//user:jeslie
//use:if you tap key1,the next led_light will be on,and the current one will go out.
// if you tap key2,the function is opposite to the key1.
// if you tap key3,the 4led_light will be a water_light,tap it again,all of the 4 led will go out.
//******************************
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
sbit led2=P1^1;
sbit led3=P1^2;
sbit led4=P1^3;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
uchar num=1,numt=0;
void init()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
switch(num)
{
case 1:
led1=1;led2=0;led3=0;led4=0;break;
case 2:
led1=0;led2=1;led3=0;led4=0;break;
case 3:
led1=0;led2=0;led3=1;led4=0;break;
case 4:
led1=0;led2=0;led3=0;led4=1;break;
}
}
void k
高级流水灯(按键检测+中断定时)
最新推荐文章于 2024-04-07 22:03:39 发布