/* www.microDigitalEd.com * p5_8.c Toggling red LED at 1 Hz using Timer_A * * This program uses Timer_A to generate 1 second delay to * toggle the red LED. * Subsystem Master Clock (SMCLK) running at 3 MHz is used. * Timer_A is configured to count up from 0 to 46,875-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. * The timer counter roll over interval is: * 3,000,000 / 8 / 8 / 46,875 = 1 Hz. * The red LED is connected to P2.0. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" int main(void) { /* initialize P2.0 for red LED */ P2->SEL1 &= ~1; /* configure P2.0 as simple I/O */ P2->SEL0 &= ~1; P2->DIR |= 1; /* P2.0 set as output */ TIMER_A1->CTL = 0x02D1; /* SMCLK, ID=/8, up mode, TA clear */ TIMER_A1->EX0 = 7; /* IDEX = /8 */ TIMER_A1->CCR[0] = 46875 - 1; /* for 1 sec */ while (1) { while((TIMER_A1->CCTL[0] & 1) == 0); /* wait until the CCIFG is set */ TIMER_A1->CCTL[0] &= ~1; /* clear interrupt flag */ P2->OUT ^= 1; /* toggle red LED */ } }