我是第一次用MSP430,之前用别的单片机时都要用查询法或开中断服务来处理标志位IFG,为何在MSP430官网上下的例子中就见到有些没开中断的例子中就没有IFG的清0处理,难道不开相应模块的中断就不用去管相应的IFG?不做清0有没有什么影响?我现想用TIMERA在P1.2/TA1上做一路PWMA输出,在P4.1/TB1上做一路PWMB输出,用串口接收的指令来调整PWMA的周期,同样用用串口接收的指令来调整PWMB的周期和占空比,因为要对PWMB的脉冲个数做精确计数,所以要开PWMB的TIMERB的中断,而PWMA只需要有可改变周期的PWM波(用于控制电机转速)就行,所以TIMERA不需要开中断,就是不知道要不要在主程序中用查询法去做CCIFG 清0,为何官网上的PWM的例子不做清0处理,急盼高手指点,谢谢!
请看官网上的两个例子
定时器的例子一
//******************************************************************************
// MSP-FET430P140 Demo - Timer_A, Toggle P1.1/TA0, Up Mode, DCO SMCLK
//
// Description: Toggle P1.1 using hardware TA0 output. Timer_A is configured
// for up mode with CCR0 defining period, TA0 also output on P1.1. In this
// example, CCR0 is loaded with 500-1 and TA0 will toggle P1.1 at TACLK/500.
// Thus the output frequency on P1.1 will be the TACLK/1000. No CPU or
// software resources required.
// As coded with TACLK = SMCLK, P1.1 output frequency is ~800000/1000.
// SMCLK = MCLK = TACLK = default DCO ~800kHz
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.1/TA0|--> SMCLK/1000
//
// M. Buccini
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include <msp430x14x.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x02; // P1.1 output
P1SEL |= 0x02; // P1.1 option select
CCTL0 = OUTMOD_4; // CCR0 toggle mode
CCR0 = 500-1;
TACTL = TASSEL_2 + MC_1; // SMCLK, upmode
_BIS_SR(CPUOFF); // CPU off
}
输出PWM的例子二
//*******************************************************************************
// MSP-FET430P140 Demo - Timer_A, PWM TA1-2, Up Mode, DCO SMCLK
//
// Description: This program generates two PWM outputs on P1.2,3 using
// Timer_A configured for up mode. The value in CCR0, 512-1, defines the PWM
// period and the values in CCR1 and CCR2 the PWM duty cycles. Using ~800kHz
// SMCLK as TACLK, the timer period is ~640us with a 75% duty cycle on P1.2
// and 25% on P1.3.
// ACLK = n/a, SMCLK = MCLK = TACLK = default DCO ~800kHz.
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2/TA1|--> CCR1 - 75% PWM
// | P1.3/TA2|--> CCR2 - 25% PWM
//
// M. Buccini
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include <msp430x14x.h>
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 otions
CCR0 = 512-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 384; // CCR1 PWM duty cycle
CCTL2 = OUTMOD_7; // CCR2 reset/set
CCR2 = 128; // CCR2 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
_BIS_SR(LPM0_bits); // Enter LPM0
}