This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

【MSP430 LaunchPad设计心得】利用MSP430 LaunchPad实现呼吸灯

 收到MSP 430 LaunchPad后激动不已,在这里把我的学习心得分享给大家。这是一个利用msp430 launchpad 产生PWM波形来控制LED1产生呼吸效果的程序,当然 你可以扩展为更多的LED,此程序完全不需外部扩展只要您拥有 msp430 launchpda 即可实现。 launchpad 不只是学,你还可以玩出更多花样。

下面附上代码

#include  <msp430x14x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  unsigned int i,j,k=0;
  P1DIR |= 0x0C;                            // P1.2 and P1.3 output
  P1SEL |= 0x0C;                            // P1.2 and P1.3 TA1/2 otions
  CCR0 = 256;                               // PWM Period/2
  CCTL1 = OUTMOD_6;                         // CCR1 toggle/set
                                 
  TACTL = TASSEL_1 + MC_3;                  // ACLK, up-down mode

  while(1)
  {
     i=1500;j=1;
     CCR1 = k++;
    
     while(j--)
     while(i--);
     if(k==257)
     {
         k--;
         WDTCTL = WDT_ADLY_250;                    // WDT 250ms, ACLK, interval timer
         IE1 |= WDTIE;
         _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/interrupt
        for(;k>50;)
        {
        i=1000;j=1;
        CCR1 = k--;
       
        while(j--)
        while(i--);
        }
       
     }
  }
 
}

#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
  WDTCTL = WDTPW + WDTHOLD;
  LPM3_EXIT;
}