基于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
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』