/* * Sound the speaker at 440Hz * The speaker is connected to PORTC 4. * Default system clock 16 MHz is used. */ #include "TM4C123GH6PM.h" void delayUs(int n); int main(void) { volatile unsigned char readback; // enable PORTC 4 as output SYSCTL->RCGCGPIO |= 0x04; // enable clock to GPIOC readback = SYSCTL->RCGCGPIO; // make sure the clock is enabled GPIOC->AMSEL &= ~0x10; // disable analog function of PORTC 4 GPIOC->DIR |= 0x10; // set PORTC 4 as output pins GPIOC->DEN |= 0x10; // set PORTC 4 as digital pins for (;;) { GPIOC->DATA |= 0x10; // turn on PC4 delayUs(1136); GPIOC->DATA &= ~0x10; // turn on PC4 delayUs(1136); } } // delay n microseconds (16 MHz CPU clock) void delayUs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 3; j++) {} // do nothing for 1 us } // 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; }