-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
273 lines (253 loc) · 8.34 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#include <p18f4550.h>
#include <string.h>
#include <delays.h>
#include <timers.h>
#pragma config PLLDIV = 5
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = HS
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config XINST = OFF
#define DELAY 255
#define DELAYEF 255
// defines the size of the char[] nome string
#define MAX 31
#define REP 20
#define MAXEF 20
// defines displays activations
#define DISP1 PORTAbits.RA5 = 1; PORTAbits.RA2 = 0; PORTEbits.RE0 = 0; PORTEbits.RE2 = 0;
#define DISP2 PORTAbits.RA5 = 0; PORTAbits.RA2 = 1; PORTEbits.RE0 = 0; PORTEbits.RE2 = 0;
#define DISP3 PORTAbits.RA5 = 0; PORTAbits.RA2 = 0; PORTEbits.RE0 = 1; PORTEbits.RE2 = 0;
#define DISP4 PORTAbits.RA5 = 0; PORTAbits.RA2 = 0; PORTEbits.RE0 = 0; PORTEbits.RE2 = 1;
#define DISPON PORTAbits.RA5 = 1; PORTAbits.RA2 = 1; PORTEbits.RE0 = 1; PORTEbits.RE2 = 1;
#define DISPOFF PORTAbits.RA5 = 0; PORTAbits.RA2 = 0; PORTEbits.RE0 = 0; PORTEbits.RE2 = 0;
// defines each segment in each displays
#define A1 PORTD = 0x01; DISP1; Delay1KTCYx(DELAYEF);
#define B1 PORTD = 0x02; DISP1; Delay1KTCYx(DELAYEF);
#define C1 PORTD = 0x04; DISP1; Delay1KTCYx(DELAYEF);
#define D1 PORTD = 0x08; DISP1; Delay1KTCYx(DELAYEF);
#define E1 PORTD = 0x10; DISP1; Delay1KTCYx(DELAYEF);
#define F1 PORTD = 0x20; DISP1; Delay1KTCYx(DELAYEF);
#define G1 PORTD = 0x40; DISP1; Delay1KTCYx(DELAYEF);
#define A2 PORTD = 0x01; DISP2; Delay1KTCYx(DELAYEF);
#define B2 PORTD = 0x02; DISP2; Delay1KTCYx(DELAYEF);
#define C2 PORTD = 0x04; DISP2; Delay1KTCYx(DELAYEF);
#define D2 PORTD = 0x08; DISP2; Delay1KTCYx(DELAYEF);
#define E2 PORTD = 0x10; DISP2; Delay1KTCYx(DELAYEF);
#define F2 PORTD = 0x20; DISP2; Delay1KTCYx(DELAYEF);
#define G2 PORTD = 0x40; DISP2; Delay1KTCYx(DELAYEF);
#define A3 PORTD = 0x01; DISP3; Delay1KTCYx(DELAYEF);
#define B3 PORTD = 0x02; DISP3; Delay1KTCYx(DELAYEF);
#define C3 PORTD = 0x04; DISP3; Delay1KTCYx(DELAYEF);
#define D3 PORTD = 0x08; DISP3; Delay1KTCYx(DELAYEF);
#define E3 PORTD = 0x10; DISP3; Delay1KTCYx(DELAYEF);
#define F3 PORTD = 0x20; DISP3; Delay1KTCYx(DELAYEF);
#define G3 PORTD = 0x40; DISP3; Delay1KTCYx(DELAYEF);
#define A4 PORTD = 0x01; DISP4; Delay1KTCYx(DELAYEF);
#define B4 PORTD = 0x02; DISP4; Delay1KTCYx(DELAYEF);
#define C4 PORTD = 0x04; DISP4; Delay1KTCYx(DELAYEF);
#define D4 PORTD = 0x08; DISP4; Delay1KTCYx(DELAYEF);
#define E4 PORTD = 0x10; DISP4; Delay1KTCYx(DELAYEF);
#define F4 PORTD = 0x20; DISP4; Delay1KTCYx(DELAYEF);
#define G4 PORTD = 0x40; DISP4; Delay1KTCYx(DELAYEF);
// defines alphabet letters based in the 7 segment display
#define LA 0x77
#define LB 0x7c
#define LC 0x39
#define LD 0x5e
#define LE 0x79
#define LF 0x71
#define LG 0x6f
#define LH 0x76
#define LI 0x19
#define LJ 0x1e
#define LK 0x7a
#define LL 0x38
#define LM 0x37
#define LN 0x54
#define LO 0x3f
#define LP 0x73
#define LQ 0x67
#define LR 0x50
#define LS 0x6d
#define LT 0x78
#define LU 0x1c
#define LV 0x3e
#define LW 0x1d
#define LX 0x70
#define LY 0x6e
#define LZ 0x29
#define LSP 0x00
int cont = 0, i = 0, j = 0, k = 0, controle = 0, control_efeito = 0, c = 0;
void decode ( char l ) {
switch ( l ) {
case 'A':
PORTD = LA;
break;
case 'B':
PORTD = LB;
break;
case 'C':
PORTD = LC;
break;
case 'D':
PORTD = LD;
break;
case 'E':
PORTD = LE;
break;
case 'F':
PORTD = LF;
break;
case 'G':
PORTD = LG;
break;
case 'H':
PORTD = LH;
break;
case 'I':
PORTD = LI;
break;
case 'J':
PORTD = LJ;
break;
case 'K':
PORTD = LK;
break;
case 'L':
PORTD = LL;
break;
case 'M':
PORTD = LM;
break;
case 'N':
PORTD = LN;
break;
case 'O':
PORTD = LO;
break;
case 'P':
PORTD = LP;
break;
case 'Q':
PORTD = LQ;
break;
case 'R':
PORTD = LR;
break;
case 'S':
PORTD = LS;
break;
case 'T':
PORTD = LT;
break;
case 'U':
PORTD = LU;
break;
case 'V':
PORTD = LV;
break;
case 'W':
PORTD = LW;
break;
case 'X':
PORTD = LX;
break;
case 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AM TEIXEIRA DE VASCONCELOS ";
INTCON2bits.RBPU = 0;
ADCON1 = 0x0F;
// display 8 bit pins in PORTD
TRISD = 0x00;
// display activation bit's half in PORTA and half in PORTE
TRISA = 0x00;
TRISE = 0x00;
// button for inverting the direction of the letters passing
// through the 4 displays is detected by PORTB
TRISB = 0xFF;
DISPON;
while ( 1 ) {
if (!PORTBbits.RB0) {
controle = 0;
c = 1;
}
if (!PORTBbits.RB1) {
controle = 1;
c = 1;
}
if ( c ) {
for ( k = 0; k < REP * 2; k++ ) {
for ( j = 0; j < 4; j ++ ) {
cont = ( cont + 1 ) % 4;
if ( cont == 0 ){
DISP1
decode ( nome[ i ] );
} else if ( cont == 1 ) {
DISP2
decode ( nome[ ( i + 1 ) % MAX ] );
} else if ( cont == 2 ) {
DISP3
decode ( nome[ ( i + 2 ) % MAX ] );
} else if ( cont == 3 ) {
DISP4
decode ( nome[ ( i + 3 ) % MAX ] );
}
Delay100TCYx(DELAY);
}
}
c = 0;
}
for ( k = 0; k < REP; k++ ) {
for ( j = 0; j < 4; j ++ ) {
cont = ( cont + 1 ) % 4;
if ( cont == 0 ){
DISP1
decode ( nome[ i ] );
} else if ( cont == 1 ) {
DISP2
decode ( nome[ ( i + 1 ) % MAX ] );
} else if ( cont == 2 ) {
DISP3
decode ( nome[ ( i + 2 ) % MAX ] );
} else if ( cont == 3 ) {
DISP4
decode ( nome[ ( i + 3 ) % MAX ] );
}
Delay100TCYx(DELAY);
}
}
}
if ( !controle ) {
i = ( i + 1 ) % MAX;
} else {
i = ( i + ( MAX - 1 ) ) % MAX;
}
}