1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /* Copyright 2010 Ethan Blanton */
- /*
- * Configure TimerA to run off VLOCLK/LFXT1, then toggle an LED (about)
- * once per second off the slow timer, with the processor sleeping (DCO
- * off) in between.
- * */
- #include <msp430g2553.h>
- #include <io.h>
- #include <signal.h>
- /* Define USEXTAL if you have a 32kHz watch crystal installed and want
- * to use it as your time base -- giving you much more accurate
- * timings. */
- #ifdef USEXTAL
- #define TRIGGER 32767
- #else
- #define TRIGGER 12000
- #endif
- #define LED 0x01
- int main()
- {
- WDTCTL = WDTPW | WDTHOLD;
- /* Set the entire port P1 to output to reduce power consumption. */
- P1DIR = 0xff;
- P1OUT = LED;
- #ifndef USEXTAL
- /* Set the LF clock to the internal VLO. When using an external
- * crystal, it will be sourced for the LF clock by default. */
- BCSCTL3 |= LFXT1S_2;
- #endif
- /* Configure the Timer A count limit */
- TACCR0 = TRIGGER;
- /* Enable the timer interrupt */
- TACCTL0 |= CCIE;
- /* Configure Timer A for ACLK, start the timer. */
- TACTL = TASSEL_1 | MC_1;
- /* Enable interrupts */
- eint();
- LPM3; /* Sleep! */
- /* Unreached. If this code were reached, the LED would stay
- * continuously lit. */
- while (1)
- P1OUT = LED;
- }
- /* On TimerA interrupt, toggle the LED status and then go back to
- * sleep. */
- #pragma vector=TIMERA0_VECTOR
- __interrupt void Timer_A (void)
- {
- P1OUT ^= LED;
- }
|