/* * Read switches and use the data to set LEDs for TI Tiva LaunchPad * with Wytec EduBase. On Wytec EduBase board, PB3-PB0 are connected * to the four LEDs and PD3-PD0 are connected to both the DIP switches (SW1) * and the pushbuton switches (SW2-SW5). * In order for the pushbutton switches to be effective, the DIP switches * must be at the off position. */ #include "TM4C123GH6PM.h" int main(void) { volatile unsigned char readback; unsigned char data; // enable PORTB 3-0 as output SYSCTL->RCGCGPIO |= 0x02; // enable clock to GPIOB readback = SYSCTL->RCGCGPIO; // make sure the colock is enabled GPIOB->DIR |= 0x0F; // set PORTB 3-0 as output pins GPIOB->DEN |= 0x0F; // set PORTB 3-0 as digital pins // enable PORTD 3-0 as input SYSCTL->RCGCGPIO |= 0x08; // enable clock to GPIOD readback = SYSCTL->RCGCGPIO; GPIOD->DIR &= ~0x0F; // set pin 3-0 as input GPIOD->AMSEL &= ~0x0F; // disable analog functions GPIOD->DEN |= 0x0F; // set pin 3-0 as digital pins for (;;) { data = GPIOD->DATA; // read the switches and write to LEDs GPIOB->DATA = data; } } // 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; }