/* Read switches and use the data to set LEDs for TI Tiva LaunchPad * with EduPad. * * On EduPad board, PB3-PB0 are connected to the four LEDs. * Switches are connected to PD3-PD0 * S1 - PD0 * S2 - PD1 * S3 - PD2 * S4 - PD3 * * Built and tested with Keil MDK-ARM v5.24a and TM4C_DFP v1.1.0 */ #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; } }