/* www.microDigitalEd.com * p6_6.c Toggling red LED at 1 Hz using Timer_A1 interrupt * System clock running at 3 MHz is used. Timer_A1 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], CCIFG * bit in TIMER_A1->CCTL[0] is set and an interrupt is generated. * 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. * In the interrupt handler, the red LED is toggled. * The red LED is connected to P2.0. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" int main(void) { __disable_irq(); /* 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->CCR[0] = 46875 -1; /* for 1 sec */ TIMER_A1->EX0 = 7; /* IDEX = /8 */ TIMER_A1->CCTL[0] |= 0x10; /* enable TA1.0 interrupt */ NVIC_SetPriority(TA1_0_IRQn, 3); /* set priority to 3 in NVIC */ NVIC_EnableIRQ(TA1_0_IRQn); /* enable interrupt in NVIC */ __enable_irq(); /* global enable IRQs */ while (1) { } } void TA1_0_IRQHandler(void) { TIMER_A1->CCTL[0] &= ~1; /* clear interrupt flag */ P2->OUT ^= 1; /* toggle red LED */ }