该密码锁控制器 ,键盘上有0-9个数字按键,功能键:确认和取消等,可设置复合键。密码的位数及密码可以任意设定,,当输入数字和设置的密码相同的时候,锁打开,否则无法打开。采用IIC通信方式,密码锁的密码掉电不丢失。
#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar old1,old2,old3,old4,old5,old6;
uchar new1,new2,new3,new4,new5,new6;
uchar a=10,b=10,c=10,d=10,e=10,f=10;
uchar wei,key,temp;
bit allow,genggai,ok,wanbi,retry,close;
sbit dula=P2^6;
sbit wela=P2^7;
sbit beep=P2^3;
sbit led=P1^0;
sbit sda=P2^0;
sbit scl=P2^1;
unsigned char code table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x08};
/*****************i2c芯片24C02存储器驱动程序************************************/
void nop()
{
_nop_();
_nop_();
}
void delay1(unsigned int m)
{ unsigned int n;
for(n=0;n<m;n++);
}
void init()
{
scl=1;
nop();
sda=1;
nop();
}
void start()
{
sda=1;
nop();
scl=1;
nop();
sda=0;
nop();
scl=0;
nop();
}
void stop()
{
sda=0;
nop();
scl=1;
nop();
sda=1;
nop();
}
void writebyte(unsigned char j)
{
unsigned char i,temp;
temp=j;
for (i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
nop();
sda=CY;
nop();
scl=1;
nop();
}
scl=0;
nop();
sda=1;
nop();
}
unsigned char readbyte()
{
unsigned char i,j,k=0;
scl=0; nop(); sda=1;
for (i=0;i<8;i++)
{
nop(); scl=1; nop();
if(sda==1<