本帖最后由 nwx8899 于 2012-6-18 16:56 编辑
用launchpad 模拟的呼吸灯
这是一个利用msp430 launchpad 产生PWM波形来控制LED2产生呼吸效果的程序
用手机拍了个效果发到优酷了
又拍了个稍微清晰点的http://v.youku.com/v_show/id_XNDE1NTUxMjI4.html
#include "msp430g2231.h"
unsigned int rate=10;
unsigned char updown = 1;
void main(void) {
WDTCTL = WDT_ADLY_16; // WDT 16ms, ACLK, interval timer
//BCSCTL1 = CALDCO_8MHZ; // Set range
//DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation
P1DIR |= BIT0 | BIT6;
P1SEL |= BIT6;
P1OUT = 0;
CCR0 = 128; // PWM Period
CCTL1 = OUTMOD_6; // CCR1 reset/set
CCR1 = rate; // CCR1 PWM duty cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
IE1 |= WDTIE;
_BIS_SR(LPM3_bits + GIE);
while(1);
}
#pragma vector=WDT_VECTOR
__interrupt void interrupt_watchdog_timer(void){
CCR1 = rate;
if(updown){
rate += 3;
if(rate >= 120){
updown = 0;
}
}else{
rate -= 3;
if(rate <= 10){
updown = 1;
}
}
}
|