|
#include
sbit led1=P0^0;
sbit led2=P0^1;
sbit led3=P0^2;
sbit led4=P2^7;
sbit sound=P2^6;
sbit scl=P3^7;
sbit sda=P3^6;
int code[6];
int count;
char compf; // 密码比较函数的结果赋给他
char keyin;
int mima[6]; //初始密码
int open;
void key_in(void);
char key_scan(void);
char comparecode(int shu[],int cun[]);
void main()
{
count=0;
open=0;
mima[6]=0;
while(1)
{
key_in();
keyin=key_scan();
if(keyin==0x0b)
{
compf=comparecode(code[],mima[]);
while(compf==0)
{
count++;
if (count>=3)
{
nop;//计时1分钟无动作。
delay(250);
}
else
{
key_in();
keyin=key_scan();
if(keyin==0x0b)
{
compf=comparecode(code[],mima[]);
}
else nop;
}
}
while(compf==1)
{
led3=1;
delay(10);
led3=0;
open=1;
code[6]=0;
compf=0;
}
}
}
}
void key_in(void) //键盘密码输入
{
int i;
int rece;
for(i=0;i<6;i++)
{
rece=key_scan();
if (rece>=0x00&&rece<=0x0a)
{
if (rece>=0x00&&rece<=0x09)
{
code=rece;
}
else
{
code[6]=0;
i=0;
}
}
}
}
char key_scan(void) // 键盘扫描
{
char temp,com1,com2;
int com;
P1=0xf0;
if(P1!=0xf0)
{
com1=P1;
P1=0x0f;
com2=P1;
}
P1=0xf0;
while(P1!=0xf0);
temp=com1|com2;
led1=0;
if(temp==0xee)com=0x03;
if(temp==0xed)com=0x02;
if(temp==0xeb)com=0x01;
if(temp==0xe7)com=0x0c;//修改键
if(temp==0xde)com=0x06;
if(temp==0xdd)com=0x05;
if(temp==0xdb)com=0x04;
if(temp==0xd7)com=0x0f;//无效
if(temp==0xbe)com=0x07;
if(temp==0xbd)com=0x08;
if(temp==0xbb)com=0x09;
if(temp==0xb7)com=0x0f;//无效
if(temp==0x7e)com=0x0b; //开锁
if(temp==0x7d)com=0x00;
if(temp==0x7b)com=0x0d; //确认
if(temp==0x77)com=0x0a;//清除
return(com);
}
char comparecode(int shu[],int cun[]) //密码比较函数
{
int i;
char comp;
for(i=0;i<6;i++)
{
if(shu==cun)
{
comp=1;
}
else
{
comp=0;
break;
}
}
return(comp);
}
void delay(int ms)
{ while(--ms);}
编译有错,但不知道怎么改,高手帮忙改下呀!谢谢了。
|
|