main.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2010 Ethan Blanton */
  2. /*
  3. * Configure TimerA to run off VLOCLK/LFXT1, then toggle an LED (about)
  4. * once per second off the slow timer, with the processor sleeping (DCO
  5. * off) in between.
  6. * */
  7. #include <msp430g2553.h>
  8. #include <io.h>
  9. #include <signal.h>
  10. /* Define USEXTAL if you have a 32kHz watch crystal installed and want
  11. * to use it as your time base -- giving you much more accurate
  12. * timings. */
  13. #ifdef USEXTAL
  14. #define TRIGGER 32767
  15. #else
  16. #define TRIGGER 12000
  17. #endif
  18. #define LED 0x01
  19. int main()
  20. {
  21. WDTCTL = WDTPW | WDTHOLD;
  22. /* Set the entire port P1 to output to reduce power consumption. */
  23. P1DIR = 0xff;
  24. P1OUT = LED;
  25. #ifndef USEXTAL
  26. /* Set the LF clock to the internal VLO. When using an external
  27. * crystal, it will be sourced for the LF clock by default. */
  28. BCSCTL3 |= LFXT1S_2;
  29. #endif
  30. /* Configure the Timer A count limit */
  31. TACCR0 = TRIGGER;
  32. /* Enable the timer interrupt */
  33. TACCTL0 |= CCIE;
  34. /* Configure Timer A for ACLK, start the timer. */
  35. TACTL = TASSEL_1 | MC_1;
  36. /* Enable interrupts */
  37. eint();
  38. LPM3; /* Sleep! */
  39. /* Unreached. If this code were reached, the LED would stay
  40. * continuously lit. */
  41. while (1)
  42. P1OUT = LED;
  43. }
  44. /* On TimerA interrupt, toggle the LED status and then go back to
  45. * sleep. */
  46. #pragma vector=TIMERA0_VECTOR
  47. __interrupt void Timer_A (void)
  48. {
  49. P1OUT ^= LED;
  50. }