|
#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 ini_s(void)//buzhidao
{
WDTCTL=WDTPW+WDTHOLD; //STOPW DT
if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
//1Mhz ~1008000
BCSCTL1 = CALBC1_16MHZ; // Set range
DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation */
_NOP();
}
void main()
{
ini_s();
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;
}
|
|