一、目的

“理论到实践”

大二的时候学完单片机就想着搞点什么小东西,经常出现天天忘记带宿舍钥匙,稍微看了看网上指纹锁的视频就想着自己也搞一搞。
光学指纹的话玻璃有时候会积灰灵敏度降低,所以我就选用了晟元的电容式AS608指纹模块。

电容式指纹锁即指纹识别模块采用电容式传感器的智能锁。电容式传感器属于半导体传感器的一种,应用比较广泛的是半导体电容式指纹传感器。
电容传感器采用自动控制技术调节指纹图像像素以及指纹局部范围敏感度,在不同环境下结合反馈信息生成高质量图像。由于提供了局部调整能力,即使手指压得比较轻的区域也能被监测到,并在捕捉瞬间为这些像素提高灵敏度,生成高质量指纹图像。
电容指纹传感器优点为图像质量较好、一般无畸变、尺寸较小、易集成于各种设备。其发出的电子信号将穿过手指的表面和死性皮肤层,达到手指皮肤的活体层(真皮层),直接读取指纹图案,从而大大提高了系统的安全性。所以,即使很多用户在季节变换的过程中会手指会出现死皮的现象也不用过于担心,电容式指纹传感器能够很好的识别你的指纹。

二、材料

1
2
3
4
5
6
7
- STC89C52RC
- 广航51单片机开发板
- esp8266
- OLED0.96显示屏
- 晟元电容式AS608指纹模块
- MG996R舵机
- 12V电源模块(其实不用,单片机引出的5V电源就够了)

三、用法与演示

3.1 预备工作

不用预备,擦擦手汗即可。(D1灯为开门标志位)

3.2 切换模式

(1)识别/添加模式切换
长按后松开最左边(单片机正放)的独立按键可切换模式
识别/添加模式灯分别为D2,D3
切换
(2)访客模式切换
长按后松开最右边(单片机正放)的独立按键可切换访客模式,
D5灯为访客模式标识,灯亮或者屏幕显示f ok!代表开启
访客开启
访客开启

3.3 添加用户

D3亮起时为添加模式,此时屏幕会闪烁(绕过了识别模式,执行速度变快)
添加用户
屏幕闪烁后按下第二个按键
添加用户
按下后屏幕会显示请放手指
放
此时放上手指,轻轻按压直到模块绿灯即可
有异常会提示:
添加

3.4 重置删除所有指纹

恢复出厂设置(清空所有用户)
长按第三个按键即可(代码中屏蔽了)

3.5使用指纹开启门锁

录入指纹后把手放上去就行,指纹模块绿灯后听到舵机转后推门
指纹开启门锁

3.6访客模式使用门铃开启门锁

在开启访客模式后按黑色访客按钮,听到蜂鸣器响后推门
访客开启门锁

3.7esp8266 wifi开启门锁/访客模式

app界面:
esp开启门锁

在app界面点击对应按钮听到蜂鸣器响后推门
esp开启门锁

四、整体展示

展示
展示
展示
展示
展示

附录

stc89c52rc代码

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
#include <REGX52.H>
#include "oled.h"
#include "delay.h"
#include "pwr.h"
#include "as608.h"


void main()
{
Time0_Init();
Delay1ms(2);//等待单片机复位
SCON=0x50; //UART方式1:8位UART; REN=1:允许接收
PCON=0x80; //SMOD=0:波特率不加倍
TMOD=0x21; //T1方式2,用于UART波特率
TH1=0xFF;
TL1=0xFF; //UART波特率设置:57600
ET1=0;
TR1=1;
TR0=1;// 开定时器0
EX0=1; //开外部中断0
IT0=1;
EA=1;
OLED_Init();Delay1ms(3);
OLED_ShowCHinese(0,0,17);
OLED_ShowCHinese(16,0,18);
OLED_ShowCHinese(32,0,19);
OLED_ShowCHinese(48,0,20);
OLED_ShowCHinese(80,0,15);
OLED_ShowCHinese(96,0,21);
OLED_ShowCHinese(112,0,22);
OLED_ShowString(32,2," by JAS");
Delay1ms(50);
while(1) //主循环
{
dokey();
modec();
}
}

oled.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
#include "oled.h"
#include "oledfont.h"
#include "intrins.h"
#include "delay.h"
#define u16 unsigned int
#define u8 unsigned char
#define u32 unsigned long

//OLED的显存
//存放格式如下.
//[0]0 1 2 3 ... 127
//[1]0 1 2 3 ... 127
//[2]0 1 2 3 ... 127
//[3]0 1 2 3 ... 127
/**********************************************
//IIC Start
**********************************************/
void IIC_Start()
{
OLED_SCLK_Set();
OLED_SDIN_Set();
OLED_SDIN_Clr();
OLED_SCLK_Clr();
}

/**********************************************
//IIC Stop
**********************************************/
void IIC_Stop()
{
OLED_SCLK_Set() ;
OLED_SDIN_Clr();
OLED_SDIN_Set();
}
void IIC_Wait_Ack()
{
OLED_SCLK_Set() ;
OLED_SCLK_Clr();
}
/**********************************************
// IIC Write byte
**********************************************/
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
unsigned char m,da;
da=IIC_Byte;
OLED_SCLK_Clr();
for(i=0;i<8;i++)
{
m=da;
m=m&0x80;
if(m==0x80)
{
OLED_SDIN_Set();
}
else
OLED_SDIN_Clr();
da=da<<1;
OLED_SCLK_Set();
OLED_SCLK_Clr();
}
}
/**********************************************
// IIC Write Command
**********************************************/
void Write_IIC_Command(unsigned char IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78); //Slave address,SA0=0
IIC_Wait_Ack();
Write_IIC_Byte(0x00); //write command
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Command);
IIC_Wait_Ack();
IIC_Stop();
}
/**********************************************
// IIC Write Data
**********************************************/
void Write_IIC_Data(unsigned char IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78); //D/C#=0; R/W#=0
IIC_Wait_Ack();
Write_IIC_Byte(0x40); //write data
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Data);
IIC_Wait_Ack();
IIC_Stop();
}
void OLED_WR_Byte(unsigned dat,unsigned cmd)
{
if(cmd)
{
Write_IIC_Data(dat);
}
else
{
Write_IIC_Command(dat);
}
}

