// PortF.c // Runs on LM4F120/TM4C123 // Simple GPIO on Port F. // Jonathan Valvano // September 20, 2018 /* This example accompanies the book "Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers", ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2018 Copyright 2018 by Jonathan W. Valvano, valvano@mail.utexas.edu You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ #include #include "tm4c123gh6pm.h" #include "PortF.h" // Initialize PortF switches and LEDs void PortF_Init(void){ volatile uint32_t delay; SYSCTL_RCGCGPIO_R |= 0x00000020; // 1) activate clock for Port F delay = SYSCTL_RCGCGPIO_R; // allow time for clock to start GPIO_PORTF_LOCK_R = 0x4C4F434B; // 2) unlock GPIO Port F GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0 // only PF0 needs to be unlocked, other bits can't be locked GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF GPIO_PORTF_PCTL_R = 0x00000000; // 4) PCTL GPIO on PF4-0 GPIO_PORTF_DIR_R = 0x0E; // 5) PF4,PF0 in, PF3-1 out GPIO_PORTF_AFSEL_R = 0x00; // 6) disable alt funct on PF7-0 GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4 GPIO_PORTF_DEN_R = 0x1F; // 7) enable digital I/O on PF4-0 } // read switches, // Bit4 and Bit0 are in negative logic // returns 0x00,0x01,0x10, or 0x11 uint32_t PortF_Input(void){ return (GPIO_PORTF_DATA_R&0x11); // read PF4,PF0 inputs } // Output to LEDs // LEDs on bits 1,2,3 void PortF_Output(uint32_t data){ // write PF3-PF1 outputs GPIO_PORTF_DATA_R = data; }