Code #include "MSP430G2553.h" void led_init(); void timer0_init(); void main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //--Configure clock----- BCSCTL1=CALBC1_1MHZ; DCOCTL=CALDCO_1MHZ; //--LED initialization---- led_init(); //--Timer0 initialization---- timer0_init(); //---Open interrupt------ _EINT(); //Open interrupt LPM3; } /* * Timer 0 interrupt function*/ #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer0_A0(void) //TACCR0 interrupt { P1OUT^=(1<<6); //LED inversion } #pragma vector=TIMER0_A1_VECTOR __interrupt void Timer0_A1(void) //TACCR1 interrupt, TACCR2 interrupt and TA0 overflow interrupt share an interrupt vector{ switch(TAIV) { case 2: //TACCR1 interrupt P1OUT^=(1<<6); //LED inversion break; case 4: //TACCR2 interrupt P1OUT^=(1<<6); //LED inversion break; case 10: //TAIFG overflow interrupt P1OUT^=(1<<6); //LED inversion break; default: break; } } // LED initialization void led_init() { P1DIR|=(1<<6); } // Timer initialization void timer0_init() { /* *Set the clock of TIMER_A *TASSEL_0: TACLK, use external pin signal as input *TASSEL_1: ACLK, auxiliary clock *TASSEL_2: SMCLK, subsystem main clock *TASSEL_3: INCLK, external input clock */ TACTL |= TASSEL_1; /* *Clock source frequency division*ID_0: No frequency division*ID_1: 2 frequency division*ID_2: 4 frequency division*ID_3: 8 frequency division*/ TACTL |= ID_0; /* *Mode selection*MC_0: Stop mode, used for timer pause*MC_1: Up counting mode, counter counts to CCR0, then clears the counter*MC_2: Continuous counting mode, counter counts up to 0XFFFF(65535), then clears the counter*MC_3: Up-down counting mode, counts up to CCR0, then counts down to 0 */ TACTL |= MC_1; //Up counting mode//----Counter clear----- TACTL |= TACLR; //----Set the value of TACCRx----- //TACCR0=32768-1; //The clock is 32.768K, so the value is set to 32678-1 TACCR0=30000; TACCR1=10000; //TACCR1 and TACCR2 must be less than TACCR0, otherwise no interrupt will be generated TACCR2=20000; //----Interrupt enable---- TACCTL0 |= CCIE; //TACCR0 interrupt TACCTL1 |= CCIE; //TACCR1 interrupt TACCTL2 |= CCIE; //TACCR2 interrupt TACTL |= TAIE; //TA0 overflow interrupt} Note: It should be noted that the values of CCR1 and CCR2 should be less than CCR0 in the up-counting mode, otherwise CCR1 and CCR2 will not generate interrupts. And after each interruption of CCR1 and CCR2, they must be reassigned to ensure that the interrupt interval time of CCR1 and CCR2 remains unchanged. Similar statements are as follows: CCR1 += 100; if ( CCR1 >= 32768 ) CCR1 -= 32768;