/* 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 #include /* 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. */ interrupt (TIMERA0_VECTOR) ta_handler() { P1OUT ^= LED; }