include "msp430g2553.h"
const unsigned int spwm[] = {
250, 327, 396, 452, 487, 499, 487, 452, 396, 327,
250, 172, 103, 47, 12, 3, 12, 47, 103, 172,
};
unsigned int n=0;
void TimerA_PWM()//产生PWM波
{
P1DIR |= BIT2;
P1SEL |= BIT2; // p1.2
TACCR0 =500; // Init TACCR0 w/ sample prd=CCR0+1
TACCTL1=OUTMOD_7;
TACCR1= spwm[n]; // set/reset模式
//TACCTL2=OUTMOD_7;只有置位
TACCTL0 = CCIE;
TACTL = TACLR + MC_1 + TASSEL_1 +ID_0; // clear TAR, up mode*/
}
void main()
{
TimerA_PWM();
_EINT();
//_BIS_SR(LPM0_bits + GIE);
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TimerA(void)
{
TACCR1 = spwm[n++];
if(n==20)
n=0;
}