/* www.MicroDigitalEd.com * p5_7.c Toggling blue LED using Timer32 with prescaler * * This program uses Timer32 with prescaler to generate 1 second delay to * toggle the blue LED. * Master clock is running at 3 MHz. Timer32 is configured * with prescaler divides the incoming clock by 256. The * clock feeding the counter has the frequency of * 3,000,000 / 256 ~= 11719. * Since it is running at periodic mode, the counter reload is set to 11719-1 * to give a 1-second delay. * The blue LED is connected to P2.2. * * 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.2 for blue LED */ P2->SEL1 &= ~4; /* configure P2.2 as simple I/O */ P2->SEL0 &= ~4; P2->DIR |= 4; /* P2.2 set as output */ TIMER32_1->LOAD = 11719 - 1; /* set the reload value */ /* prescaler divided by 256, periodic wrapping mode, disable interrupt, 32-bit timer. */ TIMER32_1->CONTROL = 0xCA; while (1) { while((TIMER32_1->RIS & 1) == 0); /* wait until the RAW_IFG is set */ TIMER32_1->INTCLR = 0; /* clear raw interrupt flag */ P2->OUT ^= 4; /* toggle blue LED */ } }