RT 废话不多说 LED2 为呼吸灯 效果不是很好 步进太大了
贴代码
#include<msp430g2221.h>
void BreathLED()
{
P1SEL =BIT6;
P1DIR = BIT6;
P1OUT=0;
TACTL = TASSEL_1 + MC_1 ;
TACCTL1 = OUTMOD_3 ;
TACCTL0 = CCIE;
CCR0 =328;
CCR1 =327; //0% pwm
TACTL |=TACLR;
_EINT();
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BreathLED();
LPM0;
return 0;
}
#pragma vector=TIMERA0_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;
case 340:
CCR1=228; //40% PWM
break;
case 350:
CCR1=245; //40% PWM
break;
case 360:
CCR1=262;
break;
case 370:
CCR1=277;
break;
case 380:
CCR1=294;
break;
case 390:
CCR1=310;
break;
case 400:
{
CCR1=327;
Times=0;
}
break;
default:
break;
}
}
希望有人接着另一方法做!
for(i=0;i<500;i++) //所有的灯逐渐从暗到全亮。
{
for(m=i;m>0;m--)
DATAPORT=0X00;
for(m=500-i;m>0;m--)
DATAPORT=0XFF;
}
这样要简单一点。。。
哈哈,也是一种创新啊,步进要是不合理的话可能就是一阶一阶的,没有DA和PWM平滑,支持楼主将程序简化!
[
本帖最后由 智波景严 于 2012-10-2 11:36 编辑 ]