+/EE445L

embedded systems

git clone https://git.julia.blue/+/EE445L

jspspikeAdded lab4 files99480b6

master
2.1 KiB52 linesraw
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",
9   ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2018
10 
11 Copyright 2018 by Jonathan W. Valvano, valvano@mail.utexas.edu
12    You may use, edit, run or distribute this file
13    as long as the above copyright notice remains
14 THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
15 OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
16 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
17 VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
18 OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
19 For more information about my classes, my research, and my books, see
20 http://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;
29  SYSCTL_RCGCGPIO_R |= 0x00000020;  // 1) activate clock for Port F
30  delay = SYSCTL_RCGCGPIO_R;        // allow time for clock to start
31  GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F
32  GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
33  // only PF0 needs to be unlocked, other bits can't be locked
34  GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog on PF
35  GPIO_PORTF_PCTL_R = 0x00000000;   // 4) PCTL GPIO on PF4-0
36  GPIO_PORTF_DIR_R = 0x0E;          // 5) PF4,PF0 in, PF3-1 out
37  GPIO_PORTF_AFSEL_R = 0x00;        // 6) disable alt funct on PF7-0
38  GPIO_PORTF_PUR_R = 0x11;          // enable pull-up on PF0 and PF4
39  GPIO_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){
45  return (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
50  GPIO_PORTF_DATA_R = data;
51}
52