新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 用定时的方式控制流水灯亮灭

用定时的方式控制流水灯亮灭

作者: 时间:2016-11-11 来源:网络 收藏

#include
#include
#define uchar unsigned char
uchar num=0;
init();

本文引用地址:https://www.eepw.com.cn/article/201611/316929.htm

main() //用定时的方式控制流水灯亮灭
{

init();
while(1)
{

if(num==20) //每1s流水灯左移一次
{
P1=_crol_ (P1,1);
num=0;
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;


}


}

}

init()
{
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;//定时50ms
TR0=1;
P1=0xfe;

}

void timer0() interrupt 1
{
num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}



关键词: 定时流水灯亮

评论


技术专区

关闭