#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar old1=1,old2=2,old3=3,old4=4; //Ô-ê¼ÃüÂë000000
uchar new1,new2,new3,new4; //ÿ′ÎMCU2é¼ˉμ½μÄÃüÂëêäèë
uchar a=16,b=16,c=16,d=16; //ËíèëêyÂë1üÏÔê¾μıäá¿
uchar wei,key,temp;
bit allow,genggai,ok,wanbi,retry,k; //¸÷¸ö×′ì¬Î»
sbit led=P1^7;
unsigned char code table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40};
void delay(unsigned char i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void display(uchar a,uchar b,uchar c,uchar d)
{
P2=0XFE;
P0=table[a];
delay(5);
P2=0XFD;
P0=table[b];
delay(5);
P2=0XFb;
P0=table[c];
delay(5);
P2=0XF7;
P0=table[d];
delay(5);
}
void keyscan()
{
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
key=1;
wei++;
break;
case 0xde:
key=4;
wei++;
break;
case 0xbe:
key=7;
wei++;
break;
case 0x7e:
retry=1;
break;//------------
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
key=2;
wei++;
break;
case 0xdd:
key=5;
wei++;
break;
case 0xbd:
key=8;
wei++;
break;
case 0x7d:
genggai=1;
wei=0;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:
key=3;
wei++;
break;
case 0xdb:
key=6;
wei++;
break;
case 0xbb:
key=9;
wei++;
break;
case 0x7b:
if(allow)
ok=1;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
}
void shumima() //¶Ô°′¼ü2é¼ˉà′μÄêy¾Y½øDD·ÖÅä
{
if(!wanbi)
{
switch(wei)
{
case 1:new1=key;
a=key; break;
case 2:new2=key;
b=key; break;
case 3:new3=key;
c=key; break;
case 4:new4=key;
d=key;
wanbi=1; break;
}
}
}
void yanzheng() //ÑéÖ¤ÃüÂëêÇ·ñÕyè·
{
if(wanbi) //Ö»óDμ±áùλÃüÂë¾ùêäèëíê±Ïoó·½½øDDÑéÖ¤
{
if((new1==old1)&(new2==old2)&(new3==old3)&(new4==old4)){
allow=1;//μ±êäèëμÄÃüÂëÕyè·£¬»áμÃμ½alloweÖÃò»
a=b=c=d=17;
}
else k=1;
}
}
void main()
{
led=0;
while(1)
{
keyscan();
shumima();
yanzheng();
if(allow) //ÑéÖ¤íêoó£¬èôallowÎa1£¬Ôò¿aËø
{
led=1;
if(!genggai)
wanbi=0;
}
if(!genggai){
if(k){
a=16;b=0;c=d=15;
} }
if(genggai) //μ±S16¸ü¸ÄÃüÂë¼ü±»°′Ï£¬genggai»á±»ÖÃò»
{
if(allow) //èôòѾ-°ÑËø′ò¿a£¬2ÅóD¸ü¸ÄÃüÂëμÄè¨ÏT
{
while(!wanbi) //μ±DÂμÄáùλÃüÂëûóDé趨í꣬Ôòò»Ö±ÔúÕaàïÑ-»·
{
keyscan();
shumima();
if(retry) //¶øμ±ì½2aμ½ÖØêÔ¼üS18»òÕß1رÕÃüÂëËø¼üS19±»°′ÏÂê±£¬Ôòìø3ö
{ wanbi=1;
break;
}
display(a,b,c,d);
}
}
}
if(ok) //¸ü¸ÄÃüÂëê±£¬μ±ËùóDáùλDÂÃüÂë¾ù±»°′ÏÂê±£¬¿éòÔ°′ÏÂ′˼ü£¬½áêøÃüÂë¸ü¸Ä
{ //ÆäËûê±¼ä°′ÏÂ′˼üÎTD§
ok=0; wei=0;
genggai=0;
old1=new1;old2=new2;old3=new3; //′Ëê±£¬¾éμÄÃüÂ뽫±»′úìæ
old4=new4;
a=16;b=16;c=16;d=16;
}
if(retry) //μ±ÖØêÔ°′¼üS18±»°′Ï£¬retry»á±»ÖÃλ
{
retry=0; wei=0;wanbi=0;genggai=0;allow=0;k=0;
a=16;b=16;c=16;d=16;
new1=0;new2=0;new3=0;new4=0;
led=0;
}
display(a,b,c,d); //êμê±ÏÔê¾
}
}
|