新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機(jī)中定時器的小程序

51單片機(jī)中定時器的小程序

作者: 時間:2013-03-04 來源:網(wǎng)絡(luò) 收藏

今天我開始了對51中的進(jìn)行了學(xué)習(xí),并寫了一個小程序。

#i nclude

sbit P0_1=P0^1; //定義位變量

/*********************************************************

*

* 16個循環(huán)為1秒

*

**********************************************************/

void Delay(count)

{

int i;

while(--count != 0)

{

for(i = 0; i 125; i++); // ";" 表示空語句,CPU空轉(zhuǎn)。

} // i 從0加到125,在12M晶體下CPU大概耗時1毫秒

}

/*********************************************************

中斷子程序

************************************************************/

void time0_server_(void) interrupt 2

{static time0_server_count;

time0_server_count++;

if(time0_server_count==16)

{P0_1=~P0_1;

time0_server_count=0;

}

TF0=0;

Delay(20);

}

main()

{ TH0=0x0B;

TL0=0xDC;

P0_1=0;

EA=1;

ET0=1;

TR0=1;

while(1);

}

該程序主要是用來了解的運(yùn)行規(guī)律,并對他進(jìn)行必要的應(yīng)用。

通過對其進(jìn)行實驗,我大致的對其有了一些了解,其主要用途有定時,記數(shù),中斷。等等。



評論


相關(guān)推薦

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

關(guān)閉