#include "MSp430G2553.h" unsigned int start,end; unsigned char overflow;
void main( void ) { WDTCTL = WDTPW + WDTHOLD; P1DIR|=BIT0+BIT6;//P1.6LED, P1SEL|=BIT0+BIT2;//P1.0->ACLK输出,P1.2->捕获输入 P1OUT&=~BIT6;//关闭LED BCSCTL1 =DIVA_3;//ACLK8分频(vlo=12Khz) CCTL1=CM_1+SCS+CCIS_0+CAP+CCIE;//上升沿+同步+CCI0A(p1.2)+捕获功能+捕获中断 TACTL=TASSEL_2+MC_2+ID_3+TAIE+TACLR;//SCLK(DCO=1.1Mhz)8分频,连续计数模式 _BIS_SR(LPM0_bits+GIE); } #pragma vector=TIMER0_A1_VECTOR __interrupt void Timer_A (void) { switch(TAIV) { case 2: if(CCTL1&CM_1) { CCTL1=(CCTL1&(~CM_1))|CM_2; start=TAR; overflow=0; } if(CCTL1&CM_2)//else if与if区别要注意 { CCTL1=(CCTL1&(~CM_2))|CM_1; end=TAR; } P1OUT|=BIT6; break; case 10: overflow++; break; default: break; } }
|