/* www.MicroDigitalEd.com * p5_1.c Toggling LEDs using SysTick counter * * This program lets the SysTick counter run freely and dumps * the counter values to the tri-color LEDs continuously. * The counter value is shifted 21 places to the right so that * the changes of LEDs will be slow enough to be visible. * SysTick counter has 24 bits. * The blue LED is connected to P2.2. * The green LED is connected to P2.1. * 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) { int c; /* initialize P2.2-P2.0 for tri-color LEDs */ P2->SEL1 &= ~7; /* configure P2.2-P2.0 as simple I/O */ P2->SEL0 &= ~7; P2->DIR |= 7; /* P2.2-P2.0 set as output */ /* Configure SysTick */ SysTick->LOAD = 0xFFFFFF; /* reload reg. with max value */ SysTick->VAL = 0; /* clear current value register */ SysTick->CTRL = 5; /* enable it, no interrupt, use master clock */ while (1) { c = SysTick->VAL; /* read current value of down counter */ P2->OUT = c >> 21; /* line up counter MSB with LED */ } }