msp430频率测试程序

基于msp430f5529用内部ADC12进行方波频率测试
main.c

include

include “LCD12864.H”

define key1 !(P3IN&BIT1)

int l = 0;
unsigned int zhq,check;
double hzddd,f;

int Cycle[2];
//unsigned char tab[]={ };
unsigned char tab[]={” “};
unsigned char pl[]={“pinlv: hz”};
int i;
unsigned int a[1000]={0};
int max,value;

int key();

void find(int *a, int l, int *max, int *value);
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; //选择P1.0为ACLK时钟输出
P1SEL |= BIT0;
P2DIR &= ~BIT0; //设置P2.0为捕获输入口
P2SEL |= BIT0;
P2DIR |= BIT2; //设置P2.2为SMCLK时钟输出
P2SEL |= BIT2;
TA1CTL = TASSEL_2 + MC_2 + TACLR;//TA1主计数器时钟

    //TA1CCR1=1024;

TA1CCTL1 = CM0 + SCS + CAP + CCIE;

__bis_SR_register(GIE);

while(1)
{
for(i=0;i<1000;i++)
{
if(Cycle[1] > Cycle[0])
{
zhq=Cycle[1] - Cycle[0];
}
else
{
zhq=Cycle[0] - Cycle[1];
}

 hzddd=1 / (double)zhq;
 if(hzddd<0)
     hzddd=-hzddd;
     f=(hzddd*1000000)*1.0525+0.6173;
     if((int)f>30)
     a[i]=(int)f;

    }



     find(a,50,&max,&value);


 tab[0]=((unsigned long)value/10000)+0x30;
 tab[1]=(((unsigned long)value%10000)/1000)+0x30;

 tab[2]=(((unsigned long)value%1000)/100)+0x30;
 tab[3]=(((unsigned long)value%100/10))+0x30;
 tab[4]=((unsigned long)value%10)+0x30;
 pl[6]=tab[0];
 pl[7]=tab[1];
 pl[8]=tab[2];
 pl[9]=tab[3];
 pl[10]=tab[4];
 IO_Init();
 LCD12864_Init();

        if (key())
  {
    while(key())
    {
 LCD12864_SetPos(0,0);
 LCD12864_DisplayString(pl,15);
 LCD12864_Delay(666);
    }}

}
}

pragma vector=TIMER1_A1_VECTOR

__interrupt void TIMER0_A1_ISR(void)
{
Cycle[l] = TA1CCR1;
l++;
if(l==2)
l=0;

TA1CCTL1 &= ~CCIFG;
 // LPM0_EXIT;

}

int key()
{
{
if(key1)
{
LCD12864_Delay(10);
if(key1)
{
return 1;
}
}
return 0;
}

}

void find(int *a, int l, int *max, int *value)
{
if(l == 1)
{
*max = 1;
*value = a[0];
return;
}
find(a,l-1, max, value);
if(a[l-1] == *value) *max++;
else
{
int i, cnt = 1;
for(i = 0;i

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值