/* www.microDigitalEd.com * p5_9.c Toggling green LEDs at 1 Hz using Timer_A and Auxiliary clock * * This program uses Timer_A to generate 1 second delay to * toggle the green LED. * Auxiliary clock (ACLK) running at 32,768 Hz is used. * Timer_A is configured to count up from 0 to 512-1, * which is loaded in TIMER_A1->CCR[0]. * When the counter (TA1R) value reaches TIMER_A1->CCR[0], * the CCIFG bit in TIMER_A1->CCTL[0] is set. * The clock input dividers are set to divide by 8 and 8 again. * The timer counter roll over interval is: * 32,768 / 8 / 8 / 512 = 1 Hz. * The green LED is connected to P2.1. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" int main(void) { /* initialize P2.1 for green LED */ P2->SEL1 &= ~2; /* configure P2.1 as simple I/O */ P2->SEL0 &= ~2; P2->DIR |= 2; /* P2.1 set as output */ TIMER_A1->CTL = 0x01D1; /* ACLK, ID = /8, up mode, TA clear */ TIMER_A1->CCR[0] = 512 - 1; /* for 1 sec */ TIMER_A1->EX0 = 7; /* IDEX = /8 */ while (1) { while((TIMER_A1->CCTL[0] & 1) == 0); /* wait until the CCIFG flag is set */ TIMER_A1->CCTL[0] &= ~1; /* clear interrupt flag */ P2->OUT ^= 2; /* toggle green LED */ } }