请问如何将以下的程序改为
在G2板上利用p1.6(PWM输出口)驱动LED来实现呼吸灯。呼吸灯就是亮度渐变的LED灯,普通LED可以用TA输出PWM来控制亮度,通过WDT定时中断来改变亮度,从而实现呼吸灯效果。
1、通过按键来控制呼吸灯的呼吸频率,即亮度渐变的快慢。
控制方式:按扩展板上KEY1键,呼吸加快一档,连续按2下,呼吸加快一档,连续按3下,呼吸又加快一档......;按KEY3键,呼吸减慢一档,连续按2下,呼吸减慢一档,连续按3下,呼吸又减慢一档......。
2、在液晶屏上显示呼吸灯呼吸频率的相关信息
#include<msp430g2553.h>
void BreathLED()
{
P1SEL =BIT6;
P1DIR = BIT6;
P1OUT=0;
TACTL = TASSEL_1 + MC_1 ;
TACCTL1 = OUTMOD_3 ;
TACCTL0 = CCIE;
CCR0 =12000;
CCR1 =327; //0% pwm
TACTL |=TACLR;
_EINT();
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL3 |= LFXT1S_2; // Set LFXT1为vol时钟即12kHZ
BreathLED();
LPM0;
return 0;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void CountTimes()
{
static int Times;
Times++;
switch(Times)
{
case 20:
CCR1=294;
break;
case 30:
CCR1=277;
break;
case 40:
CCR1=262; //20% PWM
break;
case 50:
CCR1=245; //20% PWM
break;
case 60:
CCR1=228; //40% PWM
break;
case 80:
CCR1=196; //40% PWM
break;
case 100:
CCR1=163;
break;
case 120:
CCR1=131; //60% PWM
break;
case 140:
CCR1=98; //60% PWM
break;
case 160:
CCR1=65; //80% PWM
break;
case 180:
CCR1=32; //80% PWM
break;
case 200:
CCR1=1; //100% PWM
break;
case 220:
CCR1=32; //80% PWM
break;
case 240:
CCR1=65;
break;
case 260:
CCR1=98; //60% PWM
break;
case 280:
CCR1=131;
break;
case 300:
CCR1=163;
break;
case 320:
CCR1=196;
break; |