include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL |= 0x06; // P1.1 - P1.2 option select,外围模块的功能
P1DIR |= 0xff; // P1.0 - P1.2 outputs
CCTL0 = OUTMOD_4 + CCIE; // CCR0 toggle, interrupt enabled
CCTL1 = OUTMOD_4 + CCIE; // CCR1 toggle, interrupt enabled
TACTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, Contmode, int enabled
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
CCR0 += 60000; // Add Offset to CCR0
P1OUT ^= BIT0;
}
// Timer_A2 Interrupt Vector (TA0IV) handler
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1(void)
{
switch( TA0IV )
{
case 2: CCR1 += 30000; // Add Offset to CCR1
P1OUT ^= BIT6;
break;
case 4: CCR2 += 60000; // Add Offset to CCR1
P1OUT ^= BIT4;
break;
特别注意定时器服务程序:#pragma vector=TIMER0_A0_VECTOR与普通的msp430程序书写不同
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>