新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用定時(shí)器加中斷實(shí)現(xiàn)間隔1S的流水燈C程序

用定時(shí)器加中斷實(shí)現(xiàn)間隔1S的流水燈C程序

作者: 時(shí)間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
#include

#include
#define uchar unsigned char
#define uint unsigned int
uchar aa,count,flag;
void main() //主函數(shù)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
aa=0xfe; //賦初值11111110
while(1) //大循環(huán)
{
P1=aa;
if(flag==1) //延時(shí)500毫秒
{
aa=_crol_(aa,1);//將aa循環(huán)左移1位后再賦給aa
flag=0;
}
}
}

本文引用地址:http://2s4d.com/article/201611/316138.htm

void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
flag=1;
}
}



關(guān)鍵詞: 定時(shí)器中斷流水

評論


技術(shù)專區(qū)

關(guān)閉