/* p2_9.c: Display number 14 on a 2-digit 7-segment LED. */ #include "TM4C123GH6PM.h" void delayMs(int n); int main(void) { unsigned char digitPattern[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; /*from Table 2-4 */ SYSCTL->RCGCGPIO |= 0x01; /* enable clock to GPIOA */ SYSCTL->RCGCGPIO |= 0x02; /* enable clock to GPIOB */ GPIOB->DIR = 0xFF; /* set all PORTB pins as output to drive segments */ GPIOB->DEN = 0xFF; /* set all PORTB pins as digital pins */ GPIOA->DIR = 0xC0; /* set PORTA pin 7-6 as output to select digit */ GPIOA->DEN = 0xC0; /* set PORTA pin 7-6 as digital pins */ for(;;) { GPIOB->DATA = digitPattern[1]; /* drive pattern of 1 on the segments */ GPIOA->DATA = 0x80; /* select left digit */ delayMs(8); /* delay 8 ms will result in 16 ms per loop */ /* or 62.5 Hz */ GPIOB->DATA = digitPattern[4]; /* drive pattern of 4 on the segments */ GPIOA->DATA = 0x40; /* select right digit */ delayMs(8); } } /* delay n milliseconds (16 MHz CPU clock) */ void delayMs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 3180; j++) {} /* do nothing for 1 ms */ } /* This function is called by the startup assembly code to perform system specific initialization tasks. */ void SystemInit(void) { /* Grant coprocessor access */ /* This is required since TM4C123G has a floating point coprocessor */ SCB->CPACR |= 0x00F00000; }