-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersion3_1.c
614 lines (527 loc) · 11.2 KB
/
Version3_1.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
//LCD Connections
#define LCD_RS PORTA.B2 // RS
#define LCD_EN PORTD.B6 //Enable
#define LCD_D0 PORTC.B0 //Data Bit 0
#define LCD_D1 PORTC.B1 //Data Bit 1
#define LCD_D2 PORTC.B2 //Data Bit 2
#define LCD_D3 PORTC.B3 //Data Bit 3
#define LCD_D4 PORTC.B4 //Data Bit 4
#define LCD_D5 PORTC.B5 //Data Bit 5
#define LCD_D6 PORTC.B6 //Data Bit 6
#define LCD_D7 PORTC.B7 //Data Bit 7
char disp2_12='0';
unsigned short int count=0,ifFaculty=0,flag=0,RollNumber=0;
//char message[]="Show Card";
char RFID_No[13];
char rfid_T[]="120088F349";
char T_id[]="EMP001";
char rfid_S1[]="290091318C";
char rfid_S2[]="290091114B";
char rfid_S3[]="2900911BE7";
char rfid_S4[]="2900913990";
char date[9],C_No[2],Sem_No[2];
char keypadPort at PORTB;
char keypadPort_Direction at DDRB;
//unsigned short kp;
void EEPROM1_write(unsigned int uiAddress,unsigned char Rno)
{
EEARH=0x00;
EEARL=uiAddress;
EEDR=Rno;
EECR.B2=1;
EECR.B1=1;
while(EECR&0x02);
delay_ms(100);
}
void LCD_data(unsigned char Data)
{
/*
PORTC=Data&0xF0; // Send Higher nibble (D7-D4)
LCD_RS=1; // Register Select =1 (for data select register)
LCD_EN=1; //Enable=1 for H to L pulse
delay_us(5);
LCD_EN=0;
PORTC=((Data<<4)&0xF0); // Send Lower nibble (D3-D0)
LCD_EN=1; //Enable=1 for H to L pulse
delay_us(5);
LCD_EN=0;
delay_us(100);
*/
PORTC=Data;
LCD_EN=1;
delay_us(5);
LCD_EN=0;
delay_us(100);
}
//LCD Print
void LCD_Print(char * str)
{
unsigned char i=0;
// Till NULL charecter is reached, take each character
while(*(str+i)!=0)
{
LCD_data(*(str+i)); // Data sent to LCD data register
i++;
delay_ms(50); //checked
}
}
//LCD Command
void lcdcommand(unsigned char command)
{
/*
PORTC=command&0xF0; // Send Higher nibble (D7-D4)
LCD_RS=0; // Register Select =0 (for Command register)
LCD_EN=1; //Enable=1 for H to L pulse
delay_us(5);
LCD_EN=0;
delay_us(100);
PORTC=((command<<4)&0xF0); // Send Lower nibble (D3-D0)
LCD_EN=1; //Enable=1 for H to L pulse
delay_us(5);
LCD_EN=0;
delay_us(40);
*/
PORTC=command;
LCD_RS=0; // Register Select =0 (for Command register)
LCD_EN=1; //Enable=1 for H to L pulse
delay_us(5);
LCD_EN=0;
delay_us(100);
}
// Cursor Posotion
void Cursor_Position(unsigned short int x,unsigned short int y)
{
unsigned char firstcharadd[] ={0x80,0xC0,0x90,0xD0}; // First line address 0X80, Second line address 0XC0, Third line address 0X90 & 4th line add D0
lcdcommand((firstcharadd[x-1]+y-1));
}
void clear()
{
lcdcommand(0x01);
delay_ms(2);
}
//LCD Iniatialize
void LCD_Initialize()
{
LCD_EN=0;
/*
lcdCommand(0x33); // Initialize LCD for 4 bit mode
lcdCommand(0x32); // Initialize LCD for 4 bit mode
lcdCommand(0x28); // Initialize LCD for 5X7 matrix mode
*/
lcdCommand(0x38); //Function Set: 8-bit, 2 Line, 5x7 Dots 0x38 56
lcdCommand(0x0E); //Display on,cursor blinking
clear();
lcdCommand(0x06); //Shift cursor to right
//lcdCommand(0x80);
//Cursor_position(1,3);
}
unsigned char EEPROM1_read(unsigned int uiAddress)
{
EEARH=0x00;
/* Wait for completion of previous write */
while(EECR & (1<<EEWE));
/* Set up address register */
EEARL = uiAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
void usart_read_initialize()
{
UCSRB=0x10; // Rx Enable
UCSRC=0x86; // Data Size : 8-bit, Stop Bit:1,No parity
UBRRL=0x33; // X= (Fosc/(16(Desired Baud Rate)))-1
// = (8*10^6/(16 *9600))-1
// = 52.08-1
// = 51 (Dec)
//Here, URSEl=0, so Fosc is divided by 16 if it was 1 Fosc would
//Have been diveded by 8
}
void usart_write_initialize()
{
UCSRB=0x08; //Tx Enable
UCSRC=0x86; // Data Size : 8-bit, Stop Bit:1,No parity
UBRRL=0x33; // X = (Fosc/(16(Desired Baud Rate)))-1
// = (8*10^6/(16 *9600))-1
// = 52.08-1
// = 51 (Dec)
//Here, URSEl=0, so Fosc is divided by 16 if it was 1 //Fosc would Have been divided by 8
}
void usart_send(unsigned char ch)
{
while(UCSRA.B5==0); // Wait till UDR is empty
UDR=ch; //Write the value to be Tx
}
int checkIfFaculty()
{
unsigned short int i = 0;
for(i=0;i<10;i++)
{
if(RFID_No[i]!=rfid_T[i])
return 0;
}
return 1;
}
int RFID_RollNumber_Mapping()
{
unsigned short int i = 0,flag=0;
for(i=0;i<10;i++)
{
if(RFID_No[i]!=rfid_S1[i])
{
i=0;
flag=1;
break;
}
}
if(flag!=1)
return 1;
else
flag=0;
for(;i<10;i++)
{
if(RFID_No[i]!=rfid_S2[i])
{
i=0;
flag=1;
break;
}
}
if(flag!=1)
return 2;
else
flag=0;
for(;i<10;i++)
{
if(RFID_No[i]!=rfid_S3[i])
{
i=0;
flag=1;
break;
}
}
if(flag!=1)
return 3;
else
flag=0;
for(;i<10;i++)
{
if(RFID_No[i]!=rfid_S4[i])
{
i=0;
flag=1;
return 0;
}
}
if(flag!=1)
return 4;
else
return 0;
}
int checkValidInput()
{
unsigned short int i = 0;
for(; i<12; i++)
RFID_No[i] = RFID_No[i]>64 ? RFID_No[i]-55 : RFID_No[i]-48;
if( ( ( (RFID_No[0] ^ RFID_No[2]) ^ RFID_No[4] ) ^ RFID_No[6] ) ^ RFID_No[8] == RFID_No[10]&& ( ( (RFID_No[1] ^ RFID_No[3]) ^ RFID_No[5] ) ^ RFID_No[7] ) ^ RFID_No[9] == RFID_No[11])
{
for(i = 0; i<12; i++)
RFID_No[i] = RFID_No[i]>9 ? RFID_No[i]+55 : RFID_No[i]+48;
return 1;
}
return 0;
}
int CheckAddress()
{
char mem;
mem=EEPROM1_read(24);
if(mem!='E')
return 0;
else
{
mem=EEPROM1_read(54);
if(mem!='E')
return 30;
else
{
mem=EEPROM1_read(84);
if(mem!='E')
return 60;
else
{
mem=EEPROM1_read(114);
if(mem!='E')
return 90;
else
{
mem=EEPROM1_read(144);
if(mem!='E')
return 120;
}
}
}
}
}
char Press_Value(char num)
{
switch (num)
{
//case 10: kp = 42; break; // '*' // Uncomment this block for keypad4x3
//case 11: kp = 48; break; // '0'
//case 12: kp = 35; break; // '#'
//default: kp += 48;
case 1: num = 49; return num; // 1 // Uncomment this block for keypad4x4
case 2: num = 50; return num; // 2
case 3: num = 51; return num; // 3
case 4: num = 65; return num; // A
case 5: num = 52; return num; // 4
case 6: num = 53; return num; // 5
case 7: num = 54; return num; // 6
case 8: num = 66; return num; // B
case 9: num = 55; return num; // 7
case 10: num = 56; return num; // 8
case 11: num = 57; return num; // 9
case 12: num = 67; return num; // C
case 13: num = 42; return num; // *
case 14: num = 48; return num; // 0
case 15: num = 35; return num; // #
case 16: num = 68; return num; // D
}
}
void main()
{
//DDRD.B0=;
//DDRD.B1=1;
//Set-up PORTS for LCD
DDRC=0xFF; // For D3-D0
DDRA.B2=1; //For RS
DDRD.B6=1; //For Enable
char kp;
unsigned short int i,memoryCount=0,mem_offset,loop_help;
RFID_No[12] = '\0';
date[2]=date[5]='/';
date[8]=C_No[1]=Sem_No[1]='\0';
usart_read_initialize();
LCD_Initialize(); //Initialize
Cursor_Position(2,1);
LCD_Print("Booting up...");
Delay_ms(2000);
clear();
Cursor_Position(2,1);
LCD_Print("Welcome");
Delay_ms(1000);
clear();
mem_offset=CheckAddress();
Cursor_Position(3,1);
LCD_Print("Enter Date:-");
Cursor_Position(4,1);
LCD_Print("_ _/_ _/_ _");
Delay_ms(2000);
Cursor_Position(4,1);
do{
kp = Keypad_Key_Click();
}while(!kp);
date[0]=Press_Value(kp);
Cursor_Position(4,3);
do{
kp = Keypad_Key_Click();
}while(!kp);
date[1]=Press_Value(kp);
Cursor_Position(4,5);
do
kp = Keypad_Key_Click();
while(!kp);
date[3]=Press_Value(kp);
Cursor_Position(4,7);
do{
kp = Keypad_Key_Click();
}while(!kp);
date[4]=Press_Value(kp);
Cursor_Position(4,9);
do{
kp = Keypad_Key_Click();
}while(!kp);
date[6]=Press_Value(kp);
Cursor_Position(4,11);
do{
kp = Keypad_Key_Click();
}while(!kp);
date[7]=Press_Value(kp);
clear();
LCD_Print(date);
Delay_ms(2000);
memoryCount=mem_offset;
loop_help=memoryCount+9;
for(;memoryCount<loop_help;memoryCount++)
EEPROM1_write(memoryCount,date[memoryCount]);
clear();
loop_help=memoryCount+9;
for(memoryCount=0;memoryCount<loop_help;memoryCount++)
date[memoryCount]=EEPROM1_read(memoryCount);
LCD_Print(date);
clear();
Delay_ms(2000);
LCD_Print("Date Entered");
Delay_ms(500);
LCD_Print("Enter Class No.");
do{
kp = Keypad_Key_Click();
}while(!kp);
C_No[0]=Press_Value(kp);
loop_help=memoryCount+2;
for(;memoryCount<loop_help;memoryCount++)
EEPROM1_write(memoryCount,C_No[memoryCount-loop_help]);
do{
Cursor_Position(1,1);
LCD_Print("Enter Faculty ID");
Cursor_Position(4,1);
LCD_Print("options");
Delay_ms(500);
for(i=0;i<12;i++)
{
while(UCSRA.B7==0); // Wait till Data is received
RFID_No[i]=UDR;
}
clear();
if(checkValidInput() == 0)
{
Cursor_position(1,1);
LCD_Print("Cannot detect");
Cursor_position(2,1);
LCD_Print("Show again...");
Delay_ms(3000);
clear();
continue;
}
ifFaculty=checkIfFaculty();
if(ifFaculty==1)
{
Cursor_Position(1,1);
LCD_Print("Welcome");
Cursor_Position(2,1);
LCD_Print("Prof. Nishit");
Cursor_Position(3,5);
LCD_Print("Pandya");
Delay_ms(2000);
Cursor_position(1,1);
clear();
}
else
{
clear();
Delay_ms(500);
continue;
}
}while(ifFaculty==0);
while(1)
{
clear();
Cursor_Position(1,1);
LCD_Print("Student :-");
Cursor_Position(2,1);
LCD_Print("Show Card");
Delay_ms(50);
for(i=0;i<12;i++)
{
while(UCSRA.B7==0); // Wait till Data is received
RFID_No[i]=UDR;
}
clear();
if(checkValidInput() == 0)
{
Cursor_position(1,1);
LCD_Print("Cannot detect");
Cursor_position(2,1);
LCD_Print("Show again...");
Delay_ms(3000);
continue;
}
RollNumber=RFID_RollNumber_Mapping();
if(RollNumber==0)
{
LCD_Print("Invalid Student");
}
else if (RollNumber==1)
{
EEPROM1_write(memoryCount++,'1');
clear();
Cursor_Position(2,1);
LCD_Print("Roll Number 1");
Cursor_Position(3,1);
LCD_Print("Present");
Delay_ms(2000);
clear();
}
else if (RollNumber==2)
{
EEPROM1_write(memoryCount++,'1');
clear();
Cursor_Position(2,1);
LCD_Print("Roll Number 2");
Cursor_Position(3,1);
LCD_Print("Present");
Delay_ms(2000);
clear();
}
else if (RollNumber==3)
{
EEPROM1_write(memoryCount++,'1');
clear();
Cursor_Position(2,1);
LCD_Print("Roll Number 3");
Cursor_Position(3,1);
LCD_Print("Present");
Delay_ms(2000);
clear();
}
else if (RollNumber==4)
{
EEPROM1_write(memoryCount++,'1');
clear();
Cursor_Position(2,1);
LCD_Print("Roll Number 4");
Cursor_Position(3,1);
LCD_Print("Present");
Delay_ms(2000);
clear();
}
ifFaculty=checkIfFaculty();
if(ifFaculty==1)
{
Cursor_position(1,1);
LCD_Print("Attendance done");
Cursor_Position(2,1);
LCD_Print("Thank you!");
Delay_ms(2000);
clear();
Cursor_Position(3,1);
//LCD_Print("Thank You!");
Delay_ms(3000);
break;
}
}
LCD_Print("Enter Sem No.");
do
kp = Keypad_Key_Click();
while(!kp);
S_No[0]=Press_Value(kp);
memoryCount+=5;
loop_help=memoryCount+4;
for(;memoryCount<loop_help;memoryCount++)
EEPROM1_write(memoryCount,C_No[memoryCount-loop_help]);
usart_write_initialize();
for(i=1;i<=4;i++)
{
RollNumber=EEPROM1_read(i);
usart_send(RollNumber); //Send data
if (i>=4) // Till string Length
{
i=0;
delay_ms(2000);
LCD_Print("Data Read");
Delay_ms(2000);
break;
}
}
}