-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_proje.c
463 lines (338 loc) · 11.4 KB
/
temp_proje.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/*
Mechatronics Engineering Microprocessors Final Project
Slide Show Using GLCD
Author : Seyit Kaan Karaalioglu
ID : 140223014
Date: 29/12/2020
*/
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif
// fast_io initializations
#use fast_io(A)
//#use fast_io(b)
#use fast_io(C)
//#use fast_io(d)
#use fast_io(E)
//after setting up the time, we start displaying by choosing start button
#define ayar_buton pin_e0
#define onay_buton pin_a1
//7 segment define statements
#define display_1 pin_e1
#define display_2 pin_e2
// GLCD define and include statements
#define GLCD_CS1 pin_b0 // chip select 1
#define GLCD_CS2 pin_b1 // chip select 2
#define GLCD_DI pin_b2 // Data or instruction input
#define GLCD_RW pin_b3 // Read and Write pin
#define GLCD_E pin_b4 // GLCD enable
#define GLCD_RST pin_b5 // GLCD reset
#include <GLCD.c>
//EEPROM define and include statements
#define EEPROM_SDA pin_b6
#define EEPROM_SCL pin_b7
#include <24512.c>
#define INTS_PER_SECOND 152 // (20000000/(4*128*256))
#define PICTURE_COUNT 4 // number of pictures to show up
int numbers[16] ={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7C, 0x07, 0x7F, 0x6F, 0x77 , 0x7C, 0x39, 0x5E, 0x79, 0x71};
// numbers as hex codes for two digit seven segments
int16 resim, blinkcounter;
unsigned char mode, cmode, setm, sayi, dig[2];
char text1[22];
int1 blink, direct;
int8 seg;
int8 timeout, time[PICTURE_COUNT]; // A running seconds counter
int8 int_count; // Number of interrupts left before a second has elapsed
int1 on_down, on_down_onay; // on_down and on_down_onay are defined as booleans
/*
void sevenseg(void)
{
if (blink)
{
output_c( numbers[ dig[0] ] );
output_low(display_2);
Delay_ms(2);
output_high(display_2);
output_c( numbers [dig[1]] );
output_low(display_1);
Delay_ms(2);
output_high(display_1);
}
}
*/
#int_rtcc
void clock_isr()
{
//------------------------------------------
if (blinkcounter>5)
{
blinkcounter=0;
blink=!blink; // blink happens
}
else blinkcounter++;
//-------------------------------------------
output_high(display_1);
output_high(display_2);
if ((blink)||(direct))
{
if (seg==0)
{
seg=1;
output_low(display_1);
}
else
{
seg=0;
output_low(display_2);
}
output_c(numbers[dig[seg]]);
}
//--------------------------------------------
if(--int_count==0)
{ // per second.
if (timeout>0) timeout--;
int_count=INTS_PER_SECOND;
}
}
void Picture_load()
{
int16 i,j,x,y,t,start_adr;
unsigned char a;
x=127;
y=0;
t=0;
start_adr = 61 + (resim*1024)+1024;
for(i = 0 ; i < 1024 ; i++)
{
a = read_ext_eeprom(start_adr);
t=1;
for(j = 0; j < 8; j++)
{
glcd_pixel( x, y, ( (a & t)==0) );
if (x==0)
{
x=127;
y++;
}
else x--;
t=t*2;
}
start_adr--;
}
}
void main()
{
int j;
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED); // timer1 disabled
setup_timer_2(T2_DISABLED,0,1); // timer 2 disabled
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
set_tris_a(0x03); // 0b0000 0011 ra1 and ra0 are inputs
set_tris_b(0xC0); //rb6 and rb7 are inputs
set_tris_c(0x00); //all c pins are output
set_tris_d(0x00); //all d pins are output
set_tris_e(0x01); //0b 0000 0001
output_a(0x00);
output_b(0x00);
output_d(0x00);
output_e(0x06); //0b 0000 0110
output_low(display_2);
output_low(display_1);
int_count=INTS_PER_SECOND;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_adc_ports(AN0); // ANO analog
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
glcd_init(on);
//glcd_rect(10, 10, 20, 20, 1, 1);
init_ext_eeprom();
/*
for(j = 0; j < 8; j++)
{
a = read_ext_eeprom(j);
sprintf(text1,"%02X ",a);
glcd_text57(0, j*8, &text1[0], 1, 1);
}
*/
sprintf(text1,"Mikroislemciler Proje");
glcd_text57(0, 0, &text1[0], 1, 1);
sprintf(text1,"140223014");
glcd_text57(34,10,&text1[0], 1, 1);
sprintf(text1,"Seyit Kaan");
glcd_text57(32, 20, &text1[0], 1, 1);
sprintf(text1,"Karaalioglu");
glcd_text57(28, 30, &text1[0], 1, 1);
sprintf(text1, "click");
glcd_text57(40, 45, &text1[0], 1, 1);
sprintf(text1, "ayar buton");
glcd_text57(30, 55, &text1[0], 1, 1);
Delay_ms(1500);
//-----------------------------
// load values from internal eeprom
cmode = read_eeprom( 0 );
resim = read_eeprom( 1 );
for(j=0; j<PICTURE_COUNT; ++j)
{
time[j] = read_eeprom( 2+ j );
}
// defaults
time[0]= 9;
time[1]= 2;
time[2]= 11;
time[3]= 5;
cmode=2; //
resim=0; // we define resim variable for the logos
//-----------------------
mode = 1;
direct=true;
blinkcounter=0;
sayi=resim+1;
dig[0]=0;
dig[1]=0;
timeout=0;
on_down=false;
//setup_wdt(WDT_2304MS);
while(true)
{
if(input(onay_buton))
{
if (mode!=0)
{
if (!on_down_onay)
{
on_down_onay=true;
if (cmode<2) cmode++; else cmode=0;
glcd_rect(0, 0, 127, 15, 1, 1);
switch (cmode)
{
case 0: sprintf(text1,"1..n"); break;
case 1: sprintf(text1,"n..1"); break;
case 2: sprintf(text1,"1..n..1"); break;
}
glcd_text57(0, 0, &text1[0], 1, 0);
}
}
}
else on_down_onay=false;
if(input(ayar_buton) )
{
if (!on_down)
{
on_down=true;
iF(mode!=0)
{
mode = 0;
resim=0;
// Picture_load();
}
else
{
if (mode==0)
{
if (resim< (PICTURE_COUNT-1))
{
resim++;
}
else resim=0;
// Picture_load();
}
}
}
}
else on_down=false;
switch (mode)
{
case 0:
direct=false;
sayi = read_adc()/16;
if (sayi<16)
{
dig[0]=sayi;
time[resim]= sayi;
}
dig[1]=resim+1;
if(input(onay_buton))
{
for(j=0; j<PICTURE_COUNT; ++j)
{
write_eeprom( 2+ j,time[j] );
}
mode = 1;
}
/*
dig[0]=sayi;
if (sayi==15)
sayi=0; else sayi++;
*/
break;
case 1:
direct=true;
Picture_load();
timeout = time[resim];
mode=2;
dig[1]=resim;
dig[0]=timeout;
break;
//--------------------------------
case 2:
direct=true;
if (timeout==0)
{
//-------------------------------------------
if (cmode==0)
{
//0 to n;
if (resim==(PICTURE_COUNT-1))
{
resim=0;
}
else resim++;
}
else if (cmode==1)
{
//n to 0
if (resim==0)
{
resim=PICTURE_COUNT-1;
}
else resim--;
}
else
{
//0 to n to 0
if (setm==0)
{
if (resim==(PICTURE_COUNT-1))
{
resim=PICTURE_COUNT-2;
setm=1;
}
else resim++;
}
else
{
if (resim==0)
{
resim=1;
setm=0;
}
else resim--;
}
}
write_eeprom( 2, resim );
//-------------------------------------------
mode=1;
sayi = resim+1;
}
dig[1]=resim;
dig[0]=timeout;
break;
}
restart_wdt();
}
}