新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)的LCD1602液晶密碼鎖C語言程序

51單片機(jī)的LCD1602液晶密碼鎖C語言程序

作者: 時(shí)間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
#include
#include
#define uchar unsigned char
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit psb=P2^3;
sbit ret=P2^5;
sbit gg=P3^7;
uchar importcode[]={0,0,0,0,0,0};
uchar i;
uchar kk;
uchar js;
uchar j;
uchar ecode;
uchar bb;
uchar tcount,second;
uchar code key[]={0x77,0x7b,0x7d,0x7e,0xb7,0xbb,0xbd,0xbe,0xd7,0xdb,0xdd,0xde,0xe7,0xeb,0xed,0xee};
uchar code code1[8][6]={{0,6,0,4,9,8},{3,5,1,5,6,5},{2,5,4,3,9,5},{1,4,9,8,7,0},{1,3,9,7,8,5},{1,3,8,7,5,6},{2,9,1,9,9,5},{7,1,4,7,3,8}};
uchar code kp[]={0xf7,0xfd,0xfb,0xfe};
void lcd_int(void);
void functionset(void);
void write_order(uchar command);
void write_date(uchar date);
void display(void);
uchar keyy(void);
uchar gkey(void);
void keyc(void);
uchar comparecode(void);
void display(void);
void display0(void);
void display1(void);
void display2(void);
void display3(void);
void delay(int ms);
void clear_lcd(void);
void dscsh(void);
uchar keyy(void)
{ uchar key;
P1=0xf0;
while(P1!=0xf0);
do{
for(j=0;j<4;j++)
{ P1=kp[j];
if(P1!=kp[j])
{delay(100);
key=P1;
if(key!=kp[j])
{return(key);}
}
}
}while(1);
}
uchar gkey(void)
{
uchar number;
number=keyy();
for(j=0;j<16;j++)
{if(number==key[j])
return(j);
}
}
void keyc(void)
{
uchar v;
v=gkey();
switch(v)
{
case 0:kk++;
if(js<6)
{importcode[js]=0;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 1:kk++;
if(js<6)
{importcode[js]=1;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 2:kk++;
if(js<6)
{importcode[js]=2;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 3:kk++;
if(js<6)
{importcode[js]=3;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 4:kk++;
if(js<6)
{importcode[js]=4;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 5:kk++;
if(js<6)
{importcode[js]=5;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 6:kk++;
if(js<6)
{importcode[js]=6;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 7:kk++;
if(js<6)
{importcode[js]=7;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 8:kk++;
if(js<6)
{importcode[js]=8;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 9:kk++;
if(js<6)
{importcode[js]=9;
js++;
if(js==1)
{TR0=1;}
display();}
break;
case 14:
if(js==6)
{js=0;
ecode=1;}
else
{ecode=0;}
break;
case 10: clear_lcd();
js=0;kk=0;
gg=1;
TR0=0;
for(j=0;j<6;j++)
{importcode[j]=0;}
break;
case 11:gg=1;
break;
}
}
uchar comparecode(void)
{
for(j=0;j<6;j++)
{if(code1[i][j]==importcode[j])
bb=1;
else
{bb=0;break;}
}
return(bb);
}
void delay(int ms)
{ while(--ms);}
void dscsh(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%6;
ET0=1;
EA=1;
}
void main(void)
{
dscsh();
lcd_int();
functionset();
while(1)
{
display0();
keyc();
if(ecode==1)
{ ecode=0;
TR0=0;
bb=comparecode();
for(j=0;j<6;j++)
{importcode[j]=0;}
if(bb==1)
{ i++;
if(i==8)
{i=0;}
kk=0;
gg=0;
display1();
delay(50000);
delay(50000);
clear_lcd();
gg=1;
}
else
{kk=0;
display2();
gg=0;
delay(50000);
delay(50000);
clear_lcd();
}
}
}
}

上一頁 1 2 下一頁

評論


技術(shù)專區(qū)

關(guān)閉