#include "msp430g2553.h"
void Timer0A3PWM()
{
/******************************************************************
* 定时器Timer0_A的比较输出引脚即可做PWM输出的引脚为:
* out0(比较值为CCR0)P1.1,P1.5
* out1(比较值为CCR1)P1.2,P1.6
* ****************************************************************/
P1DIR |=BIT1 + BIT2 ;
P1SEL |=BIT1 + BIT2 ;
TACTL |= TASSEL_2 + MC_1 + TACLR; //时钟源:SMCLK;增计数模式
CCTL0 |= CCIE + OUTMOD_4;
CCTL1 |= CCIE + OUTMOD_7;
CCR0 =65535;
CCR1 = 2457;
}
#pragma vector = TIMER0_A1_VECTOR//因为CCTL0 |= CCIE + OUTMOD_4;
//CCTL1 |= CCIE + OUTMOD_7;所以为CCR1,
//而不是CCR0
__interrupt void TA0_ISR(void)
{
;
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
Timer0A3PWM();
_EINT();
while(1);
}
#include "msp430g2553.h"
void Timer1A3PWM()
{
/******************************************************************
* 定时器Timer1_A的比较输出引脚即可做PWM输出的引脚为:
* out0(比较值为CCR0)P2.0,P2.3
* out1(比较值为CCR1)P2.1,P2.2
* out2(比较值为CCR2)P2.4,P2.5
* ****************************************************************/
P2DIR |=0x3f;
P2SEL |=0x3f;
TA1CTL |= TASSEL_1 + MC_1 + TAIE + TACLR; //时钟源:ACLK;增计数模式
TA1CCTL0 |= CCIE + OUTMOD_4;
TA1CCTL1 |= CCIE + OUTMOD_7;
TA1CCTL2 |= CCIE + OUTMOD_7;
TA1CCR0 =3276;// 65534;
TA1CCR1 = 2457;
TA1CCR2 = 819;
}
#pragma vector = TIMER1_A1_VECTOR//因为TA1CCTL0 |= CCIE + OUTMOD_4;
//TA1CCTL1 |= CCIE + OUTMOD_7;
//TA1CCTL2 |= CCIE + OUTMOD_7;
//所以为CCR1,
//而不是CCR0,即为A1不是A0
__interrupt void TA1_ISR(void)
{
;
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
Timer1A3PWM();
_EINT();
while(1);
} |