void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x0C; // P1.2 and P1.3 output
P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 options
Init_TIMER_B();
TACTL = TASSEL_2 + TACLR; // SMCLK, up mode
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7 ; // CCR1 reset/set
CCTL2 = OUTMOD_7 ; //CCR2 reset/set
if(v==5)
{
CCR1 = 128; // CCR1 PWM duty cycle
CCR2 = 384; // CCR2 PWM duty cycle
}
else if (v==12)
{
CCR1 = 384; // CCR1 PWM duty cycle
CCR2 = 128; // CCR2 PWM duty cycle
}
else
{
CCR1 = 128; // CCR1 PWM duty cycle
CCR2 = 384; // CCR2 PWM duty cycle
}
TACTL |= MC_1; // Start Timer_A in up mode
TBCTL |= MC_1; // Start Timer_B in up mode
_EINT(); //开全局中断
_BIS_SR(LPM0_bits); // Enter LPM0
}
void Init_TIMER_B()
{
TBCTL |= TBSSEL0 +TBCLR; //ACLK
TBCCTL0 = CCIE;
TBCCR0 =32768; //定时1s
} |