-
Notifications
You must be signed in to change notification settings - Fork 0
/
7seg.c
212 lines (196 loc) · 7.83 KB
/
7seg.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "7seg.h"
char My7segBUFF[6] = {'t', 'E', 'S', 't' , ' ' , 'u'};
int cnt = 0;
int digit_current_pos = 0; //0=prva levo,1=sredina 2=desno
int digit_current_dp = 0; //DP 0=nema, 1=prva levo,2=sredina 3=desno
void seg7InitPins(void) {
/*
PB5 - DP-SEG
PA2 - A-SEG
PA6 - B-SEG
PB4 - C-SEG
PB6 - D-SEG
PB7 - E-SEG
PA3 - F-SEG
PB3 - G-SEG
PA1 - SELL 1
PA4 - SELL 2
PA5 - SELL 3
PA15- SELL 4
PA7 - SELL 5
*/
//konfiguracija PB7, general purpose Output push-pull, 50MHz
GPIOB->CRL &= ~GPIO_CRL_CNF7_0; //ocisti bit
GPIOB->CRL &= ~GPIO_CRL_CNF7_1; //ocisti bit
GPIOB->CRL |= GPIO_CRL_MODE7_0; //setuj bit
GPIOB->CRL |= GPIO_CRL_MODE7_1; //setuj bit
//konfiguracija PB6, general purpose Output push-pull, 50MHz
GPIOB->CRL &= ~GPIO_CRL_CNF6_0; //ocisti bit
GPIOB->CRL &= ~GPIO_CRL_CNF6_1; //ocisti bit
GPIOB->CRL |= GPIO_CRL_MODE6_0; //setuj bit
GPIOB->CRL |= GPIO_CRL_MODE6_1; //setuj bit
//konfiguracija PB5, general purpose Output push-pull, 50MHz
GPIOB->CRL &= ~GPIO_CRL_CNF5_0; //ocisti bit
GPIOB->CRL &= ~GPIO_CRL_CNF5_1; //ocisti bit
GPIOB->CRL |= GPIO_CRL_MODE5_0; //setuj bit
GPIOB->CRL |= GPIO_CRL_MODE5_1; //setuj bit
//konfiguracija PB4, general purpose Output push-pull, 50MHz
GPIOB->CRL &= ~GPIO_CRL_CNF4_0; //ocisti bit
GPIOB->CRL &= ~GPIO_CRL_CNF4_1; //ocisti bit
GPIOB->CRL |= GPIO_CRL_MODE4_0; //setuj bit
GPIOB->CRL |= GPIO_CRL_MODE4_1; //setuj bit
//konfiguracija PB3, general purpose Output push-pull, 50MHz
GPIOB->CRL &= ~GPIO_CRL_CNF3_0; //ocisti bit
GPIOB->CRL &= ~GPIO_CRL_CNF3_1; //ocisti bit
GPIOB->CRL |= GPIO_CRL_MODE3_0; //setuj bit
GPIOB->CRL |= GPIO_CRL_MODE3_1; //setuj bit
//konfiguracija PA6, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF6_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF6_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE6_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE6_1; //setuj bit
//konfiguracija PA3, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF3_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF3_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE3_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE3_1; //setuj bit
//konfiguracija PA2, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF2_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF2_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE2_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE2_1; //setuj bit
//konfiguracija PA15, general purpose Output push-pull, 50MHz
GPIOA->CRH &= ~GPIO_CRH_CNF15_0; //ocisti bit
GPIOA->CRH &= ~GPIO_CRH_CNF15_1; //ocisti bit
GPIOA->CRH |= GPIO_CRH_MODE15_0; //setuj bit
GPIOA->CRH |= GPIO_CRH_MODE15_1; //setuj bit
//konfiguracija PA7, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF7_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF7_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE7_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE7_1; //setuj bit
//konfiguracija PA5, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF5_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF5_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE5_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE5_1; //setuj bit
//konfiguracija PA4, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF4_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF4_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE4_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE4_1; //setuj bit
//konfiguracija PA1, general purpose Output push-pull, 50MHz
GPIOA->CRL &= ~GPIO_CRL_CNF1_0; //ocisti bit
GPIOA->CRL &= ~GPIO_CRL_CNF1_1; //ocisti bit
GPIOA->CRL |= GPIO_CRL_MODE1_0; //setuj bit
GPIOA->CRL |= GPIO_CRL_MODE1_1; //setuj bit
dig1_off;
dig2_on;
dig3_off;
dig4_off;
dig5_off;
DP_1;
A_1;
B_1;
C_1;
D_1;
E_1;
F_1;
G_1;
}
void IntTo7seg(int num) { //num=0-99999
dig=5;
if (num < 159999) {
//1, 2, 3,....
//digit_current_dp = 2;*/
while (dig--) {
My7segBUFF[dig]=num%10;
num/=10;
}
} else {
My7segBUFF[0] = 'H';
My7segBUFF[1] = 'i';
My7segBUFF[2] = 'E';
My7segBUFF[3] = 'r';
My7segBUFF[4] = 'r';
digit_current_dp = 0;
}
}
//----------------------------------------------------
//Interupt from TIM3, handle 7-seg LED
//----------------------------------------------------
void handler_led() {
//all digits off
dig1_off;
dig2_off;
dig3_off;
dig4_off;
dig5_off;
DP_0;
switch (My7segBUFF[digit_current_pos]) {
case 0: A_1; B_1; C_1; D_1; E_1; F_1; G_0; break;
case 1: A_0; B_1; C_1; D_0; E_0; F_0; G_0; break;
case 2: A_1; B_1; C_0; D_1; E_1; F_0; G_1; break;
case 3: A_1; B_1; C_1; D_1; E_0; F_0; G_1; break;
case 4: A_0; B_1; C_1; D_0; E_0; F_1; G_1; break;
case 5: A_1; B_0; C_1; D_1; E_0; F_1; G_1; break;
case 6: A_1; B_0; C_1; D_1; E_1; F_1; G_1; break;
case 7: A_1; B_1; C_1; D_0; E_0; F_0; G_0; break;
case 8: A_1; B_1; C_1; D_1; E_1; F_1; G_1; break;
case 9: A_1; B_1; C_1; D_1; E_0; F_1; G_1; break;
case 0xA: case 'A': case 'a': A_1; B_1; C_1; D_0; E_1; F_1; G_1; break;
case 0xB: case 'b': case 'B': A_0; B_0; C_1; D_1; E_1; F_1; G_1; break;
case 0xC: case 'c': case 'C': A_1; B_0; C_0; D_1; E_1; F_1; G_0; break;
case 0xD: case 'D': case 'd': A_0; B_1; C_1; D_1; E_1; F_0; G_1; break;
case 0xE: case 'e': case 'E': A_1; B_0; C_0; D_1; E_1; F_1; G_1; break;
case 0xF: case 'f': case 'F': A_1; B_0; C_0; D_0; E_1; F_1; G_1; break;
case 'H': A_0; B_1; C_1; D_0; E_1; F_1; G_1; break;
case 'L': A_0; B_0; C_0; D_1; E_1; F_1; G_0; break;
case 'r': A_0; B_0; C_0; D_0; E_1; F_0; G_1; break;
case '-': A_0; B_0; C_0; D_0; E_0; F_0; G_1; break;
case 't': A_0; B_0; C_0; D_1; E_1; F_1; G_1; break;
case 'S': A_1; B_0; C_1; D_1; E_0; F_1; G_1; break;
case 'P': A_1; B_1; C_0; D_0; E_1; F_1; G_1; break;
case ' ': A_0; B_0; C_0; D_0; E_0; F_0; G_0; break;
case 'o': A_0; B_0; C_1; D_1; E_1; F_0; G_1; break;
case '=': A_0; B_0; C_0; D_1; E_0; F_0; G_1; break;
case 'n': A_0; B_0; C_1; D_0; E_1; F_0; G_1; break;
case 'm': case 'M': A_1; B_0; C_1; D_0; E_1; F_0; G_0; break;
case 'i': A_0; B_0; C_0; D_0; E_1; F_0; G_0; break;
case 'I': A_0; B_0; C_0; D_0; E_1; F_1; G_0; break;
case 'J': A_0; B_1; C_1; D_1; E_0; F_0; G_0; break;
case 'u': A_0; B_0; C_1; D_1; E_1; F_0; G_0; break;
case 'U': A_0; B_1; C_1; D_1; E_1; F_1; G_0; break;
}
switch (digit_current_pos) {
case 0: if (digit_current_dp == 1) {DP_1} dig1_on; break;
case 1: if (digit_current_dp == 2) {DP_1} dig2_on; break;
case 2: if (digit_current_dp == 3) {DP_1} dig3_on; break;
case 3: if (digit_current_dp == 4) {DP_1} dig4_on; break;
case 4: if (digit_current_dp == 5) {DP_1} dig5_on; break;
}
//hak da pratimo stanje input-a kao prva decimalna tacka :)
if ((GPIOB->IDR & GPIO_IDR_IDR9) == (0xffff & GPIO_IDR_IDR9)) {
if (digit_current_pos == 0) {
DP_1;
}
}
if (digit_current_pos++ >= 4) digit_current_pos = 0;
/*
//brigtness
//small delay
for (int xx = 0; xx < 400; xx++) {
gpio_write_bit(GPIOC, 13, HIGH);
}
//all digits off
//dig1_off;
//dig2_off;
//dig3_off;
//dig4_off;
dig5_off;
//dig6_off;
*/
//gpio_write_bit(GPIOC, 13, HIGH);
//dig5_off;
//dig6_off;
}