/* www.MicroDigitalEd.com * p5_2.c Toggling red LEDs at 1 Hz using SysTick * * This program uses SysTick to generate 1000 ms delay to * toggle the red LED. * Master clock is running at 3 MHz. SysTick is configured * to count down from 3,000,000-1 to give a 1s delay. * 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 */ /* Configure SysTick */ SysTick->LOAD = 3000000-1; /* reload reg. with 3,000,000-1 */ SysTick->VAL = 0; /* clear current value register */ SysTick->CTRL = 5; /* enable it, no interrupt, use master clock */ while (1) { if (SysTick->CTRL & 0x10000) /* if COUNTFLAG is set */ P2->OUT ^= 1; /* toggle red LED */ } }