專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

51片內(nèi)定時(shí)器的應(yīng)用

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2010年03月27日   【字體:

/***********************************
利用定時(shí)/計(jì)數(shù)器T1產(chǎn)生定時(shí)時(shí)鐘,由P1口
控制8個(gè)發(fā)光二極管,使8個(gè)指示燈依次一個(gè)
一個(gè)閃動(dòng),閃動(dòng)頻率為10次/秒(8個(gè)燈依次
亮一遍為一個(gè)周期),循環(huán).
晶振:12MHz
stone
       2009 04 10
**********************************/

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define led P0
uint temp,t=0;
void main()
{
EA=1;
ET1=1;
TMOD=0x10;
TH1=-50000/256;
TL1=-50000/256;
TR1=1;

temp=0xfe;
while(1)
{
  if(t%2==0)
  {
   led=temp;
   if(t==20)
   {
    t=0;
    temp=_crol_(temp,1);
   }
  }
  if(t%2==1)
  {
   led=0xff;
  }
}
}

void time() interrupt 3
{
TH1=-50000/256;
TL1=-50000/256;
t++;
}
 

關(guān)閉窗口

相關(guān)文章