|
代码如下 显示结果不对,而且数字会慢慢掉;
/*
* main.c
*/
#include "msp430x54x.h"
# include "info.h"
unsigned long int countnumber=0;
unsigned long int add=0;
uint capture_array[15]; //存放捕获时计数器的值
uint count1=0,buf;
float Freq=0.0;
uint buffer[15];
char data1[8];
void floatTochar(float datain,char dataout[],int Num);
void Bubble_Sort(int dat[],int Num);
int M_Filter(int dat[],int Num);
void main(void)
{
//UCS_XT1_DCO_DCO(8);
WDTCTL = WDTPW + WDTHOLD;
P1SEL|=BIT1; //使用P1.1,也就是子系统入口
TA0CCTL0 = CM_2 + CCIS_0 + SCS + CAP + CCIE; //OFFFF,计数来源是CCIS0,同步计数,捕获模式,中断允许
TA0CTL = TASSEL_2 + MC_2 + TACLR; //SM,递增模式,清零
Lcd_Init(); //液晶显示初始化
Lcd_Clear();
__bis_SR_register(GIE); //中断允许
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_ISR(void)
{
uint i;
capture_array[count1++] = TA0R; //存计数器的值到数组capture_array
if (count1 == 5)
{
count1 = 0;
for(i=0;i<4;i++)
{ if(capture_array[i+1]>capture_array[i])
{ add= (capture_array[i+1]-capture_array[i])+add;}
else { add= (capture_array[i+1]+(65535-capture_array[i]))+add;}
}
float k;
k=add/4.0;
Freq=1000000.0/k;
floatTochar(Freq,data1,1);
Lcd_Clear();
StrDisplay("P2.1:",0,0,0);
StrDisplay(data1,2,2,0);
_Nop();_Nop();
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|