//******************************
//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:
高级流水灯(按键检测+中断定时)
最新推荐文章于 2024-04-07 22:03:39 发布
这篇博客介绍了一个高级的流水灯程序,通过按键检测和中断定时来控制4个LED灯的状态。当按下键1,下一个LED亮起,当前LED熄灭;按下键2,功能与键1相反;按下键3,4个LED呈现流水效果,再次按下则全部熄灭。程序中使用了中断定时器T0,并实现了按键延迟检测避免抖动。
摘要由CSDN通过智能技术生成