基于51单片机密码锁制作.doc
文本预览下载声明
#includereg51.h
#include intrins.h
unsigned int b[7];
unsigned int a[7]={0xee,0xed,0xdd,0xdb,0xbb,0xb7,0x77};
void delay(int i)
{
int j,k;
for(j=i;j0;j--)
for(k=125;k0;k--);
}
void main()
{
unsigned char temp;
int i,j=0,k,n=1,l=1,led;
while(1)
{
P3=0xfe;
temp=P3;
temp=temp0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
b[i++]=0xee;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
b[i++]=0xed;
break;
case 0xdd:
b[i++]=0xdd;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xdb:
b[i++]=0xdb;
break;
case 0xbb:
b[i++]=0xbb;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xb7:
b[i++]=0xb7;
break;
case 0x77:
b[i++]=0x77;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp0xf0;
}
}
}
if(b[6]==0x77)
{
for(i=0;i7;i++)
{
k=b[i];
if(a[i]==k)
j++;
}
if(j==7)
{
for(i=0;i2;i++)
{
P1=0x00;
delay(500);
P1=0xff;
delay(500);
}
显示全部