高级流水灯(按键检测+中断定时)

这篇博客介绍了一个高级的流水灯程序,通过按键检测和中断定时来控制4个LED灯的状态。当按下键1,下一个LED亮起,当前LED熄灭;按下键2,功能与键1相反;按下键3,4个LED呈现流水效果,再次按下则全部熄灭。程序中使用了中断定时器T0,并实现了按键延迟检测避免抖动。
摘要由CSDN通过智能技术生成
//******************************
//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:
		
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值