#include "msp430g2553.h"
unsigned int lastCCR0,lastCCR1;
unsigned int j;
unsigned int k;
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;//停止看门狗
P1DIR |= (BIT0 + BIT4 + BIT6);
P1DIR &= ~BIT2;
P1SEL |= (BIT4 + BIT2);//P1.4->SMCLK输出,P1.2->捕获输入
BCSCTL2 |= SELS;//SMCLK时钟源选择为LFXT1CLK(32768HZ)
TACTL = TASSEL_2 + MC_2 + TACLR + TAIE ;//定时器A时钟源为SMCLK,连续计数模式,定时器清零
CCTL0 = CM_3 + SCS + CCIS_0 + CAP + CCIE;//上升沿和下降沿都捕获,同步,捕获模式,捕获中断允许
CCTL1 = CM_1 + SCS + CCIS_0 + CAP + CCIE;//上升沿捕获,同步,捕获模式,捕获中断允许
j = 0;
k = 0;
lastCCR0 = 0;
lastCCR1 = 0;
_EINT();
while(1);
}
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TIMER_A1(void)
{
switch(TAIV)
{
case 2: P1OUT ^= BIT6;
j = CCR1 - lastCCR1;
lastCCR1 = CCR1;
break;
case 4: break;
case 10: P1OUT ^= BIT0;
break;
}
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMER_A0(void)
{
if(SCCI == 0)
{
k = CCR0 - lastCCR0;
lastCCR0 = CCR0;
}
}
麻烦帮忙看下,定时器溢出中断是可以的,但上升沿捕获发生时P1OUT ^= BIT6;并没有发生。 |