采用指纹识别和密码识别双重保证。是用51单片机编写的源程序
电路原理图如下:
Altium Designer画的单片机指纹考勤机PCB图如下:(51hei附件中可下载工程文件)
元件清单
1) 9*15万用板
2) 指纹传感器
3) 40脚座
4) 单片机
5) 12864有字库液晶
6) 20p插针
7) 20p单排母座
8) 按键*17
9) 103电位器(蓝白)
10) 1k电阻*3
11) 10k电阻*1
12) 10uf电容
13) 30pf电容*2
14) 11.0592m晶振
15) AMS1117
16) 100Uf*2
17) 自锁开关
18) DC电源接口
19) 导线若干
20) 焊锡若干
21) usb电源线
单片机源程序如下:
- #include"reg52.h"
- #include"12864.h"
- #include"eeprom.h"
- #include"matrixkey.h"
- #include"AT24CXX.h"
- #include"finger.h"
- uchar code table1[]="A:签到 B:添加 ";
- uchar code table2[]="C:清空 D:上课 ";
- uchar code table3[]=" *查询缺勤人员 ";
- uchar code table4[]=" #查询迟到人员 ";
- uchar code table5[]="请输入删去密码: ";
- uchar code table6[]=" 开始签到 ";
- uchar code table7[]=" 请按指纹签到 ";
- uchar code table8[]=" ";
- uchar code table9[]="按D: 开始上课 ";
- uchar code table10[]="请输入密码: ";
- uchar code table11[]=" 签到成功 ";
- uchar code table12[]="请按任意按键继续";
- uchar code table13[]=" 编号为: ";
- uchar code table14[]=" 请按手指 ";
- uchar code table15[]=" 请再按一次 ";
- uchar code table16[]=" 采集指纹成功 ";
- uchar code table17[]="输入删去的指纹号";
- uchar code table18[]="删去指纹库成功 ";
- uchar code table19[]="删去指纹库失败 ";
- uchar code table20[]=" 请输入新密码 ";
- uchar code table21[]="请再次输入新密码";
- uchar code table22[]=" 密码修改成功 ";
- uchar code table23[]=" 两次密码不一样";
- uchar code table24[]=" 输入密码错误 ";
- uchar code table25[]=" 还有 机会 ";
- uchar code table26[]=" 该指纹已存储 ";
- uchar code table27[]=" 采集指纹失败 ";
- uchar code table28[]="确定删去指纹库?";
- uchar code table29[]="按D: 本节课结束";
- uchar code table30[]="当前缺勤 人";
- uchar code table31[]="当前迟到 人";
- uchar code digital[15]={0x90,0x92,0x94,0x96,0x88,0x8a,0x8c,0x8e,0x98,0x9a,0x9c,0x9e};
- uchar xdata table_qiandao[100];
- uchar queqing=0;//缺勤人数
- uchar zz;
- uchar chidao=0;//迟到人数
- uchar code admin[6]={1,3,1,4,2,0};//管理员的固定密码
- uchar code init_code[6]={0,0,0,0,0,0};//上电第一次一般的初始化密码
- uchar now_code[6]={0,0,0,0,0,0};//当前存储器中存储的密码
- uchar user[6]={0,0,0,0,0,0};//用户输入的密码
- uchar user2[6]={0,0,0,0,0,0};//输入第二次修改的密码
- sbit relay=P3^7;//开锁继电器
- sbit wake=P3^6;//检测手指按压,有手指按下就是高电平
- uchar jishu=0;
- uchar err_user=3;//用户三次输入错误密码
- uchar err_admin=3;//管理员三次输入错误密码
- uchar num;//存储矩阵键盘转换的对应按键值
- uchar number=0;//输入密码的个数默认0
- uchar key_flag=0;//进入手动密码标志
- uchar i;
- uchar code_flag=0;//密码修改标志第一次输入密码时候是等于0再次输入是等于1
- void init_dispay(void)//初始化界面
- {
- PutStr(0,0,table1);
- PutStr(1,0,table2);
- PutStr(2,0,table3);
- PutStr(3,0,table4);
- }
- void admin_dispay(void)//管理员界面
- {
- PutStr(0,0,table6);
- PutStr(1,0,table7);
- PutStr(2,0,table8);
- PutStr(3,0,table9);
- }
- void init_shuju(void)
- {
- uchar i;
- for(i=0;i<100;i++)
- {
- table_qiandao[i]=0x00;
- }
- }
- void que_renshu(void)
- { queqing=0;//缺勤人数
- // WriteCommand(0x80+2);
- // WriteData(jishu/10+0x30);
- // WriteData(jishu%10+0x30);
- for(i=0;i<jishu;i++)
- {
- if(table_qiandao[i]==0x00)
- {
- queqing++;
- WriteCommand(digital[queqing-1]);
- WriteData((i+1)/10+0x30);
- WriteData((i+1)%10+0x30);
-
- }
- }
- }
- void chidao_renshu(void)
- { queqing=0;//缺勤人数
- // WriteCommand(0x80+2);
- // WriteData(jishu/10+0x30);
- // WriteData(jishu%10+0x30);
- for(i=0;i<jishu;i++)
- {
- if(table_qiandao[i]>=2)
- {
- queqing++;
- WriteCommand(digital[queqing-1]);
- WriteData((i+1)/10+0x30);
- WriteData((i+1)%10+0x30);
-
- }
- }
- }
- void key(void)
- {
- num=keynum();
- if((num==12)&&(key_flag==0))//查看缺勤人数
- {
- LcmClearTXT();//清屏
- PutStr(0,0,table30);
- que_renshu();
- WriteCommand(0x80+6);
- WriteData(queqing/10+0x30);
- WriteData(queqing%10+0x30);
- while((keynum()>=16));
- init_dispay();
- }
- if((num==14)&&(key_flag==0))//查看迟到人数
- {
- LcmClearTXT();//清屏
- PutStr(0,0,table31);
- chidao_renshu();
- WriteCommand(0x80+6);
- WriteData(queqing/10+0x30);
- WriteData(queqing%10+0x30);
- while((keynum()>=16));
- init_dispay();
- }
- if((num==11)&&(key_flag==0))//如果按下C按键进
- {
- key_flag=1;
- //只显示“请输入密码开锁:“
- LcmClearTXT();//清屏
- PutStr(0,0,table28);
- PutStr(1,0,table5);
- }
- if((num==7)&&(key_flag==0))//如果按下B按键进入添加指纹
- {
-
- LcmClearTXT();//清屏
- PutStr(1,0,table14); //显示请按指纹
- if(regist(0)==1)//如果第一次按手指成功
- {
- PutStr(1,0,table15); //显示请再按一次
- Delay(10);//延时一会
- if(regist(1)==1)//两次采集手指成功
- {
- PutStr(1,0,table16); //采集指纹成功
- PutStr(2,0,table13); //指纹编号:
- WriteCommand(0x88+5);//指定第三行显示位置
- WriteData(' ');
- id=id+1;
- WriteData(id/100+0x30);
- WriteData(id%100/10+0x30);
- WriteData(id%10+0x30);
- SectorErase(0x2200);
- jishu=id%256;
- byte_write(0x2200, id%256);
-
- }
- else PutStr(1,0,table27); //采集指纹失败
- }
- else if(regist(0)==2)//已经注册过指纹
- {
- PutStr(1,0,table26); //指纹已经存储
- }
-
- PutStr(3,0,table12); //请按任意键退出
- while(keynum()>=16);
- init_dispay();//管理员设置界面
- key_flag=0;
- num=0xff;
- }
- if((num==3)&&(key_flag==0))//如果按下A按键管理员模式
- {
- key_flag=2;//进入输入管理员密码界面
- //只显示“请输入密码:“
- LcmClearTXT();//清屏
- PutStr(1,0,table10);
- }
- if((key_flag==1)&&(num!=0xff))//非管理员模式下输入密码
- {
- num=coding(num);//转换成可以识别的
- if((number<6)&&(num<10))
- {
- user[number]=num;//用户输入的密码进行记忆
- WriteCommand(0x88+number); //指定第三行显示位置
- WriteData('*');
- //WriteData(num+0x30);//明码显示
- number++;
- }
- if((num=='B')&&(number>0))//密码删除按键
- { number--;
- WriteCommand(0x88+number); //指定第三行显示位置
- WriteData(' ');
- }
- if(number==6)//按下D键确定按键并且输入六位密码之后
- {
- LcmClearTXT();//清屏
- number=0;
- key_flag=0;
- //如果管理员密码正确,进入添加指纹,删除指纹,收到开锁,修改密码界面
- if((user[0]==now_code[0])&&(user[1]==now_code[1])&&(user[2]==now_code[2])&&(user[3]==now_code[3])&&(user[4]==now_code[4])&&(user[5]==now_code[5]))
- {
- if(cancel(0x63)==1)
- {
- PutStr(0,0,table18);//输入删去的指纹号成功
- SectorErase(0x2200);
- byte_write(0x2200, 0x00);
- }
- else
- {
- PutStr(0,0,table19);//输入删去的指纹号失败
- }
- Delay(80);
- }
- else//密码错误
- {
- PutStr(1,0,table24);//显示输入密码错误
-
-
- }
- PutStr(3,0,table12);
- while((keynum()>=16)&&(err_user!=0));
- init_dispay();//初始化界面
- }
-
- }
- if((key_flag==2)&&(num!=0xff))//签到模式下输入数字按键
- {
- num=coding(num);//转换成可以识别的
- if((number<6)&&(num<10))
- {
- user[number]=num;//用户输入的密码进行记忆
- WriteCommand(0x88+number); //指定第三行显示位置
- WriteData('*');
- // WriteData(num+0x30); //明码显示
- number++;
- }
- if(number==6)//输入六位以后进行密码校验
- { //如果管理员密码正确,进入添加指纹,删除指纹,收到开锁,修改密码界面
- if((user[0]==admin[0])&&(user[1]==admin[1])&&(user[2]==admin[2])&&(user[3]==admin[3])&&(user[4]==admin[4])&&(user[5]==admin[5]))
- {
- key_flag=55;
- admin_dispay();//进入签到页面
- err_admin=3;
- num=0XFF;
- init_shuju();
- }
- else//管理员密码错误
- {
-
- PutStr(1,0,table24);//显示输入密码错误
- PutStr(3,0,table12);
- while((keynum()>=16)&&(err_admin!=0));
- init_dispay();//初始化界面
- number=0;
- key_flag=0;
- }
- }
- if((num=='B')&&(number>0))
- {
- number--;
- WriteCommand(0x88+number); //指定第三行显示位置
- WriteData(' ');
- }
-
-
- }
- if(key_flag==55)//进入签到指纹巡查
- { num=coding(num);//转换成可以识别的
- if(num=='D')//按下就进入开始上课
- {
- key_flag=56;
- PutStr(3,0,table29);
- }
- if(wake==1)//如果有手指按下
- {
- if(check()==1)//进行指纹匹配
- { err_admin=3;
- err_user=3;
- LcmClearTXT();//清屏
- PutStr(1,0,table11);
- PutStr(2,0,table13);
- WriteCommand(0x88+5); //指定第三行显示位置
- WriteData(' ');
- zz=id%256;
- table_qiandao[zz]=0x01;
- id++;
- WriteData(id/100+0x30);
- WriteData(id%100/10+0x30);
- WriteData(id%10+0x30);
-
- // WriteData(table_qiandao[zz]%100/10+0x30);
- // WriteData(table_qiandao[zz]%10+0x30);
- relay=0;
- Delay(80);
- relay=1;
- Delay(20);
- PutStr(3,0,table12);
- number=0;
- key_flag=55;
- admin_dispay();//回到初始界面
- num=0xff;
-
- }
- }
- }
- if(key_flag==56)//迟到的
- { num=coding(num);//转换成可以识别的
- if(num=='D')//按下就进入开始上课
- {
- key_flag=0;
- number=0;
- init_dispay();
- }
- if(wake==1)//如果有手指按下
- {
- if(check()==1)//进行指纹匹配
- {
- LcmClearTXT();//清屏
- PutStr(1,0,table11);
- PutStr(2,0,table13);
- WriteCommand(0x88+5); //指定第三行显示位置
- WriteData(' ');
- zz=id%256;
- table_qiandao[zz]=table_qiandao[zz]+0x02;
- id++;
- WriteData(id/100+0x30);
- WriteData(id%100/10+0x30);
- WriteData(id%10+0x30);
-
- // WriteData(table_qiandao[zz]%100/10+0x30);
- // WriteData(table_qiandao[zz]%10+0x30);
- relay=0;
- Delay(80);
- relay=1;
- Delay(20);
- PutStr(3,0,table12);
- number=0;
- key_flag=56;
- admin_dispay();//回到初始界面
- PutStr(3,0,table29);
- num=0xff;
- }
- }
- }
-
- }
- void main()
- {
- for(i=0;i<6;i++)//读取存储器中的密码
- {
- now_code[i]=read_add(20+i);
- Delay(5);
- }
- for(i=0;i<6;i++)
- {
- if(now_code[i]>9)
- {
- i=10;
- break;
- }
- }
- if(i>9)//设置初始化密码
-
- {
- for(i=0;i<6;i++)
- {
- now_code[i]=init_code[i];
- Delay(5);
- }
- }
-
- LcmInit();//初始化12864
-
-
-
- jishu=byte_read(0x2200);
- // WriteCommand(0x88);
- // WriteData(jishu/10+0x30);
- // WriteData(jishu%10+0x30);
- // Delay(30);
- // Delay(50);
- init_dispay();//进入初始化显示界面
- UART_Init(); //初始化串口9600
- init_shuju();
- while(1)
- {
- key();
- }
- }
复制代码
所有资料51hei附件下载:
指纹考勤.7z
(1.51 MB, 下载次数: 87)
|