请问哪位高人有电子密码锁的C语言程序,最好是有注释的 谢谢
2个回答
展开全部
单片机,数码管显示。4*4矩阵键盘
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define key P1
sbit lock=P3^1;
sbit worn=P3^2;
char pass_right=0;
char pass_bit=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar code key_code[]={0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,
0x7b,0xbb,0xdb,0xeb,0x77, 0xb7,0xd7,0xe7};
uchar data scan_con[6]={0x01,0x02,0x04,0x08,0x10,0x20};
uchar data dis[6]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
uchar data shumi[]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
uchar data cmima[6]={6,5,4,3,2,1};
uchar data pass_word[]={0x6d,0x6d,0x77,0x73,0x40,0x40};
uchar data no_pass_word[]={0x76,0x76,0x76,0x76,0x76,0x76};
void delay(uint t)
{
uchar i,j;
for(i=0;i<t;i++)
for(j=0;j<121;j++);
}
uchar key_scan()
{
uchar x,y,z,j;
key=0xff;
key=0x0f;
if(key!=0x0f)
{
delay(10);
if(key!=0x0f)
x=key;
key=0xf0;
y=key;
z=x|y;
for(j=0;j<16;j++)
if(z==key_code[j])
return j;
}
else key=0xff;
return 16;
}
void display()
{
uchar i;
for(i=0;i<6;i++)
{
P0=table[dis[i]];P2=scan_con[i];delay(10);P0=0x00;
}
}
void pass_word_display()
{
uchar i;
if(pass_right)
for(i=0;i<6;i++)
{
P0=pass_word[i];P2=scan_con[i];delay(10);P0=0x00;
}
else
for(i=0;i<6;i++)
{
P0=no_pass_word[i];P2=scan_con[i];delay(10);P0=0x00; worn=0;
}
}
void shumih()
{
uchar k,i=0,j;
if((k=key_scan())==1)
{
pass_bit=0;pass_right=0; worn=1;lock=1;
for(j=0;j<6;j++)
shumi[j]=0x0a;
while(i!=6)
{
display();
if((k=key_scan())!=16)
{
while(k==key_scan());
for(j=5;j>0;j--)
shumi[j]=shumi[j-1];
switch(k)
{
case 4:shumi[0]=1;i++;break;
case 5:shumi[0]=2;i++;break;
case 6:shumi[0]=3;i++;break;
case 8:shumi[0]=4;i++;break;
case 9:shumi[0]=5;i++;break;
case 10:shumi[0]=6;i++;break;
case 12:shumi[0]=7;i++;break;
case 13:shumi[0]=8;i++;break;
case 14:shumi[0]=9;i++;break;
case 15:shumi[0]=0;i++;break;
default:break;
}
}
for(j=0;j<6;j++)
dis[j]=shumi[j];
}
}
}
void mima_pass()
{
uchar k;
if((k=key_scan())==2)
{
delay(5);
pass_bit=1;
while(k==key_scan());
if(shumi[0]==cmima[0])
if(shumi[1]==cmima[1])
if(shumi[2]==cmima[2])
if(shumi[3]==cmima[3])
if(shumi[4]==cmima[4])
if(shumi[5]==cmima[5])
{
pass_right=1;
lock=0;
}
}
}
void main()
{
display();
while(1)
{
shumih();
mima_pass();
if(pass_bit!=1)
display();
else
pass_word_display();
}
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define key P1
sbit lock=P3^1;
sbit worn=P3^2;
char pass_right=0;
char pass_bit=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar code key_code[]={0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,
0x7b,0xbb,0xdb,0xeb,0x77, 0xb7,0xd7,0xe7};
uchar data scan_con[6]={0x01,0x02,0x04,0x08,0x10,0x20};
uchar data dis[6]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
uchar data shumi[]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
uchar data cmima[6]={6,5,4,3,2,1};
uchar data pass_word[]={0x6d,0x6d,0x77,0x73,0x40,0x40};
uchar data no_pass_word[]={0x76,0x76,0x76,0x76,0x76,0x76};
void delay(uint t)
{
uchar i,j;
for(i=0;i<t;i++)
for(j=0;j<121;j++);
}
uchar key_scan()
{
uchar x,y,z,j;
key=0xff;
key=0x0f;
if(key!=0x0f)
{
delay(10);
if(key!=0x0f)
x=key;
key=0xf0;
y=key;
z=x|y;
for(j=0;j<16;j++)
if(z==key_code[j])
return j;
}
else key=0xff;
return 16;
}
void display()
{
uchar i;
for(i=0;i<6;i++)
{
P0=table[dis[i]];P2=scan_con[i];delay(10);P0=0x00;
}
}
void pass_word_display()
{
uchar i;
if(pass_right)
for(i=0;i<6;i++)
{
P0=pass_word[i];P2=scan_con[i];delay(10);P0=0x00;
}
else
for(i=0;i<6;i++)
{
P0=no_pass_word[i];P2=scan_con[i];delay(10);P0=0x00; worn=0;
}
}
void shumih()
{
uchar k,i=0,j;
if((k=key_scan())==1)
{
pass_bit=0;pass_right=0; worn=1;lock=1;
for(j=0;j<6;j++)
shumi[j]=0x0a;
while(i!=6)
{
display();
if((k=key_scan())!=16)
{
while(k==key_scan());
for(j=5;j>0;j--)
shumi[j]=shumi[j-1];
switch(k)
{
case 4:shumi[0]=1;i++;break;
case 5:shumi[0]=2;i++;break;
case 6:shumi[0]=3;i++;break;
case 8:shumi[0]=4;i++;break;
case 9:shumi[0]=5;i++;break;
case 10:shumi[0]=6;i++;break;
case 12:shumi[0]=7;i++;break;
case 13:shumi[0]=8;i++;break;
case 14:shumi[0]=9;i++;break;
case 15:shumi[0]=0;i++;break;
default:break;
}
}
for(j=0;j<6;j++)
dis[j]=shumi[j];
}
}
}
void mima_pass()
{
uchar k;
if((k=key_scan())==2)
{
delay(5);
pass_bit=1;
while(k==key_scan());
if(shumi[0]==cmima[0])
if(shumi[1]==cmima[1])
if(shumi[2]==cmima[2])
if(shumi[3]==cmima[3])
if(shumi[4]==cmima[4])
if(shumi[5]==cmima[5])
{
pass_right=1;
lock=0;
}
}
}
void main()
{
display();
while(1)
{
shumih();
mima_pass();
if(pass_bit!=1)
display();
else
pass_word_display();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询