msp430x22x4_lpm3_vlo.c


1
//******************************************************************************
2
//   MSP430F22x4 Demo - Basic Clock, LPM3 Using WDT ISR, VLO ACLK
3
//
4
//   Description: This program operates MSP430 normally in LPM3, pulsing P1.0
5
//   ~ 6 second intervals. WDT ISR used to wake-up system. All I/O configured
6
//   as low outputs to eliminate floating inputs. Current consumption does
7
//   increase when LED is powered on P1.0. Demo for measuring LPM3 current.
8
//   ACLK = VLO/2, MCLK = SMCLK = default DCO ~1.2MHz
9
//
10
//                MSP430F22x4
11
//             -----------------
12
//         /|\|              XIN|-
13
//          | |                 |
14
//          --|RST          XOUT|-
15
//            |                 |
16
//            |             P1.0|-->LED
17
//
18
//   A. Dannenberg
19
//   Texas Instruments Inc.
20
//   October 2006
21
//   Built with IAR Embedded Workbench Version: 3.41A
22
//******************************************************************************
23
#include "msp430x22x4.h"
24
25
volatile unsigned int i;
26
27
void main(void)
28
{
29
  WDTCTL = WDT_ADLY_1000;                   // WDT 1s*4 interval timer
30
  BCSCTL1 |= DIVA_1;                        // ACLK/2
31
  BCSCTL3 |= LFXT1S_2;                      // ACLK = VLO
32
  IE1 |= WDTIE;                             // Enable WDT interrupt
33
  P1DIR = 0xFF;                             // All P1.x outputs
34
  P1OUT = 0;                                // All P1.x reset
35
  P2SEL = 0;                                // All P2.x GPIO function
36
  P2DIR = 0xFF;                             // All P2.x outputs
37
  P2OUT = 0;                                // All P2.x reset
38
  P3DIR = 0xFF;                             // All P3.x outputs
39
  P3OUT = 0;                                // All P3.x reset
40
  P4DIR = 0xFF;                             // All P4.x outputs
41
  P4OUT = 0;                                // All P4.x reset
42
43
  while(1)
44
  {
45
    __bis_SR_register(LPM3_bits + GIE);     // Enter LPM3, enable interrupts
46
    P1OUT |= 0x01;                          // Set P1.0 LED on
47
    for (i = 5000; i > 0; i--);             // Delay
48
    P1OUT &= ~0x01;                         // Clear P1.0 LED off
49
  }
50
}
51
52
#pragma vector=WDT_VECTOR
53
__interrupt void watchdog_timer (void)
54
{
55
  __bic_SR_register_on_exit(LPM3_bits);     // Clear LPM3 bits from 0(SR)
56
}