⑴ 51单片机的电子密码锁程序,用KEIL C写的
以前帮别人做过一个类似的
#include<reg52.h>
#include <def.h>
#include"lcd.c"
uchar key;
uchar num;
sbit alarm=P2^4;
sbit open=P2^1;
uchar code table[]={' ','1','2','3',
'4','5','6','7'哪绝,
'8','9','0'};
void keyscan();
uchar hptable[10];
uchar password[6];
uchar wordbuf[6];
uchar fom[]="input password:";
uchar change[]="set mask:";
uchar state1[]="right";
uchar state2[]="error";
uchar sflag;
uchar dflag,cnt;
uchar setf,fset;
uchar flag;
void main ()
{
uchar hp;
alarm=0;
flag=0;
setf=0;
fset=0;
dflag=0;
lcden=0;
lcdrw=1;
lcdrs=1;
P3=0x0f;
for(hp=0;hp<6;hp++)
{
password[hp]='8';
}
write(0x38,0); //0为写命令
delay(9);
write(0x08,0);
write(0x01,0);
write(0x06,0);
write(0x0c,0);
write(0x80,0);
for(hp=0;hp<15;hp++)
{
write(fom[hp],1);
}
while(1)
{
// alarm=!alarm;
keyscan();
if(setf==0)
{
if(num>=1&&num<=10)
{
write(0x80+0x40+cnt,0);
write('*',1);
wordbuf[cnt]=table[num];
cnt++;
num=0;
}
}
else
{
write(0x01,0);
write(0x80,0);
for(hp=0;hp<9;hp++)
{
write(change[hp],1);
}
fset=1;
cnt=0;
while(fset)
{
keyscan();
if(num>=1&&num<=10)
{
write(0x80+0x40+cnt,0);
write('*',1);
password[cnt]=table[num];
cnt++;
num=0;
}
if(num==11)
{
write(0x80+0x40+cnt-1,0);
write('