代码只能完成一部分我想调节的是频率出来的却是调节占空比
```c
#include <msp430x14x.h>
#define uchar unsigned char
#define uint unsigned int
#define keyin (P1IN & 0x0f)
uchar T[]={10,20,40,100,150,200}; //高电平持续
void delay(void)
{
uint tmp;
for(tmp = 12000;tmp > 0;tmp--);
}
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;
TACTL=TASSEL_1+TACLR;
uchar temp,keyval= 0;
char i =0;
CCR0=200;//PWM周期
CCTL1=OUTMOD_7;
CCR1=100;
CCTL2=OUTMOD_7;
CCR2=100;
P2DIR |= 0x08; // P2.3 输出
P2SEL |= 0x08; // P2.3 TA1
P2DIR |= 0x10; // P2.4 输出
P2SEL |= 0x10; // P2.4 TA2
P2DIR |= 0x24;
P2OUT &= (~BIT5) +(~BIT2); //P2.2与P2.5点亮
TACTL|=MC_1;//增计数模式
while(1)
{
if(keyin != 0x0f) //如果有键被按下
{
delay(); //延时消抖
if(keyin != 0x0f) //再次检测按键状态
{
temp=keyin;
while(keyin != 0x0f); //等待按键被放开
switch(temp) //转换键值
{
case 0x0e:
keyval = 1;break;
case 0x0d:
keyval = 2;break;
default:
keyval = 0;break;
}
if(keyval==1) //按键加
{
P2DIR |= 0x80;
P2OUT^=BIT7; //按键指示
i++;
if(i>5)
i=0;
}
if(keyval==2) //按键减
{
if(i==0)
i=5;
else
i--;
P2DIR |= 0x80;
P2OUT^=BIT7; //按键指示
}
}
CCR1 = T[i]; //占空比: T[i] / 200
CCR2 = T[i]; //占空比: T[i] / 200
}
}
}