#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit ST=P1^0; //启动转换位
sbit OE=P1^1; //输出允许位
sbit ALE=P1^2; //地址允许锁存位
sbit EOC=P1^3; //转换结束位
sbit CLK=P1^4; //时钟
sbit BUZ=P1^6;
sbit RED=P1^5;
sbit GREEN = P1^7;
long datas,bai,she,ge;
uchar code_num;
uchar key_val=0xff; //定义键值,初始默认为0
uchar key_flag;
uchar i;
uchar duan;
uchar code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x0}; //不带点的数字
uchar code num_dot[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed}; //带点的数字
uchar code wei[]={0XFE,0xFd,0xFb,0xF7,0XEF,0xDF,0xBF,0x7F}; //位码
uchar mima[8]={10, 10, 10, 10, 10, 10, 10, 10};
uchar code mima_init[8]={8, 8, 8, 8, 8, 8, 8, 8}; //初始密码修改处
void delay(uint z)
{
uchar i;
while(z--)
for(i=0;i<120;i++);
}
void display()
{
uchar i=0;
for(i=0;i<8;i++)
{
P2= wei[i];
P0= num[mima[i]];
delay(2);
}
}
uchar temp,i,m,s=0,s1,s2,s3,s4,s5;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0x8e};
void display(uchar a);
void delay(uint z);
void keyscan();
void keyin(uchar zhi,uchar a,uchar b,uchar c,uchar d);
/****************** 显示函数 *******************/
void disp(uchar a)
{
if(s==1){P1=0x20;P0=table[a];s1=table[a];delay(1);}
if(s==2){P1=0x10;P0=s1;delay(1);
P1=0x20;P0=table[a];s2=table[a];delay(1);}
if(s==3){P1=0x08;P0=s1;delay(1);
P1=0x10;P0=s2;delay(1);
P1=0x20;P0=table[a];s3=table[a];delay(1);}
if(s==4){P1=0x04;P0=s1;delay(1);
P1=0x08;P0=s2;delay(1);
P1=0x10;P0=s3;delay(1);
P1=0x20;P0=table[a];s4=table[a];delay(1);}
if(s==5){P1=0x02;P0=s1;delay(1);
P1=0x04;P0=s2;delay(1);
P1=0x08;P0=s3;delay(1);
P1=0x10;P0=s4;delay(1);
P1=0x20;P0=table[a];s5=table[a];delay(1);}
if(s==6){P1=0x01;P0=s1;delay(1);
P1=0x02;P0=s2;delay(1);
P1=0x04;P0=s3;delay(1);
P1=0x08;P0=s4;delay(1);
P1=0x10;P0=s5;delay(1);
P1=0x20;P0=table[a];delay(1);}
if(s>6){s=1;}if(s==1){P1=0x20;P0=table[a];s1=table[a];delay(1);}
if(s==2){P1=0x10;P0=s1;delay(1);
P1=0x20;P0=table[a];s2=table[a];delay(1);}
if(s==3){P1=0x08;P0=s1;delay(1);
P1=0x10;P0=s2;delay(1);
P1=0x20;P0=table[a];s3=table[a];delay(1);}
if(s==4){P1=0x04;P0=s1;delay(1);
P1=0x08;P0=s2;delay(1);
P1=0x10;P0=s3;delay(1);
P1=0x20;P0=table[a];s4=table[a];delay(1);}
if(s==5){P1=0x02;P0=s1;delay(1);
P1=0x04;P0=s2;delay(1);
P1=0x08;P0=s3;delay(1);
P1=0x10;P0=s4;delay(1);
P1=0x20;P0=table[a];s5=table[a];delay(1);}
if(s==6){P1=0x01;P0=s1;delay(1);
P1=0x02;P0=s2;delay(1);
P1=0x04;P0=s3;delay(1);
P1=0x08;P0=s4;delay(1);
P1=0x10;P0=s5;delay(1);
P1=0x20;P0=table[a];delay(1);}
if(s>6){s=1;}if(s==1){P1=0x20;P0=table[a];s1=table[a];delay(1);}
if(s==2){P1=0x10;P0=s1;delay(1);
P1=0x20;P0=table[a];s2=table[a];delay(1);}
if(s==3){P1=0x08;P0=s1;delay(1);
P1=0x10;P0=s2;delay(1);
P1=0x20;P0=table[a];s3=table[a];delay(1);}
if(s==4){P1=0x04;P0=s1;delay(1);
P1=0x08;P0=s2;delay(1);
P1=0x10;P0=s3;delay(1);
P1=0x20;P0=table[a];s4=table[a];delay(1);}
if(s==5){P1=0x02;P0=s1;delay(1);
P1=0x04;P0=s2;delay(1);
P1=0x08;P0=s3;delay(1);
P1=0x10;P0=s4;delay(1);
P1=0x20;P0=table[a];s5=table[a];delay(1);}
if(s==6){P1=0x01;P0=s1;delay(1);
P1=0x02;P0=s2;delay(1);
P1=0x04;P0=s3;delay(1);
P1=0x08;P0=s4;delay(1);
P1=0x10;P0=s5;delay(1);
P1=0x20;P0=table[a];delay(1);}
if(s>6){s=1;}
}
void keyin(uchar zhi,uchar a,uchar b,uchar c,uchar d);
/****************** 键扫描函数 *******************/
void keyscan()
{
P3=0xff;
keyin(0xfe,0,1,2,3);
keyin(0xfd,4,5,6,7);
keyin(0xfb,8,9,10,11);
keyin(0xf7,12,13,14,15);
}
/****************** 键输入函数 *******************/
void keyin(uchar zhi,uchar a,uchar b,uchar c,uchar d)
{
uchar temp,m,s,flag;
P3=zhi;
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
temp=P3;
temp=P3&0xf0;
switch(temp)
{
case(0xe0):m=a;break;
case(0xd0):m=b;break;
case(0xb0):m=c;break;
case(0x70):m=d;break;
default:break;
}
flag=1;
delay(200);
s++;if(s>6)s=1;
}
delay(10);
}
P3=zhi;
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
temp=P3;
temp=P3&0xf0;
switch(temp)
{
case(0xe0):m=a;break;
case(0xd0):m=b;break;
case(0xb0):m=c;break;
case(0x70):m=d;break;
default:break;
}
flag=1;
delay(200);
s++;if(s>6)s=1;
}
delay(10);
}
P3=zhi;
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{
temp=P3;
temp=P3&0xf0;
switch(temp)
{
case(0xe0):m=a;break;
case(0xd0):m=b;break;
case(0xb0):m=c;break;
case(0x70):m=d;break;
default:break;
}
flag=1;
delay(200);
s++;if(s>6)s=1;
}
delay(10);
}
P3=zhi;
temp=P3;
temp=P3&0xf0;
if(temp!=0xf0)
{