/* * Read switches and use the data to set LEDs on the Digilent Orbit BoosterPack. * The switches are connected to the MCU as: * SW1 PA7 * SW2 PA6 * BTN1 PD2 * BTN2 PE0 * The LEDs are connected to the MCU as: * LD1 PC6 * LD2 PC7 * LD3 PD6 * LD4 PB5 * Default system clock 16 MHz is used. */ #include "TM4C123GH6PM.h" int main(void) { volatile unsigned char readback; SYSCTL->RCGCGPIO |= 0x1F; // enable clock to GPIOA, GPIOB, GPIOC, GPIOD, GPIOE readback = SYSCTL->RCGCGPIO; // make sure the clock is enabled // configure input pins GPIOA->DIR &= ~0xC0; // set PORTA 7, 6 as input pins GPIOA->DEN |= 0xC0; // set PORTA 7, 6 as digital pins GPIOD->DIR &= ~0x04; // set PORTD 2 as input pins GPIOD->DEN |= 0x04; // set PORTD 2 as digital pins GPIOE->DIR &= ~0x01; // set PORTE 0 as input pins GPIOE->DEN |= 0x01; // set PORTE 0 as digital pins // configure output pins GPIOC->DIR |= 0xC0; // set PORTC 7, 6 as output pins GPIOC->DEN |= 0xC0; // set PORTC 7, 6 as digital pins GPIOD->DIR |= 0x40; // set PORTD 6 as output pins GPIOD->DEN |= 0x40; // set PORTD 6 as digital pins GPIOB->DIR |= 0x20; // set PORTB 5 as output pins GPIOB->DEN |= 0x20; // set PORTB 5 as digital pins for (;;) { // infinite loop if(GPIOD->DATA & 0x04) // read the BTN1 and turn on/off LD1 GPIOC->DATA |= 0x40; else GPIOC->DATA &= ~0x40; if(GPIOE->DATA & 0x01) // read the BTN2 and turn on/off LD2 GPIOC->DATA |= 0x80; else GPIOC->DATA &= ~0x80; if(GPIOA->DATA & 0x80) // read the SW1 and turn on/off LD3 GPIOD->DATA |= 0x40; else GPIOD->DATA &= ~0x40; if(GPIOA->DATA & 0x40) // read the SW2 and turn on/off LD4 GPIOB->DATA |= 0x20; else GPIOB->DATA &= ~0x20; } } // 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; }