This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

我是初学者,想做一个用pwm输出一个方波,然后去驱动喇叭唱歌,程序现在只写到这里,用示波器看波形发现不能按照设计的占空比变化,请问问题在哪。



#include <msp430x14x.h>
int SONGTABLE[ ]={1,10};

int count=0;
/***初始化时钟源****/
void Init_clk (void)
{ char i;
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM1+SELS;
do
{
IFG1&=~OFIFG;
for (i =0; i <100; i++)
_NOP();
}
while ((IFG1&OFIFG));
IFG1&=~OFIFG;
}
/****初始化定时器A,载波***/
void Init_TimerA (void)
{
P1DIR |= BIT2;
P1SEL |= BIT2;

TACCR0 =20;
TACCR1=10;
TACCTL0=CCIE;
TACCTL1 = OUTMOD_7;
TACTL =TASSEL1+ID0+MC0+TAIE+TACLR;

}
//初始化定时器B,调制波
void Init_TimerB (void)
{
TBCCR0=500;
TBCCR1=250;
TBCCTL0=CCIE;
TBCCTL1=OUTMOD_7;
TBCTL =TBSSEL1+ID0+MC0+TBIE+TBCLR;
}

/****主函数***/
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
Init_clk ();
Init_TimerA();
Init_TimerB();
_EINT();
while(1)
{
   if(count<2) 

      TACCR1=SONGTABLE[count];

     else count=0;

     }




}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B(void)
{
count++;
}