找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2196|回复: 1
打印 上一主题 下一主题
收起左侧

基于51单片机的智能门禁指纹考勤系统设计 原理图PCB源程序

[复制链接]
跳转到指定楼层
楼主
采用指纹识别和密码识别双重保证。是用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电源线

单片机源程序如下:
  1. #include"reg52.h"
  2. #include"12864.h"
  3. #include"eeprom.h"
  4. #include"matrixkey.h"
  5. #include"AT24CXX.h"
  6. #include"finger.h"
  7. uchar code table1[]="A:签到  B:添加  ";
  8. uchar code table2[]="C:清空  D:上课  ";
  9. uchar code table3[]=" *查询缺勤人员  ";
  10. uchar code table4[]=" #查询迟到人员  ";
  11. uchar code table5[]="请输入删去密码: ";

  12. uchar code table6[]="    开始签到    ";
  13. uchar code table7[]="  请按指纹签到  ";
  14. uchar code table8[]="               ";
  15. uchar code table9[]="按D:  开始上课  ";
  16. uchar code table10[]="请输入密码:     ";
  17. uchar code table11[]="    签到成功    ";
  18. uchar code table12[]="请按任意按键继续";
  19. uchar code table13[]="  编号为:      ";
  20. uchar code table14[]="    请按手指    ";
  21. uchar code table15[]="    请再按一次  ";
  22. uchar code table16[]="  采集指纹成功  ";
  23. uchar code table17[]="输入删去的指纹号";
  24. uchar code table18[]="删去指纹库成功  ";
  25. uchar code table19[]="删去指纹库失败  ";
  26. uchar code table20[]="  请输入新密码  ";
  27. uchar code table21[]="请再次输入新密码";
  28. uchar code table22[]="  密码修改成功  ";
  29. uchar code table23[]="  两次密码不一样";
  30. uchar code table24[]="  输入密码错误  ";
  31. uchar code table25[]="  还有  机会    ";
  32. uchar code table26[]="  该指纹已存储  ";
  33. uchar code table27[]="  采集指纹失败  ";
  34. uchar code table28[]="确定删去指纹库?";
  35. uchar code table29[]="按D:  本节课结束";
  36. uchar code table30[]="当前缺勤      人";
  37. uchar code table31[]="当前迟到      人";
  38. uchar code digital[15]={0x90,0x92,0x94,0x96,0x88,0x8a,0x8c,0x8e,0x98,0x9a,0x9c,0x9e};
  39. uchar  xdata table_qiandao[100];
  40. uchar queqing=0;//缺勤人数
  41. uchar zz;
  42. uchar chidao=0;//迟到人数
  43. uchar code     admin[6]={1,3,1,4,2,0};//管理员的固定密码
  44. uchar code init_code[6]={0,0,0,0,0,0};//上电第一次一般的初始化密码

  45. uchar   now_code[6]={0,0,0,0,0,0};//当前存储器中存储的密码
  46. uchar        user[6]={0,0,0,0,0,0};//用户输入的密码
  47. uchar       user2[6]={0,0,0,0,0,0};//输入第二次修改的密码
  48. sbit relay=P3^7;//开锁继电器
  49. sbit wake=P3^6;//检测手指按压,有手指按下就是高电平
  50. uchar jishu=0;
  51. uchar  err_user=3;//用户三次输入错误密码
  52. uchar err_admin=3;//管理员三次输入错误密码
  53. uchar num;//存储矩阵键盘转换的对应按键值
  54. uchar number=0;//输入密码的个数默认0
  55. uchar key_flag=0;//进入手动密码标志
  56. uchar i;
  57. uchar code_flag=0;//密码修改标志第一次输入密码时候是等于0再次输入是等于1
  58. void init_dispay(void)//初始化界面
  59. {
  60.           PutStr(0,0,table1);
  61.     PutStr(1,0,table2);
  62.                 PutStr(2,0,table3);
  63.                 PutStr(3,0,table4);
  64. }
  65. void admin_dispay(void)//管理员界面
  66. {
  67.          PutStr(0,0,table6);        
  68.    PutStr(1,0,table7);
  69.    PutStr(2,0,table8);        
  70.    PutStr(3,0,table9);                                
  71. }
  72. void init_shuju(void)
  73. {
  74.          uchar i;
  75.          for(i=0;i<100;i++)
  76.             {
  77.                                  table_qiandao[i]=0x00;
  78.                         }
  79. }
  80. void  que_renshu(void)
  81. {  queqing=0;//缺勤人数
  82. //          WriteCommand(0x80+2);        
  83. //                         WriteData(jishu/10+0x30);
  84. //                         WriteData(jishu%10+0x30);
  85.          for(i=0;i<jishu;i++)
  86.             {
  87.                                  if(table_qiandao[i]==0x00)
  88.                                  {
  89.                                           queqing++;
  90.                                           WriteCommand(digital[queqing-1]);
  91.                                           WriteData((i+1)/10+0x30);
  92.                               WriteData((i+1)%10+0x30);
  93.                                          
  94.                                  }
  95.                         }
  96. }
  97. void  chidao_renshu(void)
  98. {  queqing=0;//缺勤人数
  99. //         WriteCommand(0x80+2);        
  100. //         WriteData(jishu/10+0x30);
  101. //         WriteData(jishu%10+0x30);
  102.          for(i=0;i<jishu;i++)
  103.             {
  104.                                  if(table_qiandao[i]>=2)
  105.                                  {
  106.                                           queqing++;
  107.                                           WriteCommand(digital[queqing-1]);
  108.                                           WriteData((i+1)/10+0x30);
  109.                               WriteData((i+1)%10+0x30);
  110.                                          
  111.                                  }
  112.                         }
  113. }
  114. void key(void)
  115. {   
  116.            num=keynum();
  117.            if((num==12)&&(key_flag==0))//查看缺勤人数
  118.                  {
  119.                          LcmClearTXT();//清屏
  120.                          PutStr(0,0,table30);
  121.                          que_renshu();
  122.                          WriteCommand(0x80+6);        
  123.                          WriteData(queqing/10+0x30);
  124.                          WriteData(queqing%10+0x30);
  125.                          while((keynum()>=16));        
  126.        init_dispay();                  
  127.                  }
  128.                  if((num==14)&&(key_flag==0))//查看迟到人数
  129.                  {
  130.                          LcmClearTXT();//清屏
  131.                          PutStr(0,0,table31);
  132.                          chidao_renshu();
  133.        WriteCommand(0x80+6);        
  134.                          WriteData(queqing/10+0x30);
  135.                          WriteData(queqing%10+0x30);
  136.        while((keynum()>=16));        
  137.                init_dispay();         
  138.                  }
  139.                  if((num==11)&&(key_flag==0))//如果按下C按键进
  140.                  {
  141.                          key_flag=1;
  142.                          //只显示“请输入密码开锁:“
  143.                          LcmClearTXT();//清屏
  144.                          PutStr(0,0,table28);
  145.        PutStr(1,0,table5);                 
  146.                  }
  147.                  if((num==7)&&(key_flag==0))//如果按下B按键进入添加指纹
  148.                  {
  149.                         
  150.                           LcmClearTXT();//清屏
  151.           PutStr(1,0,table14);        //显示请按指纹
  152.                                         if(regist(0)==1)//如果第一次按手指成功
  153.                                          {
  154.                                                    PutStr(1,0,table15);        //显示请再按一次
  155.                                                    Delay(10);//延时一会
  156.                                                    if(regist(1)==1)//两次采集手指成功
  157.                                                          {
  158.                                                                    PutStr(1,0,table16);        //采集指纹成功
  159.                    PutStr(2,0,table13);        //指纹编号:
  160.                                                                    WriteCommand(0x88+5);//指定第三行显示位置
  161.                                                                          WriteData(' ');
  162.                                                                    id=id+1;
  163.                                                                          WriteData(id/100+0x30);
  164.                                                                          WriteData(id%100/10+0x30);
  165.                                                                          WriteData(id%10+0x30);                        
  166.                                                                          SectorErase(0x2200);
  167.                                                                    jishu=id%256;
  168.                    byte_write(0x2200, id%256);
  169.                                                                  
  170.                                                          }
  171.                                                          else PutStr(1,0,table27);        //采集指纹失败
  172.                                          }
  173.                                          else   if(regist(0)==2)//已经注册过指纹
  174.                                                                          {
  175.                                                                                          PutStr(1,0,table26);        //指纹已经存储
  176.                                                                          }
  177.                                        
  178.                                          PutStr(3,0,table12);        //请按任意键退出
  179.                                          while(keynum()>=16);           
  180.                                          init_dispay();//管理员设置界面        
  181.                                          key_flag=0;
  182.                                          num=0xff;
  183.                  }
  184.                  if((num==3)&&(key_flag==0))//如果按下A按键管理员模式
  185.                  {
  186.                          key_flag=2;//进入输入管理员密码界面
  187.                          //只显示“请输入密码:“
  188.                          LcmClearTXT();//清屏
  189.        PutStr(1,0,table10);               
  190.                  }
  191.                  if((key_flag==1)&&(num!=0xff))//非管理员模式下输入密码
  192.                  {
  193.                           num=coding(num);//转换成可以识别的
  194.                           if((number<6)&&(num<10))
  195.                                 {
  196.                                         user[number]=num;//用户输入的密码进行记忆
  197.                                         WriteCommand(0x88+number);                //指定第三行显示位置
  198.                                         WriteData('*');
  199.                                         //WriteData(num+0x30);//明码显示        
  200.                                         number++;
  201.                                 }
  202.                                 if((num=='B')&&(number>0))//密码删除按键
  203.                                                 {  number--;
  204.                                                         WriteCommand(0x88+number);                //指定第三行显示位置
  205.                                             WriteData(' ');        
  206.                                                 }
  207.                                 if(number==6)//按下D键确定按键并且输入六位密码之后
  208.                                         {  
  209.                                                    LcmClearTXT();//清屏
  210.                                                    number=0;
  211.                                                          key_flag=0;
  212.                                                   //如果管理员密码正确,进入添加指纹,删除指纹,收到开锁,修改密码界面
  213.                                                          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]))
  214.                                                          {   
  215.                                                                   if(cancel(0x63)==1)
  216.                                                                                         {
  217.                                                                                                  PutStr(0,0,table18);//输入删去的指纹号成功
  218.                                                                                                  SectorErase(0x2200);
  219.                          byte_write(0x2200, 0x00);                        
  220.                                                                                         }
  221.                                                                                         else
  222.                                                                                         {
  223.                                                                                                  PutStr(0,0,table19);//输入删去的指纹号失败
  224.                                                                                         }        
  225.                                                                          Delay(80);
  226.                                                     }
  227.                                                          else//密码错误
  228.                                                            {
  229.                                                                           PutStr(1,0,table24);//显示输入密码错误
  230.                                                                         
  231.                                                                         
  232.                                                                  }
  233.                                                          PutStr(3,0,table12);               
  234.                                                          while((keynum()>=16)&&(err_user!=0));
  235.                                                          init_dispay();//初始化界面         
  236.                                         }
  237.                           
  238.                  }
  239.                  if((key_flag==2)&&(num!=0xff))//签到模式下输入数字按键
  240.                  {
  241.                                                 num=coding(num);//转换成可以识别的
  242.                                                 if((number<6)&&(num<10))
  243.                                                 {
  244.                                                         user[number]=num;//用户输入的密码进行记忆
  245.                                                         WriteCommand(0x88+number);                //指定第三行显示位置
  246.                                                         WriteData('*');
  247.                                            // WriteData(num+0x30);        //明码显示
  248.                                                         number++;
  249.                                                 }
  250.                                                 if(number==6)//输入六位以后进行密码校验
  251.                                                 {  //如果管理员密码正确,进入添加指纹,删除指纹,收到开锁,修改密码界面
  252.                                                          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]))
  253.                                                          {     
  254.                                                                      key_flag=55;
  255.                                                                      admin_dispay();//进入签到页面
  256.                      err_admin=3;
  257.                                                                                   num=0XFF;
  258.                      init_shuju();                                                         
  259.                                                          }
  260.                                                          else//管理员密码错误
  261.                                                              {   
  262.                                                                                 
  263.                                                                                         PutStr(1,0,table24);//显示输入密码错误
  264.                       PutStr(3,0,table12);                                                                                 
  265.                                                                                         while((keynum()>=16)&&(err_admin!=0));
  266.                                                                                         init_dispay();//初始化界面
  267.                       number=0;
  268.                       key_flag=0;                                                                                 
  269.                                                                          }
  270.                               }
  271.                                                 if((num=='B')&&(number>0))
  272.                                                 {  
  273.                                                         number--;
  274.                                                         WriteCommand(0x88+number);                //指定第三行显示位置
  275.                                             WriteData(' ');        
  276.                                                 }
  277.                                                 
  278.                           
  279.                  }
  280.                  if(key_flag==55)//进入签到指纹巡查
  281.                  {      num=coding(num);//转换成可以识别的
  282.                               if(num=='D')//按下就进入开始上课
  283.                                                 {
  284.                                                          key_flag=56;
  285.                                                          PutStr(3,0,table29);
  286.                                                 }
  287.                                      if(wake==1)//如果有手指按下
  288.                                                 {
  289.                                                         if(check()==1)//进行指纹匹配
  290.                                                                  {   err_admin=3;
  291.                                                                                  err_user=3;
  292.                                                                                  LcmClearTXT();//清屏
  293.                                                                                  PutStr(1,0,table11);
  294.                                                                                  PutStr(2,0,table13);
  295.                                                                                  WriteCommand(0x88+5);                //指定第三行显示位置
  296.                                                                                  WriteData(' ');
  297.                                                                            zz=id%256;
  298.                                                                            table_qiandao[zz]=0x01;
  299.                                                                            id++;
  300.                                                                                  WriteData(id/100+0x30);
  301.                                                                                  WriteData(id%100/10+0x30);
  302.                                                                                  WriteData(id%10+0x30);
  303.                      
  304. //                           WriteData(table_qiandao[zz]%100/10+0x30);
  305. //                                                                                 WriteData(table_qiandao[zz]%10+0x30);                                                                                 
  306.                                                                                  relay=0;
  307.                                                                                  Delay(80);
  308.                                                                                  relay=1;
  309.                                                                                  Delay(20);
  310.                                                                                  PutStr(3,0,table12);               
  311.                                                                                  number=0;
  312.                                                                                  key_flag=55;
  313.                                                                                  admin_dispay();//回到初始界面
  314.                                                                                  num=0xff;
  315.                                                                                  
  316.                                                                  }
  317.                                                 }
  318.                  }
  319.                   if(key_flag==56)//迟到的
  320.                  {      num=coding(num);//转换成可以识别的
  321.                               if(num=='D')//按下就进入开始上课
  322.                                                 {
  323.                                                          key_flag=0;
  324.                                                          number=0;
  325.                                                          init_dispay();
  326.                                                 }
  327.                                      if(wake==1)//如果有手指按下
  328.                                                 {
  329.                                                         if(check()==1)//进行指纹匹配
  330.                                                                  {  
  331.                                                                                  LcmClearTXT();//清屏
  332.                                                                                  PutStr(1,0,table11);
  333.                                                                                  PutStr(2,0,table13);
  334.                                                                                  WriteCommand(0x88+5);                //指定第三行显示位置
  335.                                                                                  WriteData(' ');
  336.                                                                            zz=id%256;
  337.                                                                            table_qiandao[zz]=table_qiandao[zz]+0x02;
  338.                                                                            id++;
  339.                                                                                  WriteData(id/100+0x30);
  340.                                                                                  WriteData(id%100/10+0x30);
  341.                                                                                  WriteData(id%10+0x30);        
  342.                                                                         
  343. //                                                                           WriteData(table_qiandao[zz]%100/10+0x30);
  344. //                                                                                 WriteData(table_qiandao[zz]%10+0x30);                 
  345.                                                                                  relay=0;
  346.                                                                                  Delay(80);
  347.                                                                                  relay=1;
  348.                                                                                  Delay(20);
  349.                                                                                  PutStr(3,0,table12);               
  350.                                                                                  number=0;
  351.                                                                                  key_flag=56;
  352.                                                                                  admin_dispay();//回到初始界面
  353.                                                                                  PutStr(3,0,table29);
  354.                                                                                  num=0xff;
  355.                                                                  }
  356.                                                 }
  357.                  }
  358.                  
  359. }
  360. void main()        
  361. {  
  362.         for(i=0;i<6;i++)//读取存储器中的密码
  363.      {
  364.                           now_code[i]=read_add(20+i);
  365.               Delay(5);
  366.                  }        
  367.          for(i=0;i<6;i++)
  368.                  {
  369.                           if(now_code[i]>9)
  370.                                 {
  371.                                          i=10;
  372.                                          break;
  373.                                 }
  374.                  }
  375.          if(i>9)//设置初始化密码
  376.          
  377.          {
  378.                     for(i=0;i<6;i++)
  379.                                  {
  380.                                                 now_code[i]=init_code[i];
  381.                                                 Delay(5);
  382.                                  }        
  383.          }                                                               
  384.                              
  385.    LcmInit();//初始化12864
  386.          
  387.          
  388.          
  389.          jishu=byte_read(0x2200);
  390. //         WriteCommand(0x88);        
  391. //         WriteData(jishu/10+0x30);
  392. //         WriteData(jishu%10+0x30);
  393. //           Delay(30);
  394. //           Delay(50);
  395.          init_dispay();//进入初始化显示界面
  396.    UART_Init();        //初始化串口9600
  397.          init_shuju();
  398.          while(1)
  399.          {  
  400.                   key();

  401.          }
  402. }
复制代码

所有资料51hei附件下载:
指纹考勤.7z (1.51 MB, 下载次数: 77)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏6 分享淘帖 顶3 踩
回复

使用道具 举报

沙发
ID:1064915 发表于 2024-3-28 11:25 | 只看该作者
基于51单片机的指纹考勤机源程序+PCB文件+原理图等设计资料
http://www.51hei.com/bbs/dpj-156176-1.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表