-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
167 lines (139 loc) · 4.74 KB
/
main.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <stdint.h>
void delay(void){
for(int i=0;i<300000;i++);
}
int main(void)
{
/* Loop forever */
uint32_t volatile *const RCC=(uint32_t*)0x40023830;
uint32_t volatile *const GPIOA_MODE=(uint32_t*)0x40020000;
uint32_t volatile *const GPIOB_MODE=(uint32_t*)0x40020400;
uint32_t volatile *const IDRA=(uint32_t*)0x40020010;
uint32_t volatile *const ODR_B=(uint32_t*)0x40020414;
uint32_t volatile *const GPIOA_PULLUP=(uint32_t*)0x4002000C;
uint32_t volatile *const GPIOB_PULLUP=(uint32_t*)0x4002040C;
uint32_t volatile *const ODR_A=(uint32_t*)0x40020014;
//RESET AND CLOCK CONTROL
*RCC=*RCC | (1<<0);
*RCC=*RCC | (1<<1);
//CLEARING
//KEYPAD
*GPIOB_MODE=*GPIOB_MODE & ~(1<<12);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<13);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<18);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<19);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<10);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<11);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<20);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<21);
//LED
*GPIOA_MODE=*GPIOA_MODE & ~(1<<18);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<19);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<10);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<11);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<12);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<13);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<14);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<15);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<20);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<21);
//Setting OUTPUT MODE
//KEYPAD
*GPIOB_MODE=*GPIOB_MODE | (1<<12);
*GPIOB_MODE=*GPIOB_MODE | (1<<18);
*GPIOB_MODE=*GPIOB_MODE | (1<<10);
*GPIOB_MODE=*GPIOB_MODE | (1<<20);
//LED
*GPIOA_MODE=*GPIOA_MODE | (1<<18);
*GPIOA_MODE=*GPIOA_MODE | (1<<10);
*GPIOA_MODE=*GPIOA_MODE | (1<<12);
*GPIOA_MODE=*GPIOA_MODE | (1<<14);
*GPIOA_MODE=*GPIOA_MODE | (1<<20);
//SETTING INPUT MODE
*GPIOA_MODE=*GPIOA_MODE & ~(1<<0);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<1);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<2);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<3);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<8);
*GPIOA_MODE=*GPIOA_MODE & ~(1<<9);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<0);
*GPIOB_MODE=*GPIOB_MODE & ~(1<<1);
//SETTING PULL UP RESISTOR FOR COLUMN I/0
*GPIOA_PULLUP=*GPIOA_PULLUP | (1<<0);
*GPIOA_PULLUP=*GPIOA_PULLUP | (1<<2);
*GPIOA_PULLUP=*GPIOA_PULLUP | (1<<8);
*GPIOB_PULLUP=*GPIOB_PULLUP | (1<<0);
while(1){
//MAKE ALL ROW HIGH
*ODR_B=*ODR_B | (1<<10);
*ODR_B=*ODR_B | (1<<9);
*ODR_B=*ODR_B | (1<<5);
*ODR_B=*ODR_B | (1<<6);
//MAKE R1 LOW
*ODR_B=*ODR_B & ~(1<<10);
if(!(*IDRA & (1<<0))){
delay();
*ODR_A=*ODR_A | (1<<9); //1 LED ON
for(int i=0;i<600000;i++);
*ODR_A=*ODR_A & ~(1<<9);
}
if(!(*IDRA & (1<<1))){ //2 LED ON
delay();
*ODR_A=*ODR_A | (1<<9);
*ODR_A=*ODR_A | (1<<5);
for(int i=0;i<600000;i++);
*ODR_A=*ODR_A & ~(1<<9);
*ODR_A=*ODR_A & ~(1<<5);
}
if(!(*IDRA & (1<<4))){ //3 LED ON
delay();
*ODR_A=*ODR_A | (1<<9);
*ODR_A=*ODR_A | (1<<5);
*ODR_A=*ODR_A | (1<<10);
for(int i=0;i<600000;i++);
*ODR_A=*ODR_A & ~(1<<9);
*ODR_A=*ODR_A & ~(1<<5);
*ODR_A=*ODR_A & ~(1<<10);
}
//Make R2 LOW
*ODR_B=*ODR_B & ~(1<<9);
//4 LED ON
if(!(*IDRA & (1<<0))){
delay();
*ODR_A=*ODR_A | (1<<9);
*ODR_A=*ODR_A | (1<<5);
*ODR_A=*ODR_A | (1<<10);
*ODR_A=*ODR_A | (1<<7);
for(int i=0;i<600000;i++);
*ODR_A=*ODR_A & ~(1<<9);
*ODR_A=*ODR_A & ~(1<<5);
*ODR_A=*ODR_A & ~(1<<10);
*ODR_A=*ODR_A & ~(1<<7);
}
//5 LED ON
if(!(*IDRA & (1<<1))){
delay();
*ODR_A=*ODR_A | (1<<9);
*ODR_A=*ODR_A | (1<<5);
*ODR_A=*ODR_A | (1<<10);
*ODR_A=*ODR_A | (1<<7);
*ODR_A=*ODR_A | (1<<6);
for(int i=0;i<600000;i++);
*ODR_A=*ODR_A & ~(1<<9);
*ODR_A=*ODR_A & ~(1<<5);
*ODR_A=*ODR_A & ~(1<<10);
*ODR_A=*ODR_A & ~(1<<7);
*ODR_A=*ODR_A & ~(1<<6);
}
//ALL THE LED OFF
*ODR_B=*ODR_B & ~(1<<6);
if(!(*IDRA & (1<<0))){
delay();
*ODR_A=*ODR_A & ~(1<<9);
*ODR_A=*ODR_A & ~(1<<5);
*ODR_A=*ODR_A & ~(1<<10);
*ODR_A=*ODR_A & ~(1<<7);
*ODR_A=*ODR_A & ~(1<<6);
}
}
}