//坐标设置
void OLED_Set_Pos(unsigned char x, unsigned char y)
{
OLED_WR_Byte(0xb0+y,OLED_CMD);
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
OLED_WR_Byte((x&0x0f),OLED_CMD);
}
//清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
void OLED_Clear(void)
{
u8 i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7)
OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址
OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址
for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
} //更新显示
}

//在指定位置显示一个字符,包括部分字符
//x:0~127
//y:0~63
//void OLED_ShowChar(u8 x,u8 y,u8 chr)
void OLED_ShowChar(u8 x,u8 y,u8 chr)
{
unsigned char c=0,i=0;
c=chr-' ';//得到偏移后的值
if(x>Max_Column-1){x=0;y=y+2;}
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
}
//显示一个字符号串
void OLED_ShowString(u8 x,u8 y,u8 *chr)
{
unsigned char j=0;
while (chr[j]!='\0')
{
OLED_ShowChar(x,y,chr[j]);
x+=8;
if(x>120){x=0;y+=2;}
j++;
}
}
void OLED_ShowPicture(u8 x0,u8 y0,u8 x1,u8 y1,u8 BMP[])
{
unsigned int i=0;
unsigned char x,y;
//if(y1%8==0) y=y1/8;
//else y=y1/8+1;
y1/=8;
for(y=y0;y<y1;y++)
{
OLED_Set_Pos(x0,y);
for(x=x0;x<x1;x++)
{
OLED_WR_Byte(BMP[i++],OLED_DATA);
}
}
}
//显示汉字
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{
u8 t,adder=0;
OLED_Set_Pos(x,y);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
adder+=1;
}
OLED_Set_Pos(x,y+1);
for(t=0;t<16;t++)
{
OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
adder+=1;
}
}
//初始化SSD1306
void OLED_Init(void)
{

OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0???? 0xa1??
OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0???? 0xc8??
OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
OLED_WR_Byte(0x00,OLED_CMD);//-not offset
OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
OLED_WR_Byte(0x12,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
OLED_WR_Byte(0x02,OLED_CMD);//
OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
OLED_Clear();
OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
}

oled.h

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
#ifndef __OLED_H
#define __OLED_H
#include <REGX52.H>
#include "delay.h"
#include "intrins.h"
#define u16 unsigned int
#define u8 unsigned char
#define u32 unsigned long
#define OLED_CMD 0 //写命令
#define OLED_DATA 1 //写数据
#define OLED_MODE 0

sbit OLED_SCL=P0^6;//时钟 D0(SCLK?
sbit OLED_SDIN=P0^7;//D1(MOSI) 数据

#define OLED_CS_Clr() OLED_CS=0
#define OLED_CS_Set() OLED_CS=1

#define OLED_RST_Clr() OLED_RST=0
#define OLED_RST_Set() OLED_RST=1

#define OLED_DC_Clr() OLED_DC=0
#define OLED_DC_Set() OLED_DC=1

#define OLED_SCLK_Clr() OLED_SCL=0
#define OLED_SCLK_Set() OLED_SCL=1

#define OLED_SDIN_Clr() OLED_SDIN=0
#define OLED_SDIN_Set() OLED_SDIN=1

//OLED模式设置
//0:4线串行模式
//1:并行8080模式

#define Max_Column 128
//-----------------OLED端口定义----------------

//OLED控制用函数
void OLED_WR_Byte(unsigned dat,unsigned cmd);

void OLED_Init(void);
void OLED_Clear(void);
void OLED_DrawPoint(u8 x,u8 y,u8 t);
void OLED_Fill(u8 x1,u8 y1,u8 x2,u8 y2,u8 dot);
void OLED_ShowChar(u8 x,u8 y,u8 chr);
void OLED_ShowString(u8 x,u8 y, u8 *p);
void OLED_ShowCHinese(u8 x,u8 y,u8 no);
void OLED_Set_Pos(u8 x, u8 y);
//void OLED_ShowBMP(u8 x, u8 y, u8 px, u8 py, u8 index, u8 mode);
//void OLED_Refresh_Gram();
void OLED_ShowPicture(u8 x0,u8 y0,u8 x1,u8 y1,u8 BMP[]);
void IIC_Start();
void IIC_Stop();
void Write_IIC_Command(u8 IIC_Command);
void Write_IIC_Data(u8 IIC_Data);
void Write_IIC_Byte(u8 IIC_Byte);
void IIC_Wait_Ack();

#endif

oledfont.h

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
#ifndef __OLEDFONT_H
#define __OLEDFONT_H
//常用ASCII表
//偏移量32
//ASCII字符集
//偏移量32
//大小:8x16
/****************************************8*16的点阵************************************/
unsigned char code F8X16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
unsigned char code Hzk[][25]={

//添(0) 加(1) 成(2) 功(3) 失(4) 败(5) 删(6) 除(7) 所(8) 有(9) 用(10) 户(11) 电(12) 量(13) 请(14) 放(15)
//手(16) 指纹(17) 号(18)

{0x10,0x60,0x02,0x8C,0x00,0x10,0x92,0x52,0x32,0x1E,0x32,0x52,0x92,0x12,0x10,0x00},
{0x04,0x04,0x7E,0x01,0x00,0x21,0x18,0x40,0x80,0x7F,0x08,0x30,0x04,0x09,0x31,0x00},/*"添",0*/

{0x10,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0xF8,0x08,0x08,0x08,0xF8,0x00,0x00},
{0x80,0x40,0x30,0x0F,0x40,0x80,0x7F,0x00,0x00,0x7F,0x20,0x20,0x20,0x7F,0x00,0x00},/*"加",1*/

{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x08,0x00},
{0x80,0x60,0x1F,0x00,0x10,0x20,0x1F,0x80,0x40,0x21,0x16,0x18,0x26,0x41,0xF8,0x00},/*"成",2*/

{0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00},
{0x10,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00},/*"功",3*/

{0x00,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00},
{0x81,0x81,0x41,0x21,0x11,0x0D,0x03,0x01,0x03,0x0D,0x11,0x21,0x41,0x81,0x81,0x00},/*"失",4*/

{0x00,0xFE,0x02,0xFA,0x02,0xFE,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00},
{0x80,0x47,0x30,0x0F,0x10,0x67,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00},/*"败",5*/

{0x80,0xFE,0x82,0x82,0xFE,0x80,0xFE,0x82,0x82,0xFE,0x80,0x00,0xF8,0x00,0xFF,0x00},
{0x40,0x3F,0x00,0x20,0xBF,0x40,0x3F,0x40,0x80,0x7F,0x00,0x00,0x4F,0x80,0x7F,0x00},/*"删",6*/

{0x00,0xFE,0x22,0x5A,0x86,0x20,0x10,0x28,0x24,0xE3,0x24,0x28,0x10,0x20,0x20,0x00},
{0x00,0xFF,0x04,0x08,0x27,0x11,0x0D,0x41,0x81,0x7F,0x01,0x05,0x09,0x31,0x00,0x00},/*"除",7*/

{0x00,0x00,0xFC,0x24,0x24,0x22,0xE3,0x02,0xFC,0x44,0x44,0x42,0xC3,0x42,0x40,0x00},
{0x40,0x30,0x0F,0x02,0x02,0x82,0x43,0x30,0x0F,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},/*"所",8*/

{0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00},
{0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00},/*"有",9*/

{0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00},
{0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},/*"用",10*/

{0x00,0x00,0x00,0xF8,0x08,0x08,0x09,0x0E,0x08,0x08,0x08,0x08,0xF8,0x00,0x00,0x00},
{0x00,0x80,0x60,0x1F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0x00,0x00,0x00},/*"户",11*/

{0x40,0x42,0xCC,0x00,0x00,0x44,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x44,0x40,0x00},
{0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00},/*"请",12*/

{0x08,0x08,0xF9,0x4A,0x48,0xC8,0x48,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00},
{0x40,0x30,0x0F,0x20,0x40,0x3F,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00},/*"放",13*/

{0x00,0x00,0x24,0x24,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x23,0x22,0x00,0x00,0x00},
{0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00},/*"手",14*/

{0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0x3F,0x48,0x48,0x44,0x44,0x44,0x42,0x70,0x00},
{0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00},/*"指",15*/

{0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00},
{0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00},/*"号",16*/

{0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00},
{0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00},/*"欢",17*/

{0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00},
{0x00,0x40,0x20,0x1F,0x20,0x40,0x4F,0x44,0x42,0x40,0x7F,0x42,0x44,0x43,0x40,0x00},/*"迎",18*/

{0x80,0x60,0xF8,0x07,0x04,0xE4,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0xE4,0x04,0x00},
{0x00,0x00,0xFF,0x00,0x80,0x81,0x45,0x29,0x11,0x2F,0x41,0x41,0x81,0x81,0x80,0x00},/*"使",19*/

{0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00},
{0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},/*"用",20*/

{0x20,0x30,0xAC,0x63,0x10,0x08,0x08,0xF8,0x09,0x0E,0x08,0xF8,0x08,0x08,0x00,0x00},
{0x22,0x67,0x22,0x12,0x92,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x80,0x00},/*"纹",21*/

{0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xE2,0x2C,0x20,0xBF,0x20,0x28,0xE6,0x00,0x00},
{0x01,0x01,0x01,0x7F,0x21,0x11,0x80,0x4F,0x20,0x10,0x0F,0x10,0x20,0x4F,0x80,0x00},/*"锁",22*/

{0x40,0x40,0x42,0xCC,0x00,0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00},
{0x00,0x00,0x00,0x3F,0x10,0x88,0x40,0x23,0x19,0x01,0x01,0x09,0x11,0x23,0xC0,0x00},/*"识",23*/

{0x00,0x3E,0x22,0xE2,0x22,0x22,0x22,0x3E,0x00,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00},
{0x81,0x41,0x31,0x0F,0x41,0x81,0x41,0x3F,0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00},/*"别",24*/

{0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00},
{0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00},/*"模",25*/

{0x10,0x10,0x90,0x90,0x90,0x90,0x90,0x10,0x10,0xFF,0x10,0x10,0x11,0x16,0x10,0x00},
{0x00,0x20,0x60,0x20,0x3F,0x10,0x10,0x10,0x00,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00},/*"式",26*/


};

#endif

delay.h

1
2
3
4
5
6
7
8
#ifndef	__DELAY_H
#define __DELAY_H

void delay_ms(unsigned int ms);
void Delay1mss(void); //@11.0592MHz
void Delay1ms(unsigned int c); //@11.0592MHz
#endif

delay.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
#include	"delay.h"
#include "intrins.h"
/*----------------------------
函数:1ms延时
----------------------------*/
void delay_ms(unsigned int ms)
{
while(ms--)
{
Delay1mss();
}
}

void Delay1mss(void) //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void Delay1ms(unsigned int c) //误差 0us
{
unsigned char a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}

pwr.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef __PWR_H__
#define __PWR_H__
#include <REGX52.H>
#define u8 unsigned char
#define u16 unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit pwm =P0^5 ; //PWM信号输出
sbit led=P1^7;
void delay(u16 i);
void Time0_Init();
void Door_Open();
void Door_Close();

#endif

pwr.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
#include "pwr.h"

u8 jd; //角度标识
u8 count1; //0.5ms次数标识

void delay(u16 i)//延时
{
u8 j,k;
for(j=i;j>0;j--)
for(k=114;k>0;k--);
}

void Time0_Init() //定时器初始化
{
TMOD = 0x01; //定时器0工作在方式1
IE = 0x82;
TH0 = 0xfe;
TL0 = 0x33; //11.0592MZ晶振,0.5ms
TR0=1; //定时器开始
dula=0;
wela=0;
jd=1;
count1=0;
}
void Door_Open() //定时器初始化
{
jd=5; //角度标识加1
count1=0; //按键按下 则20ms周期从新开始
led=0; //等待按键放开
delay(10);
}
void Door_Close()
{
jd=1; //角度标识减1
count1=0;
if(jd==0)
jd=1;
led=1; //已经是0度,则保持
}
void Time0_Int() interrupt 1 //中断程序
{
TH0 = 0xfe; //重新赋值
TL0 = 0x33;
if(count1<jd) //判断0.5ms次数是否小于角度标识
pwm=1; //确实小于,PWM输出高电平
else
pwm=0; //大于则输出低电平
count1=(count1+1); //0.5ms次数加1
count1=count1%40; //次数始终保持为40 即保持周期为20ms
}

as608.h

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
#ifndef __AS608_H
#define __AS608_H
#include <REGX52.H>

#include "as608.h"
#include "oled.h"
#include "pwr.h"
#include "delay.h"
#define u8 unsigned char

sbit D3= P1^1;
sbit D4= P1^2;
sbit fk= P1^4;
sbit wififkkey= P3^6;
sbit fkkey= P0^3;
sbit wifikey= P0^4;
sbit k3=P3^4;
sbit k4=P3^5;
sbit k5=P3^6;
sbit k6=P3^7;
sbit beep=P2^3;

#define FALSE 0
#define TURE 1
#define MAX_NUMBER 30
#define _Nop() _nop_()


void modec();
void dokey();

void TxdByte(u8 dat);
bit Command(u8 *p,u8 MaxTime);
bit VefPSW();
void Clear_All();
u8 ImgProcess(u8 BUFID);
bit Searchfinger();
u8 search();
bit savefingure(u8 ID);
u8 enroll();
void numshow(u8 num);
void modecheck();
void fangke();
#endif

as608.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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
#include "as608.h"
#include "oled.h"
#include "pwr.h"

u8 code MODE3[16] = "Connection OK";
u8 code MODE4[16] = "Connection Faild";
u8 code shibie1[16] = " OK";
u8 code shibie2[16] = "Faild";
u8 code BMP[]={
0xC0,0xC0,0xE0,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xFC,0xFC,0xFC,0xFC,0xFD,0xFD,0xFD,
0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xF9,0xFA,0xFB,0xFB,0xF3,0xF7,0xF3,
0xF4,0xE1,0xE6,0xE9,0xCF,0x9F,0x9E,0x8C,0x81,0x33,0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFE,0xFC,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x07,0x1F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0x6F,0xAF,0xC7,0xE7,0xF7,
0xF7,0xF7,0xF3,0xF3,0xF3,0xF3,0xF3,0xF3,0xF3,0xF3,0xF7,0xF7,0xF7,0xF7,0xE7,0xE7,
0xE7,0xEF,0xEF,0xCF,0xDF,0xDF,0x9F,0xBF,0xBF,0x3F,0x7F,0x7F,0xFE,0xFE,0xFC,0xFD,
0xF9,0xF3,0xF7,0xE7,0xCF,0xDF,0x9F,0x3F,0x3F,0x1F,0xDF,0x9F,0x1C,0x98,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC3,0xE3,0xF9,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x7F,0x3F,0xDF,0xEF,0xF7,0xFB,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x7F,0xFF,0xFE,0xFE,0xFC,0xFD,0xF9,
0xF3,0xF7,0xE7,0xCF,0xDF,0x9F,0x3F,0x7F,0xFF,0xFE,0xFC,0xF9,0x81,0x1C,0x0A,0xE0,
0x3D,0x3C,0xB8,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF4,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x1F,0x0F,0xE3,0x31,
0x18,0x09,0x05,0x04,0x08,0x19,0x33,0x00,0xFF,0xFF,0xFF,0xFF,0x3F,0x3F,0xFF,0xFF,
0xFF,0x7F,0x3F,0x9F,0x67,0x23,0x10,0x14,0x16,0x30,0x67,0x8F,0x1F,0x7F,0x7F,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7E,0xFD,0x73,0xE0,0x0F,0x98,0xB8,0x0B,
0xE0,0xED,0xC6,0xFD,0xF8,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x06,0x00,0x1F,0xFF,0xFF,0x1F,0x3D,0x80,0x3F,0xF8,0xF8,0xE0,
0xC0,0x82,0x87,0x82,0xC0,0xE0,0xF0,0xFC,0xF1,0xE7,0xF1,0xFC,0xFF,0xE0,0xCF,0xE3,
0xF9,0xFC,0xC3,0x00,0x00,0x08,0x1C,0x08,0x00,0x00,0x80,0xE1,0x60,0x00,0xE0,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x87,0xF0,0xFF,0x00,0x0F,0xFC,0xFF,0xFF,0x00,
0x81,0xB3,0x7F,0x7F,0x7F,0xBF,0xBF,0xBF,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x3E,0xFF,0xFE,0xFE,0xFC,0xFD,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0x07,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
0xF7,0xF7,0x07,0x8F,0xFE,0xFC,0xFC,0xFC,0xDE,0xCF,0xE3,0xE9,0x64,0x17,0x47,0xBF,
0xDF,0xCF,0xE7,0x03,0xF9,0xFC,0xFF,0xFF,0xFF,0x3F,0xE0,0x00,0xFF,0xFF,0x0F,0xE0,
0x00,0x0F,0x0F,0x0E,0x0D,0x0C,0x08,0x08,0x09,0x09,0x08,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xF9,0xF3,0xF7,0xE7,0x0F,
0xDF,0x9F,0x3F,0xBF,0x3F,0x7F,0x7F,0x7E,0xF8,0xF3,0xF7,0xEF,0xEF,0xEF,0xEF,0xEF,
0xF7,0xF9,0xFC,0xFF,0xFF,0xFF,0x7F,0x7F,0x7F,0x3F,0x9F,0x1F,0xC1,0xFE,0xFF,0xFF,
0xFF,0xFF,0x1F,0x00,0xFF,0xFF,0xFF,0xC7,0x7F,0xFF,0x80,0x70,0xF7,0xC7,0x00,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x38,
0xE1,0x1F,0x00,0x87,0x1F,0x0F,0xEF,0xEE,0xE2,0xE4,0xF4,0xF5,0x05,0x39,0xBB,0x0B,
0x07,0x3B,0xF9,0xFC,0x3C,0x9E,0xC0,0xE3,0xE0,0xF7,0x07,0x78,0x1F,0xFF,0xFF,0xFF,
0xFF,0x5F,0x00,0xFE,0xF1,0x3F,0xFF,0xFF,0xFE,0xF9,0xE7,0x98,0x0F,0xFF,0xFC,0xF0,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Users\admin\Desktop\hutao.bmp",0*/

};
u8 strnum[4]={0};
u8 SaveNumber=50,searchnum=0;
unsigned int SearchNumber=0,clk0=0;
bit modeflag= 0 , clearallflag=0, changeflag=0,fkflag=0;
u8 num_char[10]={'0','1','2','3','4','5','6','7','8','9'};
//定义密码,实际上密码需要存在eeprom中,可以通过程序更改。请用户自行添加
u8 FifoNumber=0;
u8 idata FIFO[MAX_NUMBER+1]={0};
//////////////////////////////////////常用指令定义/////////////////////////////

//Verify Password :验证设备握手口令
u8 code VPWD[16]={16,0X01 ,0Xff,0xff,0xff,0xff, 0x01,0,7,0x13,0x00,0x00,0x00,0x00,0x00,0x1b}; //回送12个

//设置设备握手口令
u8 code STWD[16]={16,0X01 ,0Xff,0xff,0xff,0xff, 0x01,0,7,0x12,0x00,0x00,0x00,0x00,0x00,0x1a}; //回送12个

//GetImage :探测手指并从传感器上读入图像
u8 code GIMG[14]={12, 0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,3,1,0x00,0x05}; //回送12个

//Gen Templet1 :根据原始图像生成指纹特征1
u8 code GENT1[14]={13,0X01 ,0Xff,0xff,0xff,0xff,0x01,0,4,2,1,0x00,0x08}; //回送12个

//Gen Templet2 :根据原始图像生成指纹特征2
u8 code GENT2[14]={13,0X01 ,0Xff,0xff,0xff,0xff,0x01,0,4,2,2,0x00,0x09}; //回送12个


//Search Finger :以CharBufferA或CharBufferB中的特征文件搜索整个或部分指纹库
u8 code SEAT[18]={17, 0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,8, 4,1,0,0, 0,0x65, 0x00,0x73}; //回送16个


//Merge Templet ;将CharBufferA与CharBufferB中的特征文件合并生成模板,结果存于ModelBuffer。
u8 code MERG[14]={12, 0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,3,5 , 0x00,0x09};//回送12个

//Store Templet :将ModelBuffer中的文件储存到flash指纹库中
u8 code STOR[16]={15, 0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,6,6,2, 0x00,0x00, 0x00,0x0f}; //回送12个

//Read Note
u8 code RDNT[14]={13,0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,4,0x19, 0, 0x00,0x1e};

//Clear Note
u8 code DENT[46]={45,0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,36,0x18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00,0x3d};

//DEL one templet
u8 code DELE_one[16]={16, 0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,7, 0x0c, 0x00,0x00, 0,1, 0x00,0x15};

//DEL templet ;清空指纹库
u8 code DELE_all[12]={12,0X01 ,0Xff,0xff,0xff,0xff, 0x01, 0,3, 0x0d,0x00,0x11};

/*******************************************************************************
串口发送函数
*******************************************************************************/
void TxdByte(u8 dat)//串口发送信息,通过查询方式发送一个字符
{
TI = 0; //让TI=0
SBUF = dat; //读入数据
while(!TI); //等待发送完毕
TI = 0; //清零
}
void fangke()//fangke&wifi
{
if((fkkey==0&&fkflag==1)||wifikey==0)//访客模式
{
Delay1ms(5);
if(fkkey==0||wifikey==0)//如果仍为低电平,表示按键有效
{
beep=0;
Delay1ms(40);
beep=1;
Delay1ms(40);
beep=0;
Delay1ms(40);
beep=1;
Delay1ms(40);
Door_Open();
while(fkkey==0||wifikey==0);//等待松手
Delay1ms(2000);
Door_Close();
}
}
if(fkkey==0&&fkflag==0)
{
Delay1ms(5);
if(fkkey==0)//如果仍为低电平,表示按键有效
{
OLED_Clear();Delay1ms(20);
OLED_ShowString(0,0,"sleep! please");
OLED_ShowString(2,2,"back later!");
}
}
}

/*******************************************************************************
命令解析,给模块发送一个命令
*******************************************************************************/
bit Command(u8 *p,u8 MaxTime) //命令解析,给模块发送一个命令
{
u8 count=0,tmpdat=0,temp=0,i=0,package=0,flag=0,checksum=0;
bit result=0, start=0,stop=0;
TxdByte(0xef);//数据包包头识别码
TxdByte(0x01);//数据包包头识别码
i=*p; //数组的第“0”个元素、里面存放了本数组的长度,把这个长度给变量i,方便进行操作
p++;
p++;
for (count=i-1; count!=1;count--) //Sent command String
{
temp=*p++;//取第个“1”个元素的内容,然后发送
TxdByte(temp);//将数据发送出去
}
result=TURE;//发送完成,结果为真 (真为1)
FifoNumber=0;
for (count=MAX_NUMBER+1; count!=0; count--)//清空所有FIFO[]数组里面的内容,写入0X00
{
FIFO[count-1]=0x00;
}
if (result)
{
result=FALSE;
start =FALSE;
stop =FALSE;
count=0;
clk0=0; //清零CL0计数
do /////////////////////////////do的内容////////////////////////////////
{
restart0:
if (RI==1)//如果接收到数据
{
tmpdat=SBUF;//先把接收到的数据放到tmpdat中
RI=0;
if ((tmpdat==0xef)&&(start==FALSE))//这个数据为第一个传回来的数据,也就是“指令应答”的第一个字节
{
count=0;
FIFO[0]=tmpdat;//读入第一个应答字节(0XEF),存在第“0”个元素中
flag=1;
goto
restart0;//可以用中断方式进行
}

if(flag==1)//第一个字节已经回来,所以flag==1成立
{
if(tmpdat!=0x01) //接收数据错误,将重新从缓冲区接收数据
{
flag=0;//接收应答失败
result=FALSE;
start =FALSE;
stop=FALSE;
count=0;
goto
restart0;
}
//如果成功接收到0xef01,可以开始接收数据
flag=2;//flag=2;表示应答成功,可以开始接收数据了
count++;//现在count=1;
FIFO[count]=tmpdat;//读入第二个应答字节(0X01),存在第“1”个元素中
start=TURE; //应答成功可以开始接收数据
goto
restart0;
}

if((flag==2)&&(start==TURE))//flag=2;表示应答成功,可以开始接收数据了
{
count++; //数据元素下标++
FIFO[count]=tmpdat;//存入数据
if(count>=6)
{
checksum=FIFO[count]+checksum; //计算校验和
}

if(count==8)
{
package = FIFO[7]*256 + FIFO[8]; //计算包长度
stop= TURE;
}

if(stop)
{
if(count == package+8)
{
checksum=checksum-FIFO[count-1] - FIFO[count];
if(checksum != (FIFO[count]&0xff))
result=FALSE; //校验失败,置结果标志为0
else
result=TURE;
flag=0;
break;
}
}
}
}
}/////////////////////////////do的内容----------------结束////////////////////////////////

while ((clk0<=MaxTime)&&(count<=MAX_NUMBER) && ( changeflag == 0 )); //由定时器以及最大接收数据来控制,保证不会在此一直循环

FifoNumber=count; //保存接收到的数据个数
}
return (result);
}
/*******************************************************************************
验证设备握手 ,成功返回1
*******************************************************************************/
bit VefPSW()
{
u8 count=0;
while (1)
{
if(Command(VPWD,20) && (FifoNumber==11) && (FIFO[9]==0x00))
{
return (1) ;
}
count++;
if (count>=2)//如果不成功,再验证一次,如果两次不成功,返回失败
{
return(0);
}
}
}
/*******************************************************************************
清空指纹库
*******************************************************************************/
/*void Clear_All() //清空指纹库
{
Delay1ms(200);
Command(DELE_all,50); //清空指纹库
}*/
/*******************************************************************************
发获取图像并生成特征文件,存入BUFID中//输入参数为缓冲区号
*******************************************************************************/
u8 ImgProcess(u8 BUFID) //
{
if(Command(GIMG,89) && (FifoNumber==11) && (FIFO[9]==0x00))
{
if(BUFID==1)
{
if(Command(GENT1,60) && (FifoNumber==11) && (FIFO[9]==0x00))
{
return 1;
}
}
else if(BUFID==2)
{
if(Command(GENT2,60) && (FifoNumber==11) && (FIFO[9]==0x00))
{
return 1;
}
}
else
{
;
}
}

return 0;
}
/*******************************************************************************
搜索指纹(发送搜索命令、以及根据返回值确定是否存在)
*******************************************************************************/
bit Searchfinger()//
{
if(Command(SEAT,60) && (FifoNumber==15) && (FIFO[9]==0x00) )
{
SearchNumber=FIFO[10]*0x100+FIFO[11];//搜索到的页码
//MatchScore=FIFO[12]*0x100+FIFO[13] 可以在此计算得分,从而进行安全级别设定,本程序忽略
return 1;
}
else
{
return 0;
}
}

/*******************************************************************************
搜索用户
*******************************************************************************/
u8 search()//搜索用户
{
u8 SearchBuf=0,i=0;
while (i<20)
{
if ( ImgProcess(1)==1 ) //首先读入一次指纹 这里表示有指纹按在上面了
{
SearchBuf=Searchfinger();//进行指纹比对,如果搜索到,返回搜索到的指纹序号
if(SearchBuf==1)
{
return SearchNumber;
}
else
{
return 255; //由于只有162个指纹,如果返回255,表示这个指纹识别失败
}
}
i++;
}
return 0;
}
/*******************************************************************************
保存指纹
*******************************************************************************/
bit savefingure(u8 ID)
{
u8 i=0;
//现在开始进行存储指纹模板的操作
for (i=0;i<16;i++) //保存指纹信息
{
FIFO[i]=STOR[i];
}
FIFO[12]=ID; //把指纹模板存放的PAGE_ID也就是FLASH的位置
FIFO[14]=FIFO[14]+ID; //校验和
if (Command(FIFO,70)==1)//不成功返回0 //此处进行存放指纹模板的命
{
return(1);
}

return (0) ; //不成功返回0
}


/*******************************************************************************
采集指,两次采集并生成一个指纹模板
*******************************************************************************/
u8 enroll() //采集两次指纹,生成1个 指纹模板
{
u8 temp=0,count=0;
Delay1ms(30);
while(1)
{
temp=ImgProcess(1); //生成特征1
if ( temp == 1 )//生成特征文件成功
{
break;
}
else
{
if ( temp == 0 )//采集指纹没有成功
{
count++;
if (count>=40)//如果采集了40次,还不成功,直接采集失败,直接退出enroll函数----返回0
return(0);
}
}
}
count=0;
Delay1ms(1000);//延时1S开始采集下一个特征
//开始采集第二个特征
while(1)
{
temp=ImgProcess(2); //生成特征2
if (temp==1)//生成特征文件2成功
{
if ( (Command(MERG,40)&& (FifoNumber==11) && (FIFO[9]==0x00))==0 ) //合并不成功返回0,成功返回1
{
return(0);
}
else//特征文件合并生成模板,结果存于ModelBuffer
{
OLED_Clear();Delay1ms(10);
OLED_ShowCHinese(32,0,0); //添加
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,2);//成功
OLED_ShowCHinese(80,0,3);
return 1;
}
}
else //采集指纹没有成功
{
count++;
if (count>=25)
{
OLED_Clear();Delay1ms(10);
OLED_ShowCHinese(32,0,0); //添加
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,4);//失败
OLED_ShowCHinese(80,0,5);
return(0);
}
}
}
}
/*******************************************************************************
OLED显示指纹号
*******************************************************************************/
void numshow(u8 num)
{
strnum[0]= ':';
strnum[1]= num_char[num/10]; Delay1ms(10); //+48是为了转换在ASCII码 百
strnum[2]= num_char[num%10];//+48是为了转换在ASCII码 十
OLED_ShowCHinese(76,2,15);//指纹号
OLED_ShowCHinese(92,2,21);
OLED_ShowCHinese(108,2,16);
OLED_ShowString(82,4,strnum);
fangke();
}
/*******************************************************************************
模式状态显示
*******************************************************************************/
void modecheck()
{
if(modeflag==0)
{
D3=0;
D4=1;
OLED_Clear();
OLED_ShowPicture(0, 0, 128, 64, BMP);
OLED_ShowCHinese(64,0,23); //识别模式
OLED_ShowCHinese(80,0,24);
OLED_ShowCHinese(96,0,25);
OLED_ShowCHinese(112,0,26);
}
else
{
D3=1;
D4=0;
OLED_Clear();
OLED_ShowCHinese(32,0,0); //添加用户
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,10);
OLED_ShowCHinese(80,0,11);
}
numshow(0);
}
void modec()
{
unsigned int i=0;
unsigned char p;
while(1)
{
for(i=0;i<6;i++)//开始握手6次,如果没有一次成功,表示模块通信不正常。只要成功就跳出此循环
{
if(VefPSW())//与模块握手通过,绿灯亮起。进入识别模式
{
OLED_ShowString(8,4, "Lock test");// Fingerprint lock指纹锁
OLED_ShowString(10,6,MODE3);
Delay1ms(50); //显示1秒握手状态
modecheck(); //显示当前是什么状态
break;
}
else
{
OLED_Clear();
OLED_ShowString(0,0,MODE4);
break;
}
}
for(p=30;p>0;p--)
{
dokey();
fangke();
if( modeflag == 1 )//为录入指纹模式
{
if(k4==0)//录入一个指纹
{
Delay1ms(10);
OLED_Clear();
if(k4==0)//如果仍为低电平,表示按键有效
{
OLED_ShowCHinese(32,2,12); //请放手指
OLED_ShowCHinese(48,2,13);
OLED_ShowCHinese(64,2,14);
OLED_ShowCHinese(80,2,15);
while(k4==0);//等待松手
if( SaveNumber<162 )//与模块握手通过
{
if(enroll()==1)//采集两次,生成1个指纹模板成功
{
if(savefingure(SaveNumber+1)==1)//保存也成功
{
SaveNumber++;//加一次
OLED_Clear();
OLED_ShowCHinese(32,0,0); //添加
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,2);//成功
OLED_ShowCHinese(80,0,3);
Delay1ms(500);
OLED_Clear();
OLED_ShowCHinese(32,0,0); //添加用户
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,10);
OLED_ShowCHinese(80,0,11);
numshow(SaveNumber);
}
}
else
{
OLED_Clear();
OLED_ShowCHinese(32,0,0); //添加
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,4);//失败
OLED_ShowCHinese(80,0,5);
Delay1ms(500);
OLED_Clear();
OLED_ShowCHinese(32,0,0); //添加用户
OLED_ShowCHinese(48,0,1);
OLED_ShowCHinese(64,0,10);
OLED_ShowCHinese(80,0,11);
numshow(SaveNumber);
}
}
}
}
}
dokey();
fangke();
if( modeflag==0 )//为识别模式
{
fangke();
searchnum=search();
if(searchnum>=1 && searchnum <= 162 )
{
numshow(searchnum);//显示搜索到的指纹
OLED_ShowString(80,6,shibie1);
Delay1ms(2);
//OLED_Clear();
//Delay1ms(5);
//OLED_ShowString(1,0,"Open!");
Door_Open();
Delay1ms(2000);
Door_Close();
OLED_ShowPicture(0, 0, 128, 64, BMP);
OLED_ShowCHinese(64,0,23); //识别模式
OLED_ShowCHinese(80,0,24);
OLED_ShowCHinese(96,0,25);
OLED_ShowCHinese(112,0,26);
numshow(searchnum);
}
if(searchnum==255)//识别指纹失败
{
numshow(0);
OLED_ShowString(80,6,shibie2);
Delay1ms(100);
OLED_ShowPicture(0, 0, 128, 64, BMP);
OLED_ShowCHinese(64,0,23); //识别模式
OLED_ShowCHinese(80,0,24);
OLED_ShowCHinese(96,0,25);
OLED_ShowCHinese(112,0,26);
numshow(0);
}
}

