代码:
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= XTS; P3DIR |= 0x20; // P1.0 output
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 1000;
//TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
TACTL = TASSEL_1 + MC_1; __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMERA0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
P3OUT ^= 0x20; // Toggle P1.0
CCR0 += 1000; // Add Offset to CCR0
}
灰小子:
CCR0 += 1000; // Add Offset to CCR0
增加了周期的数值,宽度肯定会增加,直到CCR0数据溢出