1.“输入”按键:每次需要输入密码必须按“输入”按键,否则无法输入密码,若输入密码正确,则提示正确信息,否则提示错误信息并报警,10S内不允许重新输入密码。 2.“确认”按键:同于确认密码输入完成。 3.“修改密码”按键:需要修改密码,在输入正确密码后可按此按键进行修改。 4. 锁的初始密码是123456(密码长度为6位,超过6位再次输入则无效)。 5.??开锁10秒后不允许更改密码、并提示修改超时_进入初始态,需要重新输入密码方可再次修改密码。 6.??系统未使用存储器存储密码故掉电后密码自动恢复为初始密码 |
?
void main()
{
unsigned char i,j=0,num=0,count=0;
LCD_Init(); //显示屏初始化
Timer0_Init(); //定时器初始化
LCD_Write_Cmd(0x0F); //光标闪烁
LCD_Write_Str(0,0,"FireFly Sci&Tech"); //初始显示界面
LCD_Write_Str(4,1,"Welcome!");
while(1)
{
Key_Num = KeyPro();
if(time_flag) //定时器计时10S,返回初始界面
{ //关闭定时器
TR0 = 0; //定时标志位清零
time_flag = 0;
change_time =10;
Set_password = 0;
Unlock_Led = 0;
Beep = 0;
LCD_Write_Cmd(0x01); //清屏,并返回初始界面
LCD_Write_Str(0,0,"FireFly Sci&Tech");
LCD_Write_Str(4,1,"Welcome!");
}
if(Key_Num >= 12) //按键值是否大于12
{
if(Key_Num == 12) //输入按键是否按下
{
LCD_Write_Cmd(0x01); //清屏,并进入输入界面
DelayMs(5);
LCD_Write_Str(1,0,"PassWord:");
TR0 = 0; //关闭定时器,重新设定定时时间,
time_flag = 0;
change_time =10;
input_flag = 1; //输入标志位置1
Unlock_Led = 0; //开锁显示灯灭
num = 0;
i = 0;
}
else if(Key_Num == 13) //确认按键是否被按下
{
if(num == 6) //输入密码长度是否为6位
{
if(change_flag) //修改密码标志位真
{
change_flag = 0;
for(j = 0; j < 6; j++) //将密码从中间数组导入密码存储数组
{
Pass_Word[j] = Pass_Temp[j];
}
LCD_Write_Cmd(0x01); //清屏,并进入密码修改成功界面
LCD_Write_Str(2, 0, "SET Success!");
}
else if(input_flag)
{
if(memcmp(Pass_Num, Pass_Word, 6) == 0) //将输入的密码与设置的密码进行比对
{
LCD_Write_Cmd(0x01); //清屏,并进入密码输入正确界面
LCD_Write_Str(1, 0, "PassWord Right");
LCD_Write_Str(2, 1, "Door unlock");
Set_password = 1; //设定密码,10秒内可修改
Unlock_Led = 1; //开锁显示灯亮
input_flag = 0;
}
else
{
LCD_Write_Cmd(0x01); //清屏,并进入密码输入错误界面
DelayMs(5);
LCD_Write_Str(1, 0, "PassWord Error");
change_time =10;
TR0 = 1;
Unlock_Led = 0;
while(!time_flag)
{
Unlock_Led = ~Unlock_Led;
Beep = ~Beep; //板子为无源蜂鸣器
DelayUs2x(100);
}
}
}
change_time =10; //重新赋值定时时间,开定时器,输入计数和显示位置计数清零
TR0 = 1;
num = 0;
i = 0;
}
}
else if(Key_Num == 14) //修改密码按键
{
if(Set_password) //如果在设定密码时间内
{
LCD_Write_Cmd(0x01); //清屏,进入修改密码界面
DelayMs(5);
LCD_Write_Str(1, 0, "New PassWord:");
TR0 = 0;
time_flag = 0;
change_time =10;
change_flag = 1;
input_flag = 0;
Set_password = 0;
num = 0;
i = 0;
}
}
else if(Key_Num == 15) //取消修改密码
{
if(change_flag)
{
LCD_Write_Cmd(0x01);
DelayMs(5);
LCD_Write_Str(1, 0, "Cancel Change!");
TR0 = 1;
change_flag = 0;
num = 0;
i = 0;
}
}
}
。