/*if(clearallflag==1)
{
OLED_Clear();
OLED_ShowCHinese(16,0,6);//删除所有指纹
OLED_ShowCHinese(32,0,7);
OLED_ShowCHinese(48,0,8);
OLED_ShowCHinese(64,0,9);
OLED_ShowCHinese(80,0,10);
OLED_ShowCHinese(96,0,11);
OLED_ShowCHinese(32,2,2);
OLED_ShowCHinese(48,2,3);
Delay1ms(100);
clearallflag=0;
Clear_All();
D3=D4=0;
modeflag=1;//进入录入指纹模式
SaveNumber=0;
numshow(0);
Delay1ms(200);
modecheck();
} */
if( changeflag == 1 )
{
modecheck();
changeflag=0;
}
fangke();
}////////////////////////////while(1)结束////////////////////////////////
}
}
void dokey() //按键操作
{
fangke();
if(k3==0)//模式转换 其中用modeflag 来标志,默认从第1个指纹开始录入
{
Delay1ms(5);
if(k3==0)//如果仍为低电平,表示按键有效
{
while(k3==0);//等待松手
modeflag=~modeflag;//0表示录入指纹 1表示识别指纹
OLED_ShowString(64,6,"loading...");// Fingerprint lock指纹锁
changeflag=1;//模式发生了切换
}
}
/*if(k5==0) //清除所有指纹
{
Delay1ms(5);
if(k5==0)//如果仍为低电平,表示按键有效
{
while(k5==0);//等待松手
clearallflag=1;
}
}*/
if(k6==0)//访客模式
{
Delay1ms(5);
if(k6==0)//如果仍为低电平,表示按键有效
{
while(k6==0);//等待松手
fkflag=~fkflag;
if(fkflag)
{
beep=0;
Delay1ms(40);
beep=1;
Delay1ms(40);
}
fk=~fk;
OLED_ShowString(64,6,"f ok!");
}
}
if(wififkkey==0)
{

fkflag=~fkflag;
if(!fkflag)
{
beep=0;
Delay1ms(40);
beep=1;
Delay1ms(40);
}
if(fkflag)
{
beep=0;
Delay1ms(30);
beep=1;
Delay1ms(30);
beep=0;
Delay1ms(30);
beep=1;
Delay1ms(30);
beep=0;
Delay1ms(30);
beep=1;
Delay1ms(30);
}
fk=~fk;
OLED_ShowString(64,6,"f ok!");
Delay1ms(5000);
}
}

