|
响应团购群发起的呼吸灯制作 我开个头LaunchPad做的呼吸灯
[复制链接]
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; } }
希望有人接着另一方法做!
|
|