-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.c
More file actions
49 lines (40 loc) · 1.32 KB
/
Key.c
File metadata and controls
49 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Key.c
// This software configures the off-board piano keys
// Lab 6 requires a minimum of 4 keys, but you could have more
// Runs on LM4F120 or TM4C123
// Program written by: Devin Chaky
// Date Created: 1/2/17
// Last Modified: 2/20/23
// Lab number: 6
// Hardware connections
// Input switches on PA5-2
// Code files contain the actual implemenation for public functions
// this file also contains an private functions and private data
#include <stdint.h>
#include "../inc/tm4c123gh6pm.h"
// **************Key_Init*********************
// Initialize piano key inputs on PA5-2 or PE3-0
// Input: none
// Output: none
void Key_Init(void){
// used in Lab 6 , initialize input pins
volatile uint32_t delay;
SYSCTL_RCGCGPIO_R |= 0x10;
delay = SYSCTL_RCGCGPIO_R;
GPIO_PORTE_DIR_R &= ~(0x0F);
GPIO_PORTE_DEN_R |= 0x0F;
}
// **************Key_In*********************
// Input from piano key inputs on PA5-2 or PE3-0
// Input: none
// Output: 0 to 15 depending on keys
// 0x01 is just Key0, 0x02 is just Key1, 0x04 is just Key2, 0x08 is just Key3
uint32_t Key_In(void){
// write this
uint32_t input;
if((GPIO_PORTE_DATA_R & 0x40) == 0x40){
return 20;
}
input = (GPIO_PORTE_DATA_R & 0x0F); // shift two places to make 0-15 value
return input; // return input key value
}