/* * www.microDigitalEd.com * * p2_4.c Cycle through all color combinations of the tri-color LEDs. * The red LED is connected to P2.0. * The green LED is connected to P2.1. * The blue LED is connected to P2.2. * The LEDs are high active (a '1' turns ON the LED). * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" void delayMs(int n); int main(void) { int counter = 0; P2->SEL1 &= ~7; /* configure P2.2-P2.0 as simple I/O */ P2->SEL0 &= ~7; P2->DIR |= 7; /* P2.2-2.0 set as output */ while (1) { /* turn on/off the tri-color LEDs by the least significant three bits of the counter */ P2->OUT = counter & 7; delayMs(500); counter++; /* increment counter */ } } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 250; i > 0; i--); /* Delay */ }