这是一个基于STC89C52的指纹识别和键盘密码锁,里面包括程
1.当要想从标志位中退出来就一定要知道程序当前在哪个标志位中读取,然后就是在这个里面设定退出方可,
否则是不能使用的,相当于是没有一样。
单片机源程序如下:
- /*************************************************************************************
- 密码锁,可以改个人密码和管理员密码的一个基于单片机的锁。
- 按键值码: 1 2 3 set 输入密码只能按0~9,10位确定键,11位取消键(输入密码小
- 4 5 6 ↑ 于8时取消输入的密码),12是时钟功能键,13是时钟“+”,
- 7 8 9 ↓ 14是时钟“-”,15改密码的时候的确定键
- ok 0 c fun
- **************************************************************************************/
- /******************************头文件****************************************/
- #include<reg52.h>
- #include<stdio.h>
- #include<math.H>
- #include"lcd.h"
- #include"ds1302.h"
- #include"keyboard.h"
- #include"delay.h"
- #include"deal.h"
- #include "i2c.h"
- #include "uart.h"
- /*************************宏定义*************************************/
- #define uchar unsigned char
- #define uint unsigned int
- //========================IO口定义==================================//
- sbit s = P2^2; //控制背光
- sbit k2 = P3^2; //
- sbit JDQ_key = P3^7; //继电器控制
- unsigned char flag4,flag5=0,flag8=1,flag1=0,flag_time=0,
- flag_time2=0;flag3=0;
- unsigned char wrongtimes=0,k,p=1,miao=59,t=0,snum=0,
- c=0,up=0,down=0,a=0;
- //===========================密码的初始值==========================//
- unsigned char MIMAword[8]={1,2,3,4,5,6,7,8}; //密码的初始值
- unsigned char G_MIMA[8]={8,8,8,8,8,8,8,8}; //管理员密码,可以更改
- void MIMA_input(); //EEPROM写
- void MIMA_output(); //EEPROM读
- //===========================配置定时器============================//
- void init_conf()
- {
- TH0=(65536-50000)/256; //
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- IT0=1; //跳变沿出发方式(下降沿)
- EX0=1; //打开INT0的中断允许。
- TR1 = 1;
- ET1 = 1;
- }
- //===============================主函数===========================//
- void main()
- {
- unsigned char num,i = 0,j;
- unsigned char temp[8];
-
- unsigned char Ztemp[8]={'1','2','3','4','5','6','7','8'};
- unsigned char Zresponsuccess[4]={0x55,0x11,0x01,0x00};
- unsigned char Zresponfail[]="your command is wrong";
- unsigned char ch[8]={0},z1=0, Znum[8]={0};
- bit Flag;
- /***********************以下是断电后重启的读出EEPROM的数据*******************************/
- //第一次上电先隐去 88888888修改管理员密码 然后取隐用修改后的管理员进入修改个人密码
- G_MIMA[0] = EEPROMread_add(11,19);
- delay(20);
- G_MIMA[1] = EEPROMread_add(12,20);
- delay(20);
- G_MIMA[2] = EEPROMread_add(13,21);
- delay(20);
- G_MIMA[3] = EEPROMread_add(14,22);
- delay(20);
- G_MIMA[4] = EEPROMread_add(15,23);
- delay(20);
- G_MIMA[5] = EEPROMread_add(16,24);
- delay(20);
- G_MIMA[6] = EEPROMread_add(17,25);
- delay(20);
- G_MIMA[7] = EEPROMread_add(18,26);
- delay(20);
- /***********************以上是断电重启后读出EEPROM里面的数据*********************************/
- s=0; //背光控制,上电时低电平将三极管导通
- JDQ_key=1; //继电器驱动装置,低电平(三极管不导通,则继电器工作,则锁关
- //换为J3Y后更改电平
- init_conf(); //配置定时器
- LCD12864_Init(); //12864初始化
- Ds1302Init(); //1302初始化
- UartInit(); //串口初始化
- LCD12864_SetWindow(0,2,"欢迎光临"); //第一行显示信息
- LCD12864_SetWindow(1,1,"华北科技学院"); //第二行显示信息
- LCD12864_SetWindow(2,1,"单片机实验室"); //第三行显示信息
- LCD12864_SetWindow(3,1,"输入八位密码"); //第四行显示信息
- Delay3000ms();
- LCD12864_SetWindow(0,0," ");
- LCD12864_SetWindow(1,0," ");
- while(1)
- {
- //=============================串口处理函数=====================================//
- while(UART_Re_N(8,ch))
- {
- for(z1=0;z1<8;z1++)
- {
- Znum[z1]= ch[z1];
- }
- if((Ztemp[0]==Znum[0])&&(Ztemp[1]==Znum[1]))
- {
- UART_Send_Strs(Zresponsuccess);
- UART_Send_Enter();
- JDQ_key=0;//三极管不导通,则继电器不工作,则锁开
- LCD12864_SetWindow(3,0," ");
- //经测试发现正确的“正”不能正常显示,
- //需要打补丁才能显示,“正”的内码缺失,
- //运用GBK国标扩展码显示如下
- LCD12864_WriteCmd(0x98+2);
- LCD12864_WriteData(0xc3);//密
- LCD12864_WriteData(0xdc);
- LCD12864_WriteData(0xc2);//码
- LCD12864_WriteData(0xeb);
- LCD12864_WriteData(0xd5);//正
- LCD12864_WriteData(0xfd);
- LCD12864_WriteData(0xc8);//确
- LCD12864_WriteData(0xb7);
- Delay5000ms();//5s后把继电器导通,使锁锁上
- LCD12864_SetWindow(2,0," ");
- LCD12864_SetWindow(3,0," ");//清除该行
- LCD12864_SetWindow(2,1,"单片机实验室"); //写入第3行信息
- LCD12864_SetWindow(3,1,"输入八位密码");
- JDQ_key=1; //三极管导通,则继电器工作,则锁关
- }
- else
- {
- UART_Send_Strs(Zresponfail);
- UART_Send_Enter();
- }
- }
- if(flag3 == 1)
- {
- MIMA_input();//修改密码
- }
- else
- {
- if(flag_time2==0)
- {
- p=1;
- LCD12864_WriteCmd(0x0c);
- LCD12864_SetWindow(2,1,"单片机实验室"); //第三行显示信息
- Ds1302Write(0x90,0xa9); //涓细充电
- Ds1302ReadTime(); //时间读取
- LcdDisplaytime(); //显示时间
- delay(5);
- week(); //显示星期
- delay(5);
- displayday(); //显示日期
- delay(5);
-
- while(UART_Re_N(8,ch)) //串口处理
- {
- for(z1=0;z1<8;z1++)
- {
- Znum[z1]= ch[z1];
- }
- if((Ztemp[0]==Znum[0])&&(Ztemp[1]==Znum[1]))
- {
- UART_Send_Strs(Zresponsuccess);
- UART_Send_Enter();
- JDQ_key=0;//三极管不导通,则继电器不工作,则锁开
- LCD12864_SetWindow(3,0," ");
- //经测试发现正确的“正”不能正常显示,
- //需要打补丁才能显示,“正”的内码缺失,
- //运用GBK国标扩展码显示如下
- LCD12864_WriteCmd(0x98+2);
- LCD12864_WriteData(0xc3);//密
- LCD12864_WriteData(0xdc);
- LCD12864_WriteData(0xc2);//码
- LCD12864_WriteData(0xeb);
- LCD12864_WriteData(0xd5);//正
- LCD12864_WriteData(0xfd);
- LCD12864_WriteData(0xc8);//确
- LCD12864_WriteData(0xb7);
- Delay5000ms();//5s后把继电器导通,使锁锁上
- LCD12864_SetWindow(2,0," ");
- LCD12864_SetWindow(3,0," ");//清除该行
- LCD12864_SetWindow(2,1,"单片机实验室"); //写入第3行信息
- LCD12864_SetWindow(3,1,"输入八位密码");
- JDQ_key=1; //三极管导通,则继电器工作,则锁关
- }
- else
- {
- UART_Send_Strs(Zresponfail);
- UART_Send_Enter();
- }
- }
-
- num=KeyPro();
- delay(5); //按键扫描
- if(num!=0xff)
- {
- if(num==12) //设置时间的标志位
- flag_time=1;
- if(num>=0&&num<10) //设置密码数位为0~9有效
- {
- if(i==0)
- {
- LCD12864_SetWindow(3,0," ");//显示空,相当于清屏
- }
- if(i<8) //密码是8位,大于8位时不再输入按键值
- {
- temp[i]=num;
- LCD12864_char(3,i,'*'); //显示*号
- }
- i++;
- }
- if(num==11) //取消清零键,只有密码少于8位时有效
- {
- i=0; //计数清零
- LCD12864_SetWindow(3,0," ");
- LCD12864_SetWindow(3,1,"输入八位密码");
- }
- while(i==8)
- {
- num=KeyPro();
- if(num==10) //确定键
- i=9;
- }
- if(i==9) //8位后的按键不输入数值
- {
- i=0; //计数器复位
- Flag=1; //先把比较位置1
- flag4 = 1;
- MIMA_output(); // p = 1
- for(k = 0; k < 8; k++)
- flag4=flag4&&((temp[k]==G_MIMA[k])); //管理员密码比较
- if(flag4) //flag4为管理员的更改密码
- {
- unsigned char m;
- flag8 = 0;
- flag5 = 1;
- LCD12864_WriteCmd(0x01);
- LCD12864_SetWindow(0,2,"修改密码");
- LCD12864_SetWindow(1,0,"1.个人密码修改");
- LCD12864_SetWindow(2,0,"2.管理员密码修改"); //管理员密码正确显示的信息
- LCD12864_SetWindow(1,0,"");
- LCD12864_WriteCmd(0x0f); //显示光标
- m=KeyPro();
- delay(50);
- m=0XFF;
- while(m != 10) //改密码按键
- {
- m=0XFF;
- while(m==0XFF)
- {
- m=KeyPro();
- if( m == 14) //下
- {
- p = 0; //管理员密码修改的标志位
- LCD12864_SetWindow(2,0,"");
- LCD12864_WriteCmd(0x0f);
- }
- if( m == 13) //上
- {
- p = 1; //个人密码修改的标志位
- LCD12864_SetWindow(1,0,"");
- LCD12864_WriteCmd(0x0f);
- }
- }
- }
- k2=0; //可以进入改密码中断
- MIMA_input();
- flag8 = 0;
- }
- for(j=0;j<8;j++) //循环比较8个数值,如果有一个不等 则最终Flag值为0
- Flag=Flag&&(temp[j]==MIMAword[j]);//比较输入值和已有密码
- if(Flag) //如果比较全部相同,标志位置1
- {
- wrongtimes=0;
- JDQ_key=0;//三极管不导通,则继电器不工作,则锁开
- LCD12864_SetWindow(3,0," ");
- //经测试发现正确的“正”不能正常显示,
- //需要打补丁才能显示,“正”的内码缺失,
- //运用GBK国标扩展码显示如下
- LCD12864_WriteCmd(0x98+2);
- LCD12864_WriteData(0xc3);//密
- LCD12864_WriteData(0xdc);
- LCD12864_WriteData(0xc2);//码
- LCD12864_WriteData(0xeb);
- LCD12864_WriteData(0xd5);//正
- LCD12864_WriteData(0xfd);
- LCD12864_WriteData(0xc8);//确
- LCD12864_WriteData(0xb7);
- Delay5000ms();//5s后把继电器导通,使锁锁上
- LCD12864_SetWindow(2,0," ");
- LCD12864_SetWindow(3,0," ");//清除该行
- LCD12864_SetWindow(2,1,"单片机实验室"); //写入第3行信息
- LCD12864_SetWindow(3,1,"输入八位密码");
- JDQ_key=1; //三极管导通,则继电器工作,则锁关
- }
- else
- flag1=1;
- if(flag8)
- {
- if(flag1==1)
- {
- flag1=0;
- LCD12864_SetWindow(3,0," ");
- LCD12864_SetWindow(2,0," ");
- LCD12864_SetWindow(2,2,"密码错误"); //密码错误,提示重新输入
- LCD12864_SetWindow(3,2,"重新输入");
- Delay2000ms();
- wrongtimes++; //错误次数累加
- LCD12864_SetWindow(2,0," ");//清除该行
- LCD12864_SetWindow(3,0," ");
- LCD12864_SetWindow(2,1,"单片机实验室");
- LCD12864_SetWindow(3,1,"输入八位密码");
- if(wrongtimes>=5) //当错误达到n次后
- {
- TR0=1; //启动定时
- wrongtimes=0; //清零
- LCD12864_SetWindow(2,0," ");//清除该行
- LCD12864_SetWindow(3,0," ");//清除该行
- nop();
- LCD12864_SetWindow(2,2,"错误五次");
- LCD12864_SetWindow(3,2,"等59秒");
- while(TR0); //锁定屏幕
- }
- }
- }
- }
- }
- }
- }//flag3的else
- if(flag_time==1)//显示的是更改时间的页面
- {
- i = 0;
- flag_time=0; //要将标志位置零,不然会一直扫描
- flag_time2=1;
- LCD12864_WriteCmd(0x01);//清屏
- LCD12864_SetWindow(0,1,"修改时间日期");delay(10);//第一行显示内容
- week1();delay(10); //星期
- displayday1();delay(10);//日期
- LcdDisplaytime1();delay(10);//时间
- }
- if(flag_time2==1)
- {
- num=KeyPro();
- if(num==15)//改时间的确定键
- {
- snum=0;//清零0
- //下面将改过的时间写进去
- Ds1302Write(0x80,TIME[0]);delay(10);//秒
- Ds1302Write(0x82,TIME[1]);delay(10);//分
- Ds1302Write(0x84,TIME[2]);delay(10);//时
- Ds1302Write(0x8a,TIME[5]);delay(10);//星期
- Ds1302Write(0x86,TIME[3]);delay(10);//日
- Ds1302Write(0x88,TIME[4]);delay(10);//月
- Ds1302Write(0x8c,TIME[6]);delay(10);//年
- Ds1302Write(0x8E,0x80);
- LCD12864_WriteCmd(0x01);
- LCD12864_WriteCmd(0x0c);
- LCD12864_SetWindow(3,1,"输入八位密码");
- flag_time2=0;//在这里就可以实现退出的功能,因为当
- //flag_time2==1时,程序一直会扫描这里
- }
- if(num==12)
- {
- Ds1302Write(0x8E,0x00); //关闭写保护
- LCD12864_WriteCmd(0x0f);
- delay(10);
- snum++;
- switch(snum)
- {
- case 1: LCD12864_SetWindow(3,2,"调整秒");LCD12864_WriteCmd(0x88+5);break;
- case 2: LCD12864_SetWindow(3,2,"调整分");LCD12864_SetWindow(2,3,"");break;
- case 3: LCD12864_SetWindow(3,2,"调整时");LCD12864_SetWindow(2,1,"");break;
- case 4: LCD12864_SetWindow(3,2,"调整星期");LCD12864_SetWindow(1,7,"");break;
- case 5: LCD12864_SetWindow(3,0," ");
- LCD12864_SetWindow(3,2,"调整日");
- LCD12864_SetWindow(1,5,"");break;
- case 6: LCD12864_SetWindow(3,2,"调整月");LCD12864_SetWindow(1,3,"");break;
- case 7: LCD12864_SetWindow(3,2,"调整年");LCD12864_SetWindow(1,1,"");break;
- case 8:
- {
- snum=0;
- LCD12864_WriteCmd(0x01);
- LCD12864_SetWindow(3,1,"输入八位密码");
- LCD12864_WriteCmd(0x0c);delay(20);
- Ds1302Write(0x80,TIME[0]);delay(10);
- Ds1302Write(0x82,TIME[1]);delay(10);
- Ds1302Write(0x84,TIME[2]);delay(10);
- Ds1302Write(0x8a,TIME[5]);delay(10);
- Ds1302Write(0x86,TIME[3]);delay(10);
- Ds1302Write(0x88,TIME[4]);delay(10);
- Ds1302Write(0x8c,TIME[6]);delay(10);
- Ds1302Write(0x8E,0x80); //打开写保护
- flag_time2=0;
- }break;
- }
- }
- if(snum!=0)
- {
- //*******************************以下是按键按下减的计数******************************************/
- if(num==13)
- {
- LCD12864_WriteCmd(0x0c);
- switch(snum)
- {
- case 1: //秒
- {
- TIME[0]++;
- if((TIME[0]&0x0f)==10)
- {
- TIME[0]&=0xf0;
- TIME[0]+=0x10;
- }
- if(TIME[0]>=0x60)
- TIME[0]=0;
- LCD12864_WriteCmd(0x88+5);
- Ds1302Write(0,'0'+TIME[0]);
- LCD12864_WriteData('0'+TIME[0]/16);//秒
- LCD12864_WriteData('0'+(TIME[0]&0x0f));
- }break;
- case 2: //分
- {
- TIME[1]++;
- if((TIME[1]&0x0f)==10)
- {
- TIME[1]&=0xf0;
- TIME[1]+=0x10;
- }
- if(TIME[1]>=0x60)
- TIME[1]=0;
- LCD12864_WriteCmd(0x88+3);
- Ds1302Write(0,'0'+TIME[1]);
- LCD12864_WriteData('0'+TIME[1]/16);//分
- LCD12864_WriteData('0'+(TIME[1]&0x0f));
- }break;
- case 3: //时
- {
- TIME[2]++;
- if((TIME[2]&0x0f)==10)
- {
- TIME[2]&=0xf0;
- TIME[2]+=0x10;
- }
- if(TIME[2]>=0x24)
- TIME[2]=0;
- LCD12864_WriteCmd(0x88+1);
- Ds1302Write(0,'0'+TIME[2]);
- LCD12864_WriteData('0'+TIME[2]/16);//时
- LCD12864_WriteData('0'+(TIME[2]&0x0f));
- }break;
- case 4: //星期
- {
- TIME[5]++;
- if(TIME[5]>=0x08)//星期最大到7
- TIME[5]=0x01;//最小到1
- LCD12864_WriteCmd(0x90+7);
- Ds1302Write(0,'0'+TIME[5]);
- c=TIME[5];
- switch(c)
- {
- case 1:LCD12864_SetWindow(1,7,"一");break;
- case 2:LCD12864_SetWindow(1,7,"二");break;
- case 3:{
- LCD12864_WriteCmd(0x90+7);
- DelayUs2x(10);
- LCD12864_WriteData(0xc8);//三
- LCD12864_WriteData(0xfd);
- }break;
- case 4:LCD12864_SetWindow(1,7,"四");break;
- case 5:LCD12864_SetWindow(1,7,"五");break;
- case 6:LCD12864_SetWindow(1,7,"六");break;
- case 7:LCD12864_SetWindow(1,7,"日");break;
- }//switch 星期的
- }break;
- case 5: //日
- {
- TIME[3]++;
- if((TIME[3]&0x0f)==10)
- {
- TIME[3]&=0xf0;
- TIME[3]+=0x10;
- }
- if(TIME[3]==0x32)
- TIME[3]=0x01;
- LCD12864_WriteCmd(0x90+5);
- Ds1302Write(0,'0'+TIME[3]);
- LCD12864_WriteData('0'+TIME[3]/16);//日
- LCD12864_WriteData('0'+(TIME[3]&0x0f));
- }break;
- case 6: //月
- {
- TIME[4]++;
- if((TIME[4]&0x0f)==10)
- {
- TIME[4]&=0xf0;
- TIME[4]+=0x10;
- }
- if(TIME[4]>=0x13)
- TIME[4]=0x01;
- LCD12864_WriteCmd(0x90+3);
- Ds1302Write(0,'0'+TIME[4]);
- LCD12864_WriteData('0'+TIME[4]/16);//月
- LCD12864_WriteData('0'+(TIME[4]&0x0f));
- }break;
- case 7: //年
- {
- TIME[6]++;
- if((TIME[6]&0x0f)==10)
- {
- TIME[6]&=0xf0;
- TIME[6]+=0x10;
- }
- if(TIME[6]==0xa0)
- TIME[6]=0;
- LCD12864_WriteCmd(0x90+1);
- Ds1302Write(0,'0'+TIME[6]);
- LCD12864_WriteData('0'+TIME[6]/16);//年
- LCD12864_WriteData('0'+(TIME[6]&0x0f));
- }break;
- } //switch
- }
- //*******************************以下是按键按下减的计数******************************************/
- if(num==14) //减
- {
- LCD12864_WriteCmd(0x0c);
- switch(snum)
- {
- case 1: //秒
- {
- TIME[0]--;
- if((TIME[0]&0x0f)==0x0f)
- {
- TIME[0]&=0xf0;
- TIME[0]|=0x09;
- }
- if(TIME[0]==0xf9)
- TIME[0]=0x59;
- LCD12864_WriteCmd(0x88+5);
- Ds1302Write(0,'0'+TIME[0]);
- LCD12864_WriteData('0'+TIME[0]/16);//秒
- LCD12864_WriteData('0'+(TIME[0]&0x0f));
- }break;
- case 2: //分
- {
- TIME[1]--;
- if((TIME[1]&0x0f)==0x0f)
- {
- TIME[1]&=0xf0;
- TIME[1]|=0x09;
- }
- if(TIME[1]==0xf9)
- TIME[1]=0x59;
- LCD12864_WriteCmd(0x88+3);
- Ds1302Write(0,'0'+TIME[1]);
- LCD12864_WriteData('0'+TIME[1]/16);//分
- LCD12864_WriteData('0'+(TIME[1]&0x0f));
- }break;
- case 3: //时
- {
- TIME[2]--;
- if((TIME[2]&0x0f)==0x0f)
- {
- TIME[2]&=0xf0;
- TIME[2]|=0x09;
- }
- if(TIME[2]==0xf9)
- TIME[2]=0x23;
- LCD12864_WriteCmd(0x88+1);
- Ds1302Write(0,'0'+TIME[2]);
- LCD12864_WriteData('0'+TIME[2]/16);//时
- LCD12864_WriteData('0'+(TIME[2]&0x0f));
- }break;
- case 4: //星期
- {
- TIME[5]--;
- if(TIME[5]<=0x00)
- TIME[5]=0x07;
- c=TIME[5];
- LCD12864_WriteCmd(0x90+7);
- Ds1302Write(0,'0'+TIME[5]);
- switch(c)
- {
- case 1:LCD12864_SetWindow(1,7,"一");break;
- case 2:LCD12864_SetWindow(1,7,"二");break;
- case 3:{
- LCD12864_WriteCmd(0x90+7);
- DelayUs2x(10);
- LCD12864_WriteData(0xc8);//三
- LCD12864_WriteData(0xfd);
- }break;
- case 4:LCD12864_SetWindow(1,7,"四");break;
- case 5:LCD12864_SetWindow(1,7,"五");break;
- case 6:LCD12864_SetWindow(1,7,"六");break;
- case 7:LCD12864_SetWindow(1,7,"日");break;
- }//switch 星期的
- }break;
- case 5: //日
- {
- TIME[3]--;
- if((TIME[3]&0x0f)==0x0f)
- {
- TIME[3]&=0xf0;
- TIME[3]|=0x09;
- }
- if(TIME[3]==0x00)
- TIME[3]=0x31;
- LCD12864_WriteCmd(0x90+5);
- Ds1302Write(0,'0'+TIME[3]);
- LCD12864_WriteData('0'+TIME[3]/16);//日
- LCD12864_WriteData('0'+(TIME[3]&0x0f));
- }break;
- case 6: //月
- {
- TIME[4]--;
- if((TIME[4]&0x0f)==0x0f)
- {
- TIME[4]&=0xf0;
- TIME[4]|=0x09;
- }
- if(TIME[4]==0x00)
- TIME[4]=0x12;
-
- LCD12864_WriteCmd(0x90+3);
- Ds1302Write(0,'0'+TIME[4]);
- LCD12864_WriteData('0'+TIME[4]/16);//月
- LCD12864_WriteData('0'+(TIME[4]&0x0f));
- }break;
- case 7: //年
- {
- TIME[6]--;
- if((TIME[6]&0x0f)==0x0f)
- {
- TIME[6]&=0xf0;
- TIME[6]|=0x09;
- }
- if(TIME[6]==0xf9)
- TIME[6]=0x99;
- LCD12864_WriteCmd(0x90+1);
- Ds1302Write(0,'0'+TIME[6]);
- LCD12864_WriteData('0'+TIME[6]/16);//年
- LCD12864_WriteData('0'+(TIME[6]&0x0f));
- }break;
- }//switch
- }
- }
- }
- } //while
- }
- //===============================中断处理函数===============================//
- //是错误次数达到一定次数后的中断
- void init_irq1()interrupt 1 using 0
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- a++;
- if(a>=20)
- {
- a=0; //a大于等于20时说明一秒到了
- miao--; //五次错误后将会锁屏1分钟后才能输入密码
- clock(3,miao);
- }
- if(miao<=0)
- {
- TR0=0;
- miao=59; //当倒计时完成后将时间重新置于一分钟即是60
- LCD12864_SetWindow(2,0," ");
- LCD12864_SetWindow(3,0," ");
- LCD12864_SetWindow(2,1,"单片机实验室"); //写入第一行信息,主循环中不再更改此信息,所以在while之前写入
- LCD12864_SetWindow(3,1,"输入八位密码");
- flag_time2=0;
- }
-
- }
- //==============================密码输入(密码修改)=============================//
- void MIMA_input()
- {
- unsigned char i=0,m,k=1,flag7 = 1;
-
- if(flag5 == 1)
- {
- if(k2 == 0)
- {
- delay(5);
- if(k2 == 0) //如果扫描是按键有效值则进行处理
- {
- flag7 = 0;
- flag8 = 1;
- if(i == 0)
- LCD12864_WriteCmd(0x01);//输入是第一个字符的时候需要把改行清空,方便观看密码
- if(p==1)//修改个人密码
- {
- LCD12864_SetWindow(0,0,"修改个人密码");
- LCD12864_SetWindow(1,2,"新密码");
- LCD12864_SetWindow(2,1,"请输入密码");
- LCD12864_WriteCmd(0x0c);
- }
- if(p==0)//修改管理员密码
- {
- LCD12864_SetWindow(0,0,"修改管理员密码");
- LCD12864_SetWindow(1,2,"新密码");
- LCD12864_SetWindow(2,1,"请输入密码");
- LCD12864_WriteCmd(0x0c);
- }
- for(i = 0; i < 8 ; i++) //密码是8位,大于8位时不再输入按键值
- {
- delay(10);
- m=0XFF;
- while(m==0XFF)
- {
- m=KeyPro(); //扫描键盘
- if(m == 11)
- {
- delay(20);
- if(m == 11)
- {
- i= -1; //计数清零
- LCD12864_SetWindow(2,0," ");
- }
- }
- }
- delay(10);
- if(m != 11)
- {
- if(m >= 10)
- {
- i--;
- }
- if(i==0)
- LCD12864_SetWindow(2,0,"* ");
- if( m>=0 && m<10 ) //设置密码数位为0~9有效
- {
- LCD12864_char(2,i,'*'); //星号(*)
- if(p == 1)
- {
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
密码锁1.12864 720.zip
(152.87 KB, 下载次数: 107)
|