/* * This program drives the speaker on the Wytec EduBase board * at 440 Hz using WTIMER0A in PWM mode. * */ #include "TM4C123GH6PM.h" void delayMs(int n); void delayUs(int n); int main(void) { SYSCTL->RCGCGPIO |= 0x04; // enable clock to GPIOC SYSCTL->RCGCWTIMER |= 0x01; // enable clock to Timer Block 0 // enable PORTC 4 as output 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 GPIOC->AFSEL |= 0x10; // enable alternate function GPIOC->PCTL &= ~0x000F0000; // clear alternate function for PORTC 4 GPIOC->PCTL |= 0x00070000; // set PORTC 4 alternate function to WTIMER WTIMER0->CTL &= ~1; // disable WTIMER0A during setup WTIMER0->CFG = 4; // configure as 32-bit timer mode WTIMER0->TAMR = 0x0A; // down-count, PWM-periodic mode WTIMER0->TAILR = 36362; // set frequency to 440 Hz WTIMER0->TAMATCHR = 18180; // set duty cycle to 50% WTIMER0->CTL |= 1; // enable WTIMER0A while(1) { } } // 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 } // 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; }