-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFingerPrint.c
More file actions
141 lines (127 loc) · 10 KB
/
FingerPrint.c
File metadata and controls
141 lines (127 loc) · 10 KB
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
#include "built_in.h"
// Lcd pinout settings
sbit LCD_RS at PORTA0_bit;
sbit LCD_EN at PORTA1_bit;
sbit LCD_D7 at PORTA5_bit;
sbit LCD_D6 at PORTA4_bit;
sbit LCD_D5 at PORTA3_bit;
sbit LCD_D4 at PORTA2_bit;
// Pin direction
sbit LCD_RS_Direction at DDA0_bit;
sbit LCD_EN_Direction at DDA1_bit;
sbit LCD_D7_Direction at DDA5_bit;
sbit LCD_D6_Direction at DDA4_bit;
sbit LCD_D5_Direction at DDA3_bit;
sbit LCD_D4_Direction at DDA2_bit;
char i, RD, Send[15];
int FP_Counter;
char txt[6];
void Command() {
Send[0]=0x4D;
Send[1]=0x58;
Send[2]=0x10;
for(i= 0;i<3;i++){
UART1_Write(Send[i]);
}
}
void Add_FP() {
Send[3]=0x03;
Send[4]=0x40;
Send[5]=0x00;
Send[6]=0x00;
Send[7]=0xF8;
for(i=3;i<8;i++){
UART1_Write(Send[i]);
}
}
void Del_FP() {
Send[3]=0x03;
Send[4]=0x42;
Send[5]=0x00;
Send[6]=0x00;
Send[7]=0xFA;
for(i=3;i<8;i++){
UART1_Write(Send[i]);
}
}
void Response() {
//ByteToStr(Send[4], txt);
//Lcd_Out(2,7, txt);
switch (Send[4]) {
case 0x40:
switch (RD) {
case 0xD7:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,2, ">...FINGER...<");Lcd_Out(2,6, txt);break;
case 0x48:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,2, "ADD SUCCESSFUL");Lcd_Out(2,6, txt);break;
case 0x4C:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,2, "PARAMETER ERR.");Lcd_Out(2,6, txt);break;
case 0x4B:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,2, "PROCESS FAILED");Lcd_Out(2,6, txt);break;
case 0x4A:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,5, "TIME OUT");break;
}
break;
case 0x42:
switch (RD) {
case 0xD7:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,5, "DELETION");break;
case 0x4A:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,4, "FP DELETED");Lcd_Out(2,6, txt);break;
case 0x4E:Lcd_Cmd(_LCD_CLEAR);Lcd_Out(1,2, "PARAMETER ERR.");Lcd_Out(2,6, txt);break;
}
break;
}
}
void main() {
FP_Counter=0;
i=0;
DDRB = 0x00;
PORTB = 0xFF;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 2, "FP SENSOR CTRL");
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
UART1_Init(57600); // Initialize UART module at 9600 bps
Delay_ms(800); // Wait for UART module to stabilize
while(1) {
switch (PINB) {
case 0xFE:
Command();
Add_FP();
break;
case 0xFD:
Command();
Del_FP();
break;
case 0xFB:
Command();
Del_FP();
break;
case 0xF7:
Command();
Del_FP();
break;
case 0xEF:
FP_Counter--;
if(FP_Counter<0) FP_Counter=0;
Send[5] = Hi(FP_Counter);
Send[6] = Lo(FP_Counter);
WordToStrWithZeros(FP_Counter, txt);
Lcd_Out(2,6, txt);
delay_ms(100);
break;
case 0xDF:
FP_Counter++;
if(FP_Counter>768) FP_Counter=768;
Send[5] = Hi(FP_Counter);
Send[6] = Lo(FP_Counter);
WordToStrWithZeros(FP_Counter, txt);
Lcd_Out(2,6, txt);
delay_ms(100);
break;
}
if(UART1_Data_Ready()) {
RD = UART1_Read();
//ByteToStr(RD, txt);
//Lcd_Out(2,1, txt);
Response();
}
Delay_ms(100);
}
}