不知道怎么插入代码,直接贴上来了~ 这是之前写的一个,两路PWM,一路5.6k,一路150k~ 你可以试试看~
#include <msp430g2553.h> void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL2 = SELM_0 + DIVM_0 + DIVS_1; //2
if (CALBC1_16MHZ != 0xFF) { DCOCTL = 0x00; BCSCTL1 = CALBC1_16MHZ; /* Set DCO to 16MHz */ DCOCTL = CALDCO_16MHZ; } BCSCTL1 |= XT2OFF + DIVA_0; BCSCTL3 = XT2S_0 + LFXT1S_2 + XCAP_1; P2SEL |= BIT0+BIT1; // P2.0 - P2.1 option select P2DIR |= BIT0+BIT1; // PP.0 - P2.1 outputs TA1CCTL0 = OUTMOD_4+ CCIE; // TA1CCR0 toggle, interrupt enabled TA1CCTL1 = OUTMOD_4+ CCIE; // TA1CCR1 toggle, interrupt enabled
TA1CTL = TASSEL_2 + MC_2; // SMCLK, Contmode, int enabled _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }
// Timer A0 interrupt service routine #pragma vector=TIMER1_A0_VECTOR __interrupt void Timer_A0 (void) { TA1CCR0 += 664; // Add Offset to CCR0 1.4k*4 }
// TimerA1 Interrupt Vector (TA1IV) handler #pragma vector=TIMER1_A1_VECTOR __interrupt void Timer_A1(void) { switch( TA1IV ) { case 2: TA1CCR1 += 27; // Add Offset to CCR1 150k break; } } |