/* Sound the speaker at 440Hz * * The speaker is connected to PORTC 4. * Default clock 50 MHz is used. * Delay loop is used for time interval. The number * of delay cycles is determined empirically. * * Built and tested with Keil MDK-ARM v5.24a and TM4C_DFP v1.1.0 */ #include "TM4C123.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 PB2, 0 delayUs(1184); GPIOC->DATA &= ~0x10; // turn on PB3, 1 delayUs(1184); } } /* delay n microseconds (50 MHz CPU clock) */ void delayUs(int n) { int i, j; for(i = 0 ; i< n; i++) for(j = 0; j < 6; j++) {} /* do nothing for 1 ms */ }