/* www.microDigitalEd.com * p2_6.c Display number 75 on a 2-digit 7-segment common cathode LED. * * The segments are driven by Port4. * The digit selects are driven by P5.1 and P5.0. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" void delayMs(int n); int main(void) { const unsigned char digitPattern[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; P4->SEL1 &= ~0xFF; /* configure P4 as simple I/O */ P4->SEL0 &= ~0xFF; P4->DIR |= 0xFF; /* P4 set as output */ P5->SEL1 &= ~3; /* configure P5.1, P5.0 as simple I/O */ P5->SEL0 &= ~3; P5->DIR |= 3; /* P5.1, P5.0 set as output pins */ while(1){ P5->OUT &= ~1; /* deselect ones digit */ P4->OUT = digitPattern[7]; /* display tens digit */ P5->OUT |= 2; /* select tens digit */ delayMs(8); P5->OUT &= ~2; /* deselect tens digit */ P4->OUT = digitPattern[5]; /* display ones digit */ P5->OUT |= 1; /* select ones digit */ delayMs(8); } } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* Delay */ }