C:\Users\ThinkPad\Desktop
#include "MSP430G2553.h"
#include "math.h"
#define uchar unsigned char
#define uint unsigned int
unsigned char i;
unsigned int j=1,n=0,flot=0;
unsigned int spwm[50]= {
40,120,200,279,357,434,508,581,652,719,
785,846,905,960,1011,1059,1101,1140,1174,
1205,1229,1249,1264,1274,1279,1279,1274,1264,
1249,1229,1205,1174,1140,1101,1059,1011,960,
905,846,785,719,652,581,508,434,357,279,
200,120,40
};
void ini_sys(void);//时钟初始化
void TimerA_lnit();//定时器初始化
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
ini_sys();//时钟初始化
TimerA_lnit();//定时器初始化
_EINT();
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
n++;
if(flot==1)
{
TACCR1=spwm[n];
TACCR2=0;
if(n==49)
{
n=0;
flot=0;
}
}
else
{
TACCR2=spwm[n];
TACCR1=0;
if(n==49)
{
n=0;
flot=1;
}
}
P1IFG=0;
}
void TimerA_lnit()
{
P1SEL|=BIT2+BIT6;
P1DIR|=BIT2+BIT6;
TACTL=TACLR+MC_1+TASSEL_2;
TACCR0=1600;
TACCR1=TACCR2=spwm[n];
TACCTL1=OUTMOD_6;
TACCTL2=OUTMOD_6;
TACCTL0|=CCIE;
}
void ini_sys(void)
{
BCSCTL2=SELM_1+DIVM_0;
BCSCTL1=CALBC1_8MHZ;
DCOCTL=CALDCO_8MHZ;
}
输出后第一个和最后一个波形发现了翻转现象,不知哪里出问题 |