-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyPad_Edit1
57 lines (50 loc) · 1.47 KB
/
keyPad_Edit1
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
50
51
52
53
54
55
56
57
#include "TM4C123GH6PM.h"
void SystemInit(){}
void initialize_PortE_A () {
SYSCTL_RCGCGPIO_R |= 0x11;
while(!(SYSCTL_PRGPIO_R & 0x11)){};
//No lock code for PORT_E
GPIO_PORTA_LOCK_R = 0x4C4F434B ;
//First 4 pins of port E ---> Output
GPIO_PORTE_CR_R = 0x0F ; //Overwrite portE 3, 2, 1, and 0
GPIO_PORTE_AMSEL_R &= ~0x1D ; //DigT IO
GPIO_PORTE_PCTL_R = 0 ;
GPIO_PORTE_AFSEL_R = 0 ;
GPIO_PORTE_DIR_R = 0x0F ; //First 4 pins port E output X
GPIO_PORTE_DEN_R = 0x1F ; //Enable all 5 pins digital
GPIO_PORTE_PUR_R = 0x11;
GPIO_PORTE_DATA_R = 0 ; //Initialize all 5 pins of port E to 0
//First 4 pins of port A ---> Input
GPIO_PORTA_CR_R = 0xEF; //Overwrite for portA 7, 6, 5, 3, 2, 1, and 0
GPIO_PORTA_AMSEL_R = 0 ; //DigT IO
GPIO_PORTA_PCTL_R = 0 ;
GPIO_PORTA_AFSEL_R = 0 ;
GPIO_PORTA_DIR_R = 0xE0 ; //first 4 pins of port A input
GPIO_PORTA_DEN_R = 0xFF ; //all of portA digital_enable
GPIO_PORTA_DATA_R = 0; //Initialize portA values
}
char char_shift(char c, int n) {
return (char)(c + n);
}
int keyPad(){
int i, j;
char keymap [4][4] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'C', '0', '#', 'E'}
};
for (i = 0; i<4; i++) {
char X = 0x01; //0x00000001, First 4 pins of E
GPIO_PORTA_DATA_R = X;
for (j = 0; j<4; j++) {
char Y = 0x01; //0x00000001, First 4 pins of A
if(GPIO_PORTE_DATA_R == Y){
return keymap [i][j];
break;
}
char_shift(Y, 1);
}
char_shift(X, 1);
}
}