|
求教 MSP430F149测频率,低频会溢出怎么办
[复制链接]
#include
#include "LCD1602.c"
#include "Config.h"
void cap_init()
{
P1SEL=0X04;
// TACCTL1=CM0+SCS+CAP+CCIE;
//TACTL|=TASSEL1+MC1;
TACTL |=TASSEL_2+ID_0+MC_2;//选择SMCLK为定时器时钟,不分频,连续计数方式。
TACCTL1 |=CM_1+CCIS_0+SCS+CAP+CCIE;//上升沿捕获,CCI2A做捕获输入,同步方式,捕获方式,允许捕获中断。
}
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
switch(TAIV)
{
case 2:flag=1;
case 4:break;
case 10:break;
}
}
void main(void)
{
uint temp=0;
WDT_Init();
Clock_Init();
Port_init();
delay_ms(100);
cap_init();
_EINT();
LCD_init();
LCD_clear();
LCD_write_str(0,0,"The frequency:");
while(1)
{
while(flag)
{
_DINT();
flag=0;
str[temp]=TACCR1;
temp++;
if(temp==2)
{
uchar lcdbuf[6];
unsigned long count;
count=str[1]-str[0];
count=8000000/count;
count=count+1;//修正频率
lcdbuf[0]=count/1000+0x30;
lcdbuf[1]=(count%1000)/100+0x30;
lcdbuf[2]=(count%100)/10+0x30;
lcdbuf[3]=count%10+0x30;
lcdbuf[4]='H';
lcdbuf[5]='Z';
LCD_write_str(10,1,lcdbuf);
}
}
_EINT();
}
}
只能测123Hz以上的频率,低于就会出现乱七八糟的,怎么办,,求助!!
|
|