#include <reg52.h>
#include <intrins.h>
#include<absacc.h rel='nofollow' onclick='return false;'>
#include"44key.c"
#include"1602.c"
#include"2402.c"
#include"hongwai.c"
#define DEFAULT 0
#define UNLOCK 1
#define INPUT_PASSWORD 14
#define SET_PASSWORD 15
#define TRUE 1
#define FALSE 0
uchar zhi,flag=0,flag1=0;
uchar counter1=0;
sbit BEEP=P0^0;
sbit red=P0^1;
sbit yellow=P0^2;
sbit green=P0^3;
unsigned char password[8]={1,2,3,4,5,6,7,8};
char code input[]="Input Password:";
char code old_password[]="Old Password:";
char code new_password[]="New Password:";
char code confirm[]="Input Again:";
unsigned char guess[8]={0,0,0,0,0,0,0,0};
unsigned char temp[8] ={0,0,0,0,0,0,0,0};
unsigned char temp1[8]={0,0,0,0,0,0,0,0};
uchar keyscan();
int ifkeydown();
void beep()
{
BEEP=0;
delay2(1);
BEEP=1;
}
int get_password()
{
uchar counter;
for(counter=0;counter<9;counter++)
{
delay2(50);
if(counter<8)
{
do{
displayonechar(counter,1,'_');
delay2(100);
if(flag1)
{
while(RE_DATA);
CheckRE();
keyvalue=Recived_Data;
}
else
{
while(!ifkeydown());
keyscan();
}
}
while(keyvalue==0xff);
if((keyvalue!=13)&&(keyvalue!=12))
{
// displayonechar(counter,1,'*');
displayonechar(counter,1,dis_num[keyvalue]);
guess[counter]=keyvalue;
}
if(keyvalue==13)
{
if(counter>0)
{
displayonechar(--counter,1,'_');
guess[counter]=0x00;
// displayonechar(counter,1,' ');
counter--;
}
}
if(keyvalue==12)
{
flag1=0;
coordinate(0,1);
return( 0);
}
}
if(counter==8)
{
do{
if(flag1==1)
{
while(RE_DATA);
CheckRE();
keyvalue=Recived_Data;
}
else
{
while(!ifkeydown());
keyscan();
}
}while((keyvalue!=13)&&(keyvalue!=12));
if(keyvalue==13)
{
displaymorechar(counter,1," ");
displayonechar(--counter,1,'_');
guess[counter]=0x00;
// displayonechar(counter,1,' ');
counter--;
}
if(keyvalue==12)
{
flag1=0;
return(1);
}
}
}
}
int check_password()
{
char i;
i=0;
ClearLCD();
while ((guess[i]==password[i]) && (i < 8)) i++;
if (i==8) return(TRUE);
else
return(FALSE);
}
int input_new_password()
{
unsigned char i,j;
ClearLCD();
displaymorechar(0,0,new_password);
if(get_password())
{
for(i=0;i<8;i++)
temp[i]=guess[i];
}
else
return(FALSE);
ClearLCD();
displaymorechar(0,0,confirm);
if(get_password())
{
for(i=0;i<8;i++)
temp1[i]=guess[i];
}
else
return(FALSE);
i=0;
while(!(keyscan()==12));
ClearLCD();
while ((temp1[i]==temp[i]) && (i < 8)) i++;
if (i==8)
{
for(j=0;j<8;j++)
{
password[j]=temp[j];
}
write_page_data_to_24C02(0xA0,0,password);
return(TRUE);
}
else return(FALSE);
}
void display()
{
int k=0;
switch (keyvalue)
{
case INPUT_PASSWORD :
loop: ClearLCD();
displaymorechar(0,0,input);
delay2(50);
if(get_password())
{
if ( check_password() )
{
green=0;
displaymorechar(0,0,"Right!");
delay3(3000);
ClearLCD();
green=1;
}
else
{
red=0;
displaymorechar(0,0,"Wrong!");
k++;
delay3(30000);
red=1;
if(k==3)
{
flag=1;
EA=1;
ClearLCD();
displaymorechar(0,0,"wait a moment");
while(1);
}
goto loop;
}
}
else
{
red=0;
ClearLCD();
displaymorechar(0,0,"error!");
delay3(30000);
ClearLCD();
red=1;
}
break;
case SET_PASSWORD :
//beep();
ClearLCD();
displaymorechar(0,0,old_password);
if(get_password())
{
if ( check_password() )
if( input_new_password() )
{
displaymorechar(2,0,"password has");
displaymorechar(2,1,"been changed!");
}
else
{ yellow=0;
ClearLCD();
displaymorechar(0,0,"Fail!");
delay3(30000);
yellow=1;
}
else
red=0;
displaymorechar(0,0,"Wrong!");
delay3(3000);
ClearLCD();
red=1;
}
else
{
red=0;
ClearLCD();
displaymorechar(0,0,"error!");
delay3(3000);
ClearLCD();
red=1;
}
break;
}
}
void time0(void) interrupt 1
{
TR0=0;
TH0=0x3C;
TL0=0xB0;
if(flag)
{
counter1++;
if(counter1==100)
{
TR0=1;
EA=1;
flag=0;
counter1=0;
ClearLCD();
displaymorechar(0,0,"rest success!");
delay3(30000);
(*(void(*)())0)();
}
}
TR0=1;
}
void main (void)
{
int i;
RE_DATA=1;
TMOD=0x01;
TH0=0x3C;
TL0=0xB0;
TR0=1;
ET0=1;
EA=0;
ClearLCD();
startset();
displaymorechar(4,0,"welcome");
displaymorechar(3,1,"mi ma suo");
read_page_data_from_24C02(0xA0,0);
for(i=0;i<8;i++)
{
password[i]=a[i];
}
while(1)
{
if(RE_DATA==0)
{
flag1=1;
CheckRE();
keyvalue=Recived_Data;
display();
}
displaymorechar(4,0,"welcome");
keyscan();
display();
}
}