單片機-一個簡單頻率測量
TH0 = TIME0_LOAD>>8;
本文引用地址:http://www.ex-cimer.com/article/201809/388457.htmTL0 = TIME0_LOAD 0x00FF;
if(freq.start)
{
freq.timer++;
}
else
{
freq.timer=0;
}
}
void exint0_init( )
{
IT0 =1; //下降沿產(chǎn)生中斷
EX0 =1; //使能外部中斷
EA =1; //使能全局中斷
}
void exint0( ) interrupt 0
{
if(freq.start)
{
freq.int_Count++; //開始統(tǒng)計下跳沿
}
else
{
freq.int_Count=0;
}
}
void main( )
{
Timer0_Init( );
exint0_init( );
freq.start=1;
while(1)
{
if(freq.timer>=3000)
{
freq.T=freq.timer/freq.int_Count;
freq.int_Count=0;
freq.timer=0;
display_freq( ); //顯示周期的值
}
}
}
以上是該項目部分代碼,主要可以看看定時器和外部中斷的使用方法。
評論