/* www.MicroDigitalEd.com * p5_6.c Toggling blue LEDs at 1 Hz using Timer32 one-shot mode * * This program uses Timer32 to generate 1 second delay to * toggle the blue LED. * Master clock is running at 3 MHz. Timer32 is configured * as one-shot mode to count down from 3,000,000 to 0 to give * a 1 second delay. In order to restart another one-shot, * the TIMER32_1->LOAD register is reloaded. * The blue LED is connected to P2.2. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #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 = 3000000; /* set the reload value */ /* no prescaler, one-shot mode, disable interrupt, 32-bit timer. */ TIMER32_1->CONTROL = 0xC3; 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 */ TIMER32_1->LOAD = 3000000; /* reload LOAD register to restart one-shot */ } }