esp8266代码(参考点灯科技)

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
#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI

#include <Blinker.h>
char auth[] = "91ac953e38b3";
char ssid[] = "wifi";
char pswd[] = "djyyds12121";
// 新建组件对象
BlinkerButton ButtonOn("btn-on");
BlinkerButton Button2("btn2-on");
int counter = 0;
int GPIO=0;//定义GPIO口用于控制继电器
// 按下按键即会执行该函数
void Button2_callback(const String & state) {
if (state == "press") {
BLINKER_LOG("get button state: 开");
Blinker.print("访客模式", "切换(滴一声证明是开启)");
digitalWrite(GPIO, LOW);
Button2.print("on");
}

if (state == "pressup") {
BLINKER_LOG("get button state: 关");
digitalWrite(GPIO, HIGH);
delay(200);
// 反馈开关状态
Button2.print("off");
}
Blinker.vibrate();
}
void button1_callback(const String & state) {
if (state == "on") {
BLINKER_LOG("get button state: 开");
Blinker.print("开关", "on");
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
ButtonOn.print("on");
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
// 反馈开关状态
ButtonOn.print("off");
}

if (state == "off") {
BLINKER_LOG("get button state: 关");
digitalWrite(GPIO, HIGH);
delay(200);
// 反馈开关状态
ButtonOn.print("off");
}
Blinker.vibrate();
}

// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
}


void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ",state);

if (state == BLINKER_CMD_OFF) {//如果语音接收到是关闭灯就设置GPIO口为高电平
digitalWrite(GPIO, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_ON) {
digitalWrite(GPIO, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
delay(2000);
digitalWrite(GPIO, HIGH);
digitalWrite(LED_BUILTIN,HIGH);
delay(200);
// 反馈开关状态
ButtonOn.print("off");
}
}


void setup() {
// 初始化串口
Serial.begin(115200);
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,HIGH);//初始化,由于继电器是低电平触发。所以刚开始设为高电平
pinMode(GPIO,OUTPUT);
digitalWrite(GPIO,HIGH);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
// 初始化有LED的IO
// pinMode(LED_BUILTIN, OUTPUT);
// digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
ButtonOn.attach(button1_callback);
Button2.attach(Button2_callback);
BlinkerMIOT.attachPowerState(miotPowerState);//这段代码一定要加,不加小爱同学控制不了,务必在回调函数中反馈该控制状态
}

void loop() {

Blinker.run();
}