#include "msp430g2553.h" #include "delay.h"
void sys_init(void) { DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; }
void io_init(void) { P1DIR = 0; P1DIR |= BIT4 + BIT6; P1SEL |= BIT1; } void cap_init(void) { TACTL |= TASSEL_2 + MC_2 + TACLR; //MCLK , CONTINUE , CLEAR TACCTL0 |= CM_1 + SCS + CAP + CCIE + CCIS_0; // rising edge , synchronous , capture , interupt enable }
void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; sys_init(); io_init(); cap_init(); __enable_interrupt(); while(1) { P1OUT ^= BIT6; delay_ms(30); } }
#pragma vector = TIMER0_A0_VECTOR __interrupt void capture(void) { P1OUT ^= BIT4; // 输出频率是捕获频率的一半 }
|