#include
#include
#define uchar unsigned char
static unsigned char table[6]={0,0,0,0,0,0};
//Declare functions
uchar Busy_Check();
void Initialize_LCD();
void Write_LCD_Data(uchar dat);
void Write_LCD_Command(uchar cmd);
void Display_String(uchar x,uchar y,uchar *str);
void Display_char(uchar hang,uchar lie,char sign);
// void write_add(uchar address,uchar date);// 向 AT24Cxx 中的指定地址写入数据 uchar read_add(uchar address);// 从 AT24Cxx 中的指定地址读取数据
void init();
uchar h=20;
sbit touch=P2^1;
sbit touch1=P2^2;
sbit speaker=P2^0;
void delay(unsigned char ms) // 延时 **ms
{
unsigned char i;
while(ms--)
{
for(i=250;i>0;i--)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
unsigned char keyscan() // 扫描键盘
{
unsigned char temp,y,j;
unsigned char anjian[]={0xfe,0xfd,0xfb,0xf7};
for(y=0;y<4;y++)
{
P1 = anjian[y];
temp = 0x10;
for(j=0;j<4;j++)
{
if(!(P1&temp))
{
return(j+y*4);
}
temp = _crol_(temp,1);
}
}
}
void judge()
{
P1 = 0xf0; if(P1!=0xf0) // 判断是否有按键
{
delay(50); delay(50); // 消抖
if(P1!=0xf0)
{
h=keyscan();
}
}
}
void main()
{
unsigned char a=1,i=0,k=0,l=1,m=1,n,f=0,s=0;
int q;
Initialize_LCD();
init();
Display_String(1,1,"Welcome To Use ");
Display_String(2,1," ");
touch1=0; //第一个 while 循环
while(1)
{
judge();
if(h<10)
{
if(h==table[i])
k++;
Display_String(2,a,"*");
a++;
i++;
if(a==7)
a=1;
if(i==6)
i=0;
h=16;
}
if(h==14)
{
Display_String(1,1,"Input Password");
Display_String(2,1," ");
h=16;
touch=1;
touch1=0;
k=0;
l=1;
q=0;
}
if(h==12)
{
if(k==6)
{
Display_String(1,1,"Password Right");
Display_String(2,1,"Lock Opened!");
touch=~touch;
}
else
{
Display_String(1,1,"Password Error");
Display_String(2,1," ");
l=0;
q++;
while(q==3)
{
speaker=0;
delay(200);
delay(200);
delay(200);
speaker=1 ;
q=0;
}
h=14;
}
delay(255);
k=0;
h=16;
while(l)
{
judge();
if(h==11)
{ Display_String(1,1,"New Code");
Display_String(2,1," ");
while(m==1)
{
judge();
touch1=~touch1;
if(h<10)
{
table[n]=h;
write_add(s,h);
s++;
Display_String(2,a,"*");
a++;
n++;
h=16;
if(n==6)
{
n=0;
s=0;
}
}
if(h==15)
{
if(n==0)
n=6;
s=6;
a--;
s-- ;
Display_String(2,a," ");
n--;
h=16;
}
if(h==13)
m=0;
}
if(h==13)
h=13;
f=1;
}
if(h==14)
{
l=0;
}
if(h==13)
{
Display_String(2,1," ");
for(n=0;n<6;n++)
Display_char(2,n+1,(uchar)(table[n]+48) );h=13;l=0;f=1;}
k=0;
}
}
if(h==15)
{
a--;
Display_String(2,a," ");
k--;
i--;
h=16;
}
if(h==13)
{ if(f==1)
{ for(n=0;n<6;n++)
Display_char(2,n+1,(uchar)(table[n]+48) );f=0; }
else
Display_String(2,1," ****** ");
delay(255);
delay(255);
Display_String(1,1," Welcome To Use ");
Display_String(2,1," ");
l=1;a=1;k=0;n=0;m=1;
h=16;
}
}
for(s=0;s<6;s++)
{ table[s]=read_add(s);
delay(50);
}
}