📄 lock.c
字号:
#include "reg51.h"
#include "lcd1602.c"
#include "keydriver.c"
sbit P3_0=P3^0;
sbit P3_3=P3^3;
//sbit P3_0=P3^0;
unsigned char count,i;
unsigned char a[10];
unsigned char password[4][10]={1,2,3,4,5,6,7,8,9,0,
2,4,5,6,7,8,2,3,4,7,
4,5,6,3,2,1,1,7,8,9,
0,9,8,7,6,5,4,3,2,1};
//报告结果
void report(unsigned char flag)
{
a[10]=0;
if(flag==0)
{
printf_char(1,10,"right%d") ;
P3_0=0;
delay(60000);delay(60000);
P3_0=1;
LCD_CLR();
}
else
{
printf_char(1,10,"error%d") ;
if(count>=3)
P3_3=1;
delay(60000);delay(60000);
P3_3=0;
LCD_CLR();
}
}
//回删键
void del(void)
{
if(i==0)
return;
else
{
a[i]='\0';
printf_char(2,i," %d");
i--;
}
}
//改密码
void ch_word(void)
{
unsigned char recieve=0xff,b[10],j=0;
LCD_CLR();
printf_char(1,1,"new_password%d");
while(recieve!=11)
{
recieve=keypad();
delay(10000);
if(recieve<=9&&recieve>=0)
{
b[j]=recieve;
printf_data(2,j+1,1,recieve);
j++;
}
else if(recieve==12)
{
if(j!=0)
{
a[j]='\0';
printf_char(2,j," %d");
j--;
}
}
}
LCD_CLR();
if(j==6)
{
for(j=0;j<6;j++)
password[0][j]=b[j];
printf_char(1,1,"success%d");
}
else
printf_char(1,1,"fail%d");
delay(60000); delay(60000);
LCD_CLR();
}
//功能
void menu(void)
{
//unsigned char recieve;
unsigned char number=0;
unsigned char key_value=100;
unsigned char ERROR=3;
unsigned char j=0;
for(;;)
{
number=keypad();
key_value=number;
while(number!=0XFF)
number=keypad();
printf_char(1,1,"welcome%d");
if(key_value<=9&&key_value>=0&&i<6)
{
a[i]=key_value;
printf_char(2,i+1,"*%d");
i++;
}
else if(key_value==11)
{
for(i=0;i<6;i++)
{
if(a[i]!=password[0][i]&&a[i]!=password[1][i]&&a[i]!=password[2][i]&&a[i]!=password[3][i])
{
ERROR=1;
count++;
break;
}
else
{
ERROR=0;
count=0;
}
}
i=0;
report(ERROR);
}
else if(key_value==13)
{
LCD_CLR();
a[10]=0;
}
else if(key_value==12)
del();
else if(key_value==14)
{
ch_word();
}
}
}
void main(void)
{
LCD_CLR();
LCD_init();
while(1)
menu();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -