#include<msp430g2553.h>
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
char sintable[10]={100,78,70,78,100,
126,148,156,148,126};
char y=0;
unsigned int i;
char flag=0;
void main()
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1=CALBC1_16MHZ;
DCOCTL=CALDCO_16MHZ;
P1IE|=BIT4; //P1.4触发
P1IES&=~0x10; //上升沿触发
P1IFG&=~0x10;
P1DIR=0x04; // P1.2输出
P1SEL=0x04;
P1OUT=0; //先输出低
//ta1 congigure
//ta0configure
TACTL=TASSEL1+TACLR;
CCR0=157;
CCR1=sintable[y];
CCTL1=OUTMOD_3; //CCTL1|=CCIE;
CCTL0=CCIE;
TACTL|=MC_1;
_EINT();
while(1)
{
if(flag==1)
{
flag=0;
TACTL|=MC_1;
}
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A1(void)
{
y=y+1;
if(y<10)
{
CCR1=sintable[y];
}
else
{
y=0;
CCR1=sintable[y];
}
}
#pragma vector=PORT1_VECTOR
__interrupt void PORT1(void)
{
y=3;
//for(i=100;i>0;i--);
CCR1=sintable[y];
P1IFG&=~0x10;
}
引用: 原理 发表于 2012-8-1 16:14
非常有用!谢谢!
但是现在我遇到了一个问题。定时器时钟选SMCLK频率为16MHZ,生成SPWM的频率为20KHZ,正 ...
引用: Domen 发表于 2012-7-17 09:15
这是方波呀……