單片機(jī)-一個(gè)簡(jiǎn)單頻率測(cè)量
TH0 = TIME0_LOAD>>8;
本文引用地址:http://m.butianyuan.cn/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)計(jì)下跳沿
}
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( ); //顯示周期的值
}
}
}
以上是該項(xiàng)目部分代碼,主要可以看看定時(shí)器和外部中斷的使用方法。
評(píng)論