#define CM_0 (0*0x4000u) /* Capture mode: 0 - disabled */
#define CM_1 (1*0x4000u) /* Capture mode: 1 - pos. edge */
#define CM_2 (2*0x4000u) /* Capture mode: 1 - neg. edge */
#define CM_3 (3*0x4000u) /* Capture mode: 1 - both edges */
#define TBSSEL__ACLK TBSSEL_1
#define TASSEL__ACLK TASSEL_1
#define TASSEL__ACLK2 TASSEL_0
#include "msp430g2553.h"
int start,en;
long int sum;
int overflow=0;
void main( void )
{
int i;
WDTCTL = WDTPW + WDTHOLD;
//BCSCTL1 = CALBC1_16MHZ;
//DCOCTL = CALDCO_16MHZ;
TA0CCTL1 = CCIE + CM_1 + SCS + CAP;
TA0CTL = TASSEL__ACLK + MC_2 + TACLR + TAIE;
CCTL1 |= CM_1+SCS+CCIS_0+CAP+CCIE; //输入上升沿捕获,CCI0A为捕获信号源
P2DIR |=BIT4;
P1DIR &=~BIT2;
P1SEL |=BIT2;
_EINT();
while(1)
{
P2OUT |=BIT4;
i=200;
while(i--);
P2OUT &=~BIT4;
i=200;
while(i--);
}
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR(void)
{
switch(TA0IV) //TA中断向量查询
{
case 2: //是捕获中断 2为CCR1捕获中断向量值
if (TA0CCTL1 & CM0) //上升沿捕获
{
TA0CCTL1 &=~ CM_1;
TA0CCTL1 |= CM_2; //改为下降沿捕获
start = TA0R;
}
else if (TA0CCTL1 & CM1) //下降沿捕获
{
TA0CCTL1 &=~ CM_2;
TA0CCTL1 |= CM_1; //改为上升沿捕获
en = TA0R;
sum=overflow*65535+en-start;
}
TA0CTL = TASSEL__ACLK + MC_2 + TACLR + TAIE;
CCTL1 |= CM_1+SCS+CCIS_0+CAP+CCIE;
break;
case 10: //是溢出中断
overflow++; //溢出次数自加1
break;
default:
break;
}
}
程序如上,运行时无论如何也进不了那个下降沿的IF段。。。。求帮助 |