[Launchpad] 呼吸灯程序

 1 #include "msp430g2553.h"

 2 unsigned int rate = 0;

 3 unsigned char updown = 1;

 4 

 5 void main(void) {

 6 

 7     WDTCTL = WDT_MDLY_32;

 8 

 9     TACTL = TASSEL1 + TACLR;

10     TACTL |= MC0;

11 

12     CCR0 = 20; // PWM周期

13 

14     CCTL1 = OUTMOD_7;

15     CCR1 = 0;

16 

17     P1DIR |= 0x40; // P1.6 输出

18     P1SEL |= 0x40; // P1.6 TA0

19 

20 

21     IE1 |= WDTIE;

22     _EINT();

23 

24     for (;;) {

25         _NOP();

26     }

27 }

28 

29 #pragma vector=WDT_VECTOR

30 __interrupt void interrupt_watchdog_timer(void) {

31 

32     CCR1 = rate;

33     if (updown) {

34         rate += 1;

35         if (rate >= 20) 

36             updown = 0;     

37     }

38      else

39     {

40         rate -= 1;

41         if (rate <= 0) 

42             updown = 1;      

43     }

44 }

你可能感兴趣的:(HP)