diff options
Diffstat (limited to 'msp340/Timers/main.c')
| -rwxr-xr-x | msp340/Timers/main.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/msp340/Timers/main.c b/msp340/Timers/main.c new file mode 100755 index 0000000..59ecbdd --- /dev/null +++ b/msp340/Timers/main.c @@ -0,0 +1,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; + } + } +} |
