+/EE445L
embedded systems
git clone https://git.julia.blue/+/EE445L
99480b6
master
1// PortF.c 2// Runs on LM4F120/TM4C123 3// Simple GPIO on Port F. 4// Jonathan Valvano 5// September 20, 2018 6 7/* This example accompanies the book 8"Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers", 9ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2018 1011 Copyright 2018 by Jonathan W. Valvano, valvano@mail.utexas.edu 12You may use, edit, run or distribute this file 13as long as the above copyright notice remains 14THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 15OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 16MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 17VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, 18OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 19For more information about my classes, my research, and my books, see 20http://users.ece.utexas.edu/~valvano/ 21*/ 22 23#include <stdint.h> 24#include "tm4c123gh6pm.h" 25#include "PortF.h" 26 27// Initialize PortF switches and LEDs 28void PortF_Init (void ){volatile uint32_t delay ; 29SYSCTL_RCGCGPIO_R |=0x00000020 ;// 1) activate clock for Port F 30delay = SYSCTL_RCGCGPIO_R ;// allow time for clock to start 31GPIO_PORTF_LOCK_R = 0x4C4F434B ;// 2) unlock GPIO Port F 32GPIO_PORTF_CR_R = 0x1F ;// allow changes to PF4-0 33// only PF0 needs to be unlocked, other bits can't be locked 34GPIO_PORTF_AMSEL_R = 0x00 ;// 3) disable analog on PF 35GPIO_PORTF_PCTL_R = 0x00000000 ;// 4) PCTL GPIO on PF4-0 36GPIO_PORTF_DIR_R = 0x0E ;// 5) PF4,PF0 in, PF3-1 out 37GPIO_PORTF_AFSEL_R = 0x00 ;// 6) disable alt funct on PF7-0 38GPIO_PORTF_PUR_R = 0x11 ;// enable pull-up on PF0 and PF4 39GPIO_PORTF_DEN_R = 0x1F ;// 7) enable digital I/O on PF4-0 40} 41// read switches, 42// Bit4 and Bit0 are in negative logic 43// returns 0x00,0x01,0x10, or 0x11 44uint32_t PortF_Input (void ){ 45return (GPIO_PORTF_DATA_R & 0x11 );// read PF4,PF0 inputs 46} 47// Output to LEDs 48// LEDs on bits 1,2,3 49void PortF_Output (uint32_t data ){// write PF3-PF1 outputs 50GPIO_PORTF_DATA_R = data ; 51} 52