/* p7_5.c: DAC programming to generate sine wave */ #include "TM4C123GH6PM.h" void delayMs(int n); uint8_t sineWaveLookup[]={128,192,238,255,238,192,128,64,17,0,17,64}; int main(void) { uint8_t i = 0; SYSCTL->RCGCGPIO |= 0x02; /* enable clock to GPIOB */ /* PORTB for DAC */ GPIOB->DIR = 0xFF; /* PORTB as output */ GPIOB->DEN = 0xFF; /* PORTB as digital pins */ for (;;) { for (i = 0; i < 12; i++) { GPIOB->DATA = sineWaveLookup[i]; i++; delayMs(5); } } } /* 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; }