summaryrefslogtreecommitdiff
path: root/msp340/Timers/main.c
blob: 59ecbdd1d7a3d78eca35fed96355ce445ecda7ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <msp430.h>

#define UP      0x0010      // Set MC bits to enable TimerA UP mode
#define ACLK    0x0100      // Configure TimerA to use the aux clock

#define TIME_LIMIT 5000    // Timer limit

#define RED_LED 0x0001
#define WDT_OFF 0x5A80
#define ENABLE_PINS 0xFFFE

#define TA_INT_FLAG   0x0001      // TimerA_0 CTL Register bit interrupt flag
                            // Raised by the timer when it reached its count

main() {
    WDTCTL  = WDT_OFF;       // Disable watchdog
    PM5CTL0 = ENABLE_PINS;   // Enable I/O pins

    TA0CCR0 = TIME_LIMIT;   // Set Capture/Compare Register to the number we want the
                            // timer to count. The timer compares its count with the number stored here.
    TA0CTL  = ACLK | UP;    // Setup TimerA_0 to UP mode


    P1DIR   = RED_LED;      // Set P1.0 pin as output

    while (1) {

        if (TA0CTL & TA_INT_FLAG) {
            P1OUT ^= RED_LED;

            // Reset timer by disabling its interrupt flag
            TA0CTL &= ~TA_INT_FLAG;
        }
    }
}