4×4键盘及8位数码管显示构成的电子密码锁

[10-10 20:38:44]   来源:http://www.88dzw.com  电子制作   阅读:8252

文章摘要: 图4.33.2 5. C语言源程序#include <AT89X52.H>unsigned char ps[]={1,2,3,4,5};unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40,0x73,0xff};unsigned char disp

4×4键盘及8位数码管显示构成的电子密码锁,标签:电子小制作,http://www.88dzw.com

 

 

 

图4.33.2

 

5. C语言源程序
#include <AT89X52.H>
 
unsigned char ps[]={1,2,3,4,5};
 
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71,
0x00,0x40,0x73,0xff};
unsigned char dispbuf[8]={18,16,16,16,16,16,16,16};
unsigned char dispcount;
unsigned char flashcount;
unsigned char temp;
unsigned char key;
unsigned char keycount;
unsigned char pslen=5;
unsigned char getps[6];
bit keyoverflag;
bit errorflag;
bit rightflag;
unsigned int second3;
unsigned int aa,bb;
unsigned int CC;
bit okflag;
bit alarmflag;
bit hibitflag;
unsigned char oka,okb;
 
void main(void)
{
unsigned char i,j;
 
TMOD=0x01;
TH0=(65536-500)/256;
TL0=(65536-500)%256;
TR0=1;
ET0=1;
EA=1;
 
while(1)
{
P3=0xff;
P3_4=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=10;i>0;i--)
for(j=248;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=7;
break;
case 0x0d:
key=8;
break;
case 0x0b:
key=9;
break;
case 0x07:
key=10;
break;
}
temp=P3;
P1_1=~P1_1;
if((key>=0) && (key<10))
{
if(keycount<6)
{
getps[keycount]=key;
dispbuf[keycount+2]=19;
}
keycount++;
if(keycount==6)
{
keycount=6;
}
else if(keycount>6)
{
keycount=6;
keyoverflag=1;//key overflow
}
}
else if(key==12)//delete key
{
if(keycount>0)
{
keycount--;
getps[keycount]=0;
dispbuf[keycount+2]=16;
}
else
{
keyoverflag=1;
}
}
else if(key==15)//enter key
{
if(keycount!=pslen)
{
errorflag=1;
rightflag=0;
second3=0;
}
else
{
for(i=0;i<keycount;i++)
{
if(getps[i]!=ps[i])
{
i=keycount;
errorflag=1;
rightflag=0;
second3=0;
goto a;
}
}
errorflag=0;
rightflag=1;
a: i=keycount;
}
}
temp=temp & 0x0f;
while(temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
}
keyoverflag=0;//?????????
}
}
P3=0xff;
P3_5=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
for(i=10;i>0;i--)
for(j=248;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f)
{
temp=P3;
temp=temp & 0x0f;
switch(temp)
{
case 0x0e:
key=4;
break;
case 0x0d:
key=5;
break;
case 0x0b:
key=6;
break;
case 0x07:
key=11;
break;
}
temp=P3;
P1_1=~P1_1;
if((key>=0) && (key<10))
{
if(keycount<6)
{
getps[keycount]=key;
dispbuf[keycount+2]=19;
}
keycount++;
if(keycount==6)
{
keycount=6;
}
else if(keycount>6)
{
keycount=6;
keyoverflag=1;//key overflow
}
}
else if(key==12)//delete key
{
if(keycount>0)
{
keycount--;
getps[keycount]=0;
dispbuf[keycount+2]=16;
}
else
{
keyoverflag=1;
}
}
else if(key==15)//enter key

上一页  [1] [2] [3] [4]  下一页


Tag:电子制作电子小制作维修教程知识 - 电子制作