include "msp430.h"
//功能:用TIMERA0 让P1.0口输出PWM 用TIMERB让LED闪烁
//问题:这两个定时器代码分开可以实现想要的功能 合并在一起使用LED闪烁功能无法实现
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // Set P1.0 to output direction
//定时器A部分
P1DIR |= BIT0+BIT2;
P1SEL |= BIT0+BIT2;
TA0CCR0 = 1000-1;
TA0CCTL1 = OUTMOD_7;
TA0CCR1 = 500;
TA0CTL = TASSEL_1 + MC_1 + TACLR;
//定时器B部分
TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = 50000;
TBCTL = TBSSEL_2 + MC_1 + TBCLR; // SMCLK, upmode, clear TBR
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
//进入低功耗模式0 使能全局中断
__no_operation(); // For debugger
}
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR (void)
{
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
|