采用指紋識別和密碼識別雙重保證。是用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)
2022-3-28 05:02 上傳
點擊文件名下載附件
|