msp430g2553 用捕获的方法测脉宽长度,但一直测的有问题,求救啊
程序如下:
#include "msp430g2553.h"
unsigned int start,end,overflow;
float num;
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
TA1CTL = TASSEL_1 + MC_2 + TAIE;
TA1CCTL2 = CM_1 + CCIS_1 + CAP + CCIE + SCS;
P2DIR |=BIT4;
P2DIR &=~BIT5;
P2SEL |=BIT5;
_EINT();
while(1);
}
#pragma vector = TIMER1_A1_VECTOR
__interrupt void Timer_A(void)
{
switch(TA1IV)
{
case 4:
if(TA1CCTL2&CM0)
{
start = TA1CCR2;
TA1CCTL2 = CM_2 + CCIS_1 + CAP + CCIE + SCS;
overflow = 0;
}
else if(TA1CCTL2&CM1)
{
end = TA1CCR2;
TA1CCTL2 = CM_1 + CCIS_1 + CAP + CCIE + SCS;
num = (end + overflow*65535 - start);
}
break;
case 10:
overflow++;
break;
default:break;
}
} |