基于51单片机的指纹锁系统设计
在现代社会,随着科技的不断进步,家庭安全变得越来越重要。传统的机械锁由于安全性低,已经不能满足人们对家庭安全的需求。因此,我们设计了一款基于51单片机的指纹锁系统,该系统结合了指纹识别技术和密码锁的工作原理,提供了一种安全可靠、操作便捷的解决方案。
实物图:
系统概述
本指纹锁系统以STC89C52单片机为核心,辅以AS608指纹模块、L298N电机驱动芯片、LCD1602显示屏等模块。系统通过指纹验证或密码输入实现开锁功能,具有操作简便、安全性高的特点。LCD显示屏用于显示系统状态和用户操作指引,而L298N芯片则用于驱动锁具的机械部分。
硬件设计
51单片机
51单片机是整个系统的核心,负责处理所有的逻辑控制和数据处理。STC89C52单片机具有足够的I/O端口,可以连接多个外部设备,同时具备内部Flash存储器,便于程序的存储和运行。
AS608指纹模块
AS608指纹模块负责指纹的采集和识别。该模块通过光学传感器捕捉用户的指纹图像,并通过内置算法进行特征提取和比对。模块通过串口与单片机通信,发送和接收控制指令。
L298N电机驱动芯片
L298N芯片用于驱动锁具的电机,实现锁舌的开启和关闭。该芯片可以接收单片机的控制信号,驱动电机正转或反转,从而控制锁具的开闭状态。
LCD1602显示屏
LCD1602显示屏用于显示系统状态和用户操作指引。它能够显示多行文本信息,帮助用户了解当前的操作状态,如指纹验证成功、密码输入错误等提示信息。
软件设计
软件部分主要包括指纹模块的驱动程序、用户界面的控制程序、密码管理程序和主控制程序。
指纹模块驱动程序
//AS608Ö¸ÎÆÄ£¿é volatile unsigned char AS608_RECEICE_BUFFER[32]; //volatile:ϵͳ×ÜÊÇÖØдÓËüËùÔÚµÄÄÚ´æ¶ÁÈ¡Êý¾Ý£¬¼´Ê¹ËüÇ°ÃæµÄÖ¸Áî¸Õ¸Õ´Ó¸Ã´¦¶ÁÈ¡¹ýÊý¾Ý //FINGERPRINTͨÐÅÐÒ鶨Òå code unsigned char AS608_Get_Device[10] ={0x01,0x00,0x07,0x13,0x00,0x00,0x00,0x00,0x00,0x1b};//¿ÚÁîÑéÖ¤ code unsigned char AS608_Pack_Head[6] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF}; //ÐÒé°üÍ· code unsigned char AS608_Get_Img[6] = {0x01,0x00,0x03,0x01,0x00,0x05}; //»ñµÃÖ¸ÎÆͼÏñ code unsigned char AS608_Get_Templete_Count[6] ={0x01,0x00,0x03,0x1D,0x00,0x21 }; //»ñµÃÄ£°æ×ÜÊý code unsigned char AS608_Search[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x03,0xE7,0x00,0xF8}; //ËÑË÷Ö¸ÎÆËÑË÷·¶Î§0 - 999,ʹÓÃBUFFER1ÖеÄÌØÕ÷ÂëËÑË÷ code unsigned char AS608_Search_0_9[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x13,0x00,0x21}; //ËÑË÷0-9ºÅÖ¸ÎÆ code unsigned char AS608_Img_To_Buffer1[7]={0x01,0x00,0x04,0x02,0x01,0x00,0x08}; //½«Í¼Ïñ·ÅÈëµ½BUFFER1 code unsigned char AS608_Img_To_Buffer2[7]={0x01,0x00,0x04,0x02,0x02,0x00,0x09}; //½«Í¼Ïñ·ÅÈëµ½BUFFER2 code unsigned char AS608_Reg_Model[6]={0x01,0x00,0x03,0x05,0x00,0x09}; //½«BUFFER1¸úBUFFER2ºÏ³ÉÌØÕ÷Ä£°æ code unsigned char AS608_Delete_All_Model[6]={0x01,0x00,0x03,0x0d,0x00,0x11};//ɾ³ýÖ¸ÎÆÄ£¿éÀïËùÓеÄÄ£°æ volatile unsigned char AS608_Save_Finger[9]={0x01,0x00,0x06,0x06,0x01,0x00,0x0B,0x00,0x19};//½«BUFFER1ÖеÄÌØÕ÷Âë´æ·Åµ½Ö¸¶¨µÄλÖà //code unsigned char AS608_num_of_finger_in_lib1[7]={0x01,0x00,0x04,0x1F,0x00,0x00,0x24};//²é¿´Ö¸ÎÆ¿âµÄÃüÁî //code unsigned char AS608_num_of_finger_in_lib2[7]={0x01,0x00,0x04,0x1F,0x01,0x00,0x25}; //code unsigned char AS608_num_of_finger_in_lib3[7]={0x01,0x00,0x04,0x1F,0x02,0x00,0x26}; //code unsigned char AS608_num_of_finger_in_lib4[7]={0x01,0x00,0x04,0x1F,0x03,0x00,0x27}; //·¢ËÍ°üÍ· void AS608_Cmd_Send_Pack_Head(void) { int i; for(i=0;i<6;i++) //°üÍ· Uart_Send_Byte(AS608_Pack_Head[i]); } //·¢ËÍÖ¸Áî void AS608_Cmd_Check(void) { int i=0; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<10;i++) Uart_Send_Byte(AS608_Get_Device[i]); } //½ÓÊÕ·´À¡Êý¾Ý»º³å void AS608_Receive_Data(unsigned char ucLength) { unsigned char i; for (i=0;i<ucLength;i++) AS608_RECEICE_BUFFER[i] = Uart_Receive_Byte(); } //FINGERPRINT_»ñµÃÖ¸ÎÆͼÏñÃüÁî void AS608_Cmd_Get_Img(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<6;i++) //·¢ËÍÃüÁî 0x1d Uart_Send_Byte(AS608_Get_Img[i]); } //½«Í¼Ïñת»»³ÉÌØÕ÷Âë´æ·ÅÔÚBuffer1ÖÐ void FINGERPRINT_Cmd_Img_To_Buffer1(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<7;i++) //·¢ËÍÃüÁî ½«Í¼Ïñת»»³É ÌØÕ÷Âë ´æ·ÅÔÚ CHAR_buffer1 Uart_Send_Byte(AS608_Img_To_Buffer1[i]); } //½«Í¼Ïñת»»³ÉÌØÕ÷Âë´æ·ÅÔÚBuffer2ÖÐ void FINGERPRINT_Cmd_Img_To_Buffer2(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<7;i++) //·¢ËÍÃüÁî ½«Í¼Ïñת»»³É ÌØÕ÷Âë ´æ·ÅÔÚ CHAR_buffer1 Uart_Send_Byte(AS608_Img_To_Buffer2[i]); } //ËÑË÷È«²¿Óû§999ö void AS608_Cmd_Search_Finger(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<11;i++) Uart_Send_Byte(AS608_Search[i]); } //ת»»³ÉÌØÕ÷Âë void AS608_Cmd_Reg_Model(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<6;i++) Uart_Send_Byte(AS608_Reg_Model[i]); } //ɾ³ýÖ¸ÎÆÄ£¿éÀïµÄËùÓÐÖ¸ÎÆÄ£°æ void FINGERPRINT_Cmd_Delete_All_Model(void) { unsigned char i; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<6;i++) //ÃüÁîɾ³ýÖ¸ÎÆÄ£°æ Uart_Send_Byte(AS608_Delete_All_Model[i]); } //±£´æÖ¸ÎÆ void AS608_Cmd_Save_Finger( unsigned int storeID ) { unsigned long temp = 0; unsigned char i; AS608_Save_Finger[5] =(storeID&0xFF00)>>8; AS608_Save_Finger[6] = (storeID&0x00FF); for(i=0;i<7;i++) //¼ÆËãУÑéºÍ temp = temp + AS608_Save_Finger[i]; AS608_Save_Finger[7]=(temp & 0x00FF00) >> 8; //´æ·ÅУÑéÊý¾Ý AS608_Save_Finger[8]= temp & 0x0000FF; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<9;i++) Uart_Send_Byte(AS608_Save_Finger[i]); //·¢ËÍÃüÁî ½«Í¼Ïñת»»³É ÌØÕ÷Âë ´æ·ÅÔÚ CHAR_buffer1 } //²é¿´µ±Ç°Ö¸ÎÆ¿âÖÐÖ¸ÎÆÄ£°åÊý int AS608_number_of_fingers() { int num=1;//ĬÈÏÄ£°å¿âÖÐÓÐÒ»¸öÄ£°å uchar i=0; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<6;i++) Uart_Send_Byte(AS608_Get_Templete_Count[i]); AS608_RECEICE_BUFFER[9]=1;//·½±ãºóÐøÅжÏÊÇ·ñ½ÓÊճɹ¦ AS608_Receive_Data(14);//½ÓÊÕÊý¾Ý if(AS608_RECEICE_BUFFER[9]==0) //½ÓÊճɹ¦ num=AS608_RECEICE_BUFFER[10]*256+AS608_RECEICE_BUFFER[11];//Æ´½ÓÄ£°å×ܸöÊý return num; } //ÁíÒ»ÖÖ·½·¨²é¿´Ö¸ÎÆ¿âÖÐÊÇ·ñÓÐÄ£°å //±¾À´Ó¦¸Ã²é¿´ËùÓÐ1000¸öÄ£°åλÖÃÊÇ·ñ´æÔÚÄ£°å£¬µ«Ò»°ãÖ»Óõõ½Ç°256¸ö£¬¹Ê´Ó¼ò /* bit AS608_notEmpty() { bit exist=0; char i=0; AS608_Cmd_Send_Pack_Head(); //·¢ËÍͨÐÅÐÒé°üÍ· for(i=0;i<7;i++) { Uart_Send_Byte(AS608_num_of_finger_in_lib1[i]); } AS608_Receive_Data(10);//½ÓÊÕÇ°10byteÊý¾Ý,³ýµÚ10×Ö½ÚµÄÈ·ÈÏÂëÍ⣬ÆäÓàÈ«²¿¶ªÆú if(AS608_RECEICE_BUFFER[9]==0) //½ÓÊճɹ¦ { AS608_Receive_Data(32);//½ÓÊÕºóÐø32byteÊý¾Ý£¬´Ë¼´0~255¸öÄ£°åΪÊÇ·ñ´æÔÚÖ¸ÎÆÄ£°åµÄÊý¾Ý for(i=0;i<32;i++)//²é¿´Õâ32byteÊý¾Ý£¬ÈκÎÒ»¸öλÖôæÔÚÄ£°åÔò·µ»ØֵΪÕ棬·ñÔòΪ¼Ù { if(AS608_RECEICE_BUFFER[i]) exist=1; } return exist; } } */ //Ìí¼ÓÖ¸ÎÆ void AS608_Add_Fingerprint() { unsigned char id_show[]={0,0,0}; LCD1602_WriteCMD(0x01); //ÇåÆÁ while(1) { LCD1602_Display(0x80," Add finger ",0,16); LCD1602_Display(0xc0," ID is ",0,16); //°´·µ»Ø¼üÖ±½Ó»Øµ½Ö÷²Ëµ¥ if(KEY_CANCEL == 0) { Delay_ms(5); if(KEY_CANCEL == 0) { while(KEY_CANCEL==0); break; } } //°´Çл»¼üÖ¸ÎÆiDÖµ¼Ó1 if(KEY_DOWN == 0) { Delay_ms(5); if(KEY_DOWN == 0) { while(KEY_DOWN==0); if(finger_id == 1000) finger_id = 1;//±£Áô0ºÅ²»±»¸²¸Ç else finger_id = finger_id + 1; } } //Ö¸ÎÆiDÖµÏÔʾ´¦Àí LCD1602_WriteCMD(0xc0+10); LCD1602_Display_Number(finger_id); //°´È·Èϼü¿ªÊ¼Â¼ÈëÖ¸ÎÆÐÅÏ¢ if(KEY_OK == 0) { Delay_ms(5); if(KEY_OK == 0) { while(KEY_OK==0); LCD1602_Display(0x80," Please finger ",0,16); LCD1602_Display(0xc0," ",0,16); while(KEY_CANCEL == 1) { //°´Ï·µ»Ø¼üÍ˳ö¼Èë·µ»ØfingerIDµ÷Õû״̬ if(KEY_CANCEL == 0) { Delay_ms(5); if(KEY_CANCEL == 0) { while(KEY_CANCEL==0); break; } } AS608_Cmd_Get_Img(); //»ñµÃÖ¸ÎÆͼÏñ AS608_Receive_Data(12); //ÅжϽÓÊÕµ½µÄÈ·ÈÏÂë,µÈÓÚ0Ö¸ÎÆ»ñÈ¡³É¹¦ if(AS608_RECEICE_BUFFER[9]==0) { Delay_ms(100); FINGERPRINT_Cmd_Img_To_Buffer1(); AS608_Receive_Data(12); LCD1602_Display(0x80,"Successful entry",0,16); Beep_Times(1); Delay_ms(1000); LCD1602_Display(0x80," Please finger ",0,16); LCD1602_Display(0xc0," ",0,16); while(1) { if(KEY_CANCEL == 0) { Delay_ms(5); if(KEY_CANCEL == 0) { while(KEY_CANCEL==0); break; } } AS608_Cmd_Get_Img(); //»ñµÃÖ¸ÎÆͼÏñ AS608_Receive_Data(12); //ÅжϽÓÊÕµ½µÄÈ·ÈÏÂë,µÈÓÚ0Ö¸ÎÆ»ñÈ¡³É¹¦ if(AS608_RECEICE_BUFFER[9]==0) { Delay_ms(200); LCD1602_Display(0x80,"Successful entry",0,16); LCD1602_Display(0xc0," ID is ",0,16); //Ö¸ÎÆiDÖµÏÔʾ´¦Àí LCD1602_WriteCMD(0xc0+10); LCD1602_Display_Number(finger_id); FINGERPRINT_Cmd_Img_To_Buffer2(); AS608_Receive_Data(12); AS608_Cmd_Reg_Model();//ת»»³ÉÌØÕ÷Âë AS608_Receive_Data(12); AS608_Cmd_Save_Finger(finger_id); AS608_Receive_Data(12); Beep_Times(1); Delay_ms(1000); finger_id=finger_id+1; break; } } break; } } } } } } //ËÑË÷Ö¸ÎÆ void AS608_Find_Fingerprint() { unsigned int find_fingerid = 0; unsigned char id_show[]={0,0,0}; do { LCD1602_Display(0x80," Please finger ",0,16); LCD1602_Display(0xc0," ",0,16); AS608_Cmd_Get_Img(); //»ñµÃÖ¸ÎÆͼÏñ AS608_Receive_Data(12); //ÅжϽÓÊÕµ½µÄÈ·ÈÏÂë,µÈÓÚ0Ö¸ÎÆ»ñÈ¡³É¹¦ if(AS608_RECEICE_BUFFER[9]==0) { Delay_ms(100); FINGERPRINT_Cmd_Img_To_Buffer1(); AS608_Receive_Data(12); AS608_Cmd_Search_Finger(); AS608_Receive_Data(16); if(AS608_RECEICE_BUFFER[9] == 0) //ËÑË÷µ½ { //½âËø³É¹¦// LCD1602_Display(0x80," Search success ",0,16); LCD1602_Display(0xc0," ID is ",0,16); Beep_Times(1); //Æ´½ÓÖ¸ÎÆIDÊý find_fingerid = AS608_RECEICE_BUFFER[10]*256 + AS608_RECEICE_BUFFER[11]; //Ö¸ÎÆiDÖµÏÔʾ´¦Àí LCD1602_WriteCMD(0xc0+10); LCD1602_Display_Number(find_fingerid); //ÅäÖÃIO¿Ú£¬Ö´ÐпªËø²Ù×÷ if(flag) { P1=0xfe; Delay_ms(OpenTime*100); P1=0xff; //µç¶¯»úֹͣת¶¯ Delay_ms(1000); P1=0xfd; //µç¶¯»ú·´×ª¸´Î» Delay_ms(CloseTime*100);//µç»úÕýת×èÁ¦Ô¶´óÓÚ·´×ª£¬ÐýתÏàͬ½Ç¶Èʱ£¬ÕýתÐèÒª¸ü¶àʱ¼ä P1=0xff; //µç¶¯»úֹͣת¶¯ } flag=1; //ÔÊÐíºóÐøÏà¹Ø²Ù×÷£ºÌí¼Ó»òɾ³ýÖ¸ÎÆÄ£°å break; } else //ûÓÐÕÒµ½ { LCD1602_Display(0x80," Search failed ",0,16); LCD1602_Display(0xc0," ",0,16); Beep_Times(3); } } }while(KEY_CANCEL == 1); } //ɾ³ýËùÓдæÖüµÄÖ¸ÎÆ¿â void AS608_Delete_All_Fingerprint() { unsigned char i=0; LCD1602_Display(0x80," empty all ",0,16); LCD1602_Display(0xc0," Yes or no ? ",0,16); do { if(KEY_OK==0) { Delay_ms(5); if(KEY_OK==0) { while(KEY_OK==0); LCD1602_Display(0x80," emptying ",0,16); LCD1602_Display(0xc0," ",0,16); Delay_ms(300); LCD1602_WriteCMD(0xc0); for(i=0;i<16;i++) { LCD1602_WriteDAT(42);// ¼´'*' Delay_ms(100); } FINGERPRINT_Cmd_Delete_All_Model(); AS608_Receive_Data(12); LCD1602_Display(0x80," All empty ",0,16); LCD1602_Display(0xc0," ",0,16); Beep_Times(3); break; } } }while(KEY_CANCEL==1); }
该程序负责与AS608指纹模块进行通信,实现指纹的采集、特征提取和比对。程序通过串口发送指令,控制指纹模块的工作状态,并接收模块返回的比对结果。
用户界面控制程序
//Òº¾§·±Ã¦¼ì²â void LCD1602_CheckBusy(void) { uchar busy; DataPort=0xff; RS=0; RW=1; do { EN=1; busy=DataPort; EN=0; }while(busy&0x80); } //Òº¾§³õʼ»¯º¯Êý void LCD1602_Init(void) { Delay_ms(15); //ÉϵçÑÓʱ15ms LCD1602_WriteCMD(0x38); //дÏÔʾָÁî(²»¼ì²âæÐźÅ) Delay_ms(5); LCD1602_CheckBusy(); LCD1602_WriteCMD(0x38); //дÏÔʾָÁî LCD1602_CheckBusy(); LCD1602_WriteCMD(0x01); //ÇåÆÁ LCD1602_CheckBusy(); LCD1602_WriteCMD(0x06); //ÏÔʾ¹â±êÒƶ¯ÉèÖà LCD1602_CheckBusy(); LCD1602_WriteCMD(0x0c); //ÏÔʾ¿ª¼°¹â±êÉèÖà } //Òº¾§ÏÔʾº¯Êý Èë¿Ú²ÎÊý£ºaddrÆðʼµØÖ·£¬pointerÖ¸ÕëµØÖ·£¬indexϱ꣬num¸öÊý void LCD1602_Display(unsigned char addr,unsigned char* pointer,unsigned char index,unsigned char num) { unsigned char i; LCD1602_CheckBusy(); //ÅжÏæÐźŠLCD1602_WriteCMD(addr); //дÈëµØÖ· for(i=0;i<num;i++) //дÈëÊý¾Ý { LCD1602_CheckBusy(); //ÅжÏæÐźŠLCD1602_WriteDAT(pointer[index+i]);//дÈëÊý¾Ý } } //Òº¾§ÏÔʾËÄλÊý void LCD1602_Display_Number(unsigned int num) { if(num/1000) LCD1602_WriteDAT(num/1000+48); LCD1602_WriteDAT(num%1000/100+48); LCD1602_WriteDAT(num%100/10+48); LCD1602_WriteDAT(num%10+48); }
该程序负责控制LCD1602显示屏,显示系统状态和用户操作指引。程序根据系统的工作状态,动态更新显示内容,提供清晰的用户交互界面。
主控制程序
//Ö÷º¯Êý void main() { finger_id=0; I2C_init();//I2C³õʼ»¯ LCD1602_Init(); //³õʼ»¯Òº¾§ LCD1602_Display(0x80," Designer : lsy ",0,16); //Òº¾§¿ª»úÏÔʾ½çÃæ Delay_ms(500); LCD1602_Display(0x80,"Fingerprint Test",0,16); //Òº¾§¿ª»úÏÔʾ½çÃæ Uart_Init(); //³õʼ»¯´®¿Ú Key_Init(); //³õʼ»¯°´¼ü Delay_ms(200); //ÑÓʱ200MS£¬µÈ´ýÖ¸ÎÆÄ£¿é¸´Î» Device_Check(); //У¶ÔÖ¸ÎÆÄ£¿éÊÇ·ñ½ÓÈëÕýÈ·£¬Òº¾§×ö³öÏàÓ¦µÄÌáʾ Delay_ms(1000); //¶Ô½Ó³É¹¦½çÃæÍ£ÁôÒ»¶¨Ê±¼ä OpenTime=I2C_ReadData(254);//´ÓAT24C02µÚ254¸öµ¥ÔªÖжÁÈ¡Êý¾Ý CloseTime=I2C_ReadData(250);//´ÓAT24C02µÚ255¸öµ¥ÔªÖжÁÈ¡Êý¾Ý while(1) { /**************½øÈëÖ÷¹¦ÄܽçÃæ****************/ LCD1602_Display(0x80," search finger ",0,16); //µÚÒ»ÅÅÏÔʾËÑË÷Ö¸ÎÆ LCD1602_Display(0xc0," Add delete",0,16); //Ìí¼ÓºÍɾ³ýÖ¸ÎÆ switch(local_date) { case 0: LCD1602_Display(0x80, " *",0,2); LCD1602_Display(0xc0, " ",0,2); LCD1602_Display(0xc0+8," ",0,2); break; case 1: LCD1602_Display(0x80, " ",0,2); LCD1602_Display(0xc0, " *",0,2); LCD1602_Display(0xc0+8," ",0,2); break; case 2: LCD1602_Display(0x80, " ",0,2); LCD1602_Display(0xc0, " ",0,2); LCD1602_Display(0xc0+8," *",0,2); break; } //È·Èϼü if(KEY_OK == 0) { Delay_ms(5); if(KEY_OK == 0) { while(KEY_OK == 0);//µÈ´ýËÉ¿ª°´¼ü switch(local_date) { case 0: //ËÑË÷Ö¸ÎÆ flag=1; AS608_Find_Fingerprint(); break; case 1: //Ìí¼ÓÖ¸ÎÆ flag=1; //flag=1£¬ÈôÖ¸ÎÆ¿âΪ¿Õ£¬Ôò¿ÉÒÔÖ±½ÓÌí¼ÓÖ¸ÎÆ if(AS608_number_of_fingers()) { flag=0;//flagÖÃ0ÓÉÁ½ÖØ×÷Ó㺠//1¡¢Ö¸ÎÆ¿âÖÐÒÑÓÐÖ¸ÎÆ£¬ÔòÐèÒªËÑË÷Æ¥Åä³É¹¦£¬ÓÉAS608_Find_Fingerprint()½«flagÖÃ1£¬²ÅÄÜÌí¼ÓÖ¸ÎÆ //2¡¢flag=0£¬ÔòÔÚËÑË÷Ö¸ÎƳɹ¦ºó²»Ö´ÐпªËø²Ù×÷ AS608_Find_Fingerprint(); } if(flag) AS608_Add_Fingerprint(); break; case 2: //Çå¿ÕÖ¸ÎÆ flag=0; //1¡¢ÔÚËÑË÷Ö¸ÎƳɹ¦ºó²»Ö´ÐпªËø²Ù×÷£»2¡¢ÈôËÑË÷²»³É¹¦£¬²»Ö´ÐÐÇå¿Õ²Ù×÷ AS608_Find_Fingerprint();//ËÑË÷Æ¥Åä³É¹¦ºó£¬º¯ÊýÄÚ²¿½«flagÖÃ1£¬²ÅÄÜÇå¿ÕÖ¸ÎÆ¿â if(flag) AS608_Delete_All_Fingerprint(); break; } } } //Çл»¼ü if(KEY_DOWN == 0) { Delay_ms(5); if(KEY_DOWN == 0) { while(KEY_DOWN == 0); //µÈ´ýËÉ¿ª°´¼ü local_date++; if(local_date==3) local_date=0; } } //°´Key_Mode½øÈëʱ¼äµ÷Õûģʽ if (KEY_Mode == 0) { Delay_ms(5); if(KEY_Mode == 0) { while(KEY_Mode == 0); flag=0; AS608_Find_Fingerprint(); if(flag) Refresh_time(); } } Delay_ms(100); //ÑÓʱÅжÏ100MS¼ì²âÒ»´Î } }
主控制程序负责协调各个模块的工作,实现系统的开锁逻辑。当用户进行指纹验证或密码输入时,主程序会调用相应的驱动程序,根据验证结果控制L298N芯片,实现锁具的开闭。
系统功能
本指纹锁系统具备以下功能:
- 指纹开锁:用户可以通过验证指纹来开锁。
- 状态显示:LCD显示屏会实时显示系统状态,如开锁成功、密码错误等。
- 安全报警:如果连续多次输入错误的指纹,系统会触发报警。
结论
基于51单片机的指纹锁系统设计,不仅提高了家庭安全的水平,也为用户提供了便捷的开锁方式。通过结合现代电子技术和生物识别技术,该系统在保证安全性的同时,也提供了良好的用户体验。随着技术的不断进步,未来指纹锁系统将更加智能化、多样化,为家庭安全提供更加可靠的保障。
原理图
PCB设计
希望你喜欢这个项目,并在构建过程中找到乐趣!如果你有任何问题或需要帮助,欢迎在评论区交流。
作者:Svan.
注意:本博文为不得在未经本人同意进行转载或者二次创作,违者必究!!!