毕业设计基于51单片机的密码锁设计程序Word文档下载推荐.docx
《毕业设计基于51单片机的密码锁设计程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《毕业设计基于51单片机的密码锁设计程序Word文档下载推荐.docx(36页珍藏版)》请在冰豆网上搜索。
write_ds1302_dat(addr,*pclock);
pclock++;
addr+=2;
//write_ds1302_dat(0x8e,0x80);
EA=1;
voidget_real_time(ucharCurtime[])
ucharj;
ucharaddress=0x81;
for(j=0;
j<
j++)
{
Curtime[j]=read_ds1302_data(address);
address+=2;
EA=1;
#ifndef__1302_H__
#define__1302_H__
#include<
reg52.h>
#include<
intrins.h>
#defineucharunsignedchar
#defineuintunsignedint
sbitT_IO=P2^5;
sbitT_CLK=P2^4;
sbitT_EN=P1^0;
sbitACC0=ACC^0;
sbitACC7=ACC^7;
voidwrite_ds1302_byte(uchardat);
ucharread_ds1302_byte();
voidwrite_ds1302_dat(ucharaddr,uchardat);
ucharread_ds1302_data(ucharaddr);
voidset_real_time(uchar*pclock);
voidget_real_time(ucharCurtime[]);
#endif
#include"
delay.h"
1602.h"
voidlcd_busy_wait()/*LCD1602忙等待*/
lcd_rs_port=0;
lcd_rw_port=1;
lcd_en_port=1;
lcd_data_port=0xff;
while(lcd_data_port&
0x80);
lcd_en_port=0;
voidwrite_com(ucharcommand)/*LCD1602命令字写入*/
lcd_busy_wait();
lcd_rw_port=0;
lcd_data_port=command;
voidwrite_data(uchardat)
lcd_rs_port=1;
lcd_rw_port=0;
lcd_en_port=0;
P0=dat;
lcd_en_port=1;
voidwtite_lcd_1602_dat(ucharx_pos,uchary_pos,uchardat)
x_pos&
=0x0f;
y_pos&
=0x01;
if(y_pos==0)
x_pos=x_pos+0x80;
else
x_pos=x_pos+0x80+0x40;
write_com(x_pos);
lcd_rw_port=0;
voidlcd_init()/*LCD1602初始化*/
lcd_delay(20);
write_com(0x38);
lcd_delay(100);
lcd_delay(50);
lcd_delay(10);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
/*释放数据端口*/
#ifndef__1602_H__
#define__1602_H__
sbitlcd_rs_port=P3^5;
sbitlcd_rw_port=P3^6;
sbitlcd_en_port=P3^4;
#definelcd_data_portP0
voidlcd_busy_wait();
voidwrite_com(ucharcommand);
voidwrite_data(uchardat);
voidwtite_lcd_1602_dat(ucharx_pos,uchary_pos,uchardat);
voidlcd_init();
2402.h"
voidi2c_start()
scl=1;
delay1();
sda=1;
sda=0;
voidi2c_stop()
voidi2c_ack()
while((sda==1)&
&
(i<
250))i++;
scl=0;
voidi2c_nack()
voidi2c_write_byte(uchardate)//
{//
uchari,temp;
temp=date;
i++)//
{//
temp=temp<
<
//
scl=0;
//
delay1();
;
sda=CY;
scl=1;
//
}//
//
}//
uchari2c_read_byte()
uchari,temp=0;
//delay1();
//sda=1;
temp=temp|sda;
return(temp);
voidwrite_at2404(ucharaddr,uchardat)
i2c_start();
i2c_write_byte(0xa0);
i2c_ack();
i2c_write_byte(addr);
i2c_write_byte(dat);
i2c_stop();
delay3(5000);
ucharread_at2402(ucharaddr)
uchartemp;
i2c_write_byte(0xa1);
temp=i2c_read_byte();
i2c_nack();
#ifndef__2402_H__
#define__2402_H__
sbitscl=P2^1;
sbitsda=P2^0;
voidi2c_start();
voidi2c_stop();
voidi2c_ack();
voidi2c_nack();
voidi2c_write_byte(uchar);
uchari2c_read_byte();
voidwrite_at2404(ucharaddr,uchardat);
ucharread_at2402(ucharaddr);
#include"
voiddelay(ucharx)
uchara,b;
for(a=x;
a>
0;
a--)
for(b=200;
b>
b--);
voidlcd_delay(ucharms)
while(ms--){
250;
{;
}
voiddelay1()
{;
;
voiddelay3(uintq)
{
uinte;
for(e=0;
e<
q;
e++);
#ifndef__DELAY_H__
#define__DELAY_H__
voiddelay(ucharx);
voidlcd_delay(ucharms);
voiddelay1();
voiddelay3(uintm);
display.h"
voiddisplay()
P0=0;
dula=1;
dula=0;
P0=0x7f;
wela=1;
wela=0;
#ifndef__DISPLAY_H__
#define__DISPLAY_H__
sbitdula=P2^6;
sbitwela=P2^7;
voiddisplay();
//一般放在最前面这个前后由调用先后决定着
scan.h"
//externvoidwrite_data(uchardat);
//externvoidwrite_com(ucharcommand);
ucharkey;
uchartemp,count,aa,bb,cc;
/*一般将这些变量定义在C文件中
当主函数需要时用extern引用*/
bitshu_flag,modify_flag,rst;
bitfun_flag;
//功能键标志位没使用
bitdown_flag,up_flag,open_flag;
voidkeyscan()
P1=0xfe;
temp=P1;
temp=temp&
0xf0;
if(temp!
=0xf0)
delay(15);
if(temp!
{
temp=P1;
switch(temp)
{
case0xee:
key=0;
shu_flag=1;
write_data('
*'
);
count++;
if(count>
6)count=0;
aa=0;
bb=0;
cc=0;
break;
case0xde:
key=1;
case0xbe:
key=2;
case0x7e:
key=3;
}
while(temp!
temp=P1;
temp=temp&
//beep=0;
delay(500);
//beep=1;
//write_data('
count++;
}
while(temp!
=0xf0);
temp=temp&
P1=0xfd;
case0xed:
shu_flag=1;
key=4;
//aa,bb,cc定时器中使用
case0xdd:
key=5;
//每次按键清零
//保证在按键器件不会自动返回
case0xbd:
key=6;
case0x7d:
key=7;
//beep=0;
//松手检测屏蔽蜂鸣器噪音污染
//beep=1;
//write_data('
P1=0xfb;
{//fun_flag功能键标志位
case0xeb:
key=8;
case0xdb:
key=9;
case0xbb:
modify_flag=1;
fun_flag=1;
//修改键
case0x7b:
rst=1;
//返回键
//beep=0;
//beep=1;
P1=0xf7;
{//清除键
case0xe7:
//key=12;
aa=0;
switch(count)
{
case1:
write_com(0x80+0x40+5);
'
write_com(0x80+0x40+5);
case2:
write_com(0x80+0x40+6);
write_com(0x80+0x40+6);
case3:
write_com(0x80+0x40+7);
write_com(0x80+0x40+7);
case4:
write_com(0x80+0x40+8);
write_com(0x80+0x40+8);
case5:
write_com(0x80+0x40+9);
write_com(0x80+0x40+9);
case6:
write_com(0x80+0x40+0x0a);
write_com(0x80+0x40+0x0a);
}
case0xd7:
key=13;
up_flag=1;
//开门键
case0xb7:
key=14;
down_flag=1;
case0x77:
open_flag=1;
while(temp!
temp=P1;
temp=temp&
//beep=0;
delay(500);
//beep=1;
if(count>
0)count--;
}//清除数字
#ifndef__SCAN_H__
#define__SCAN_H__
voidkeyscan();
/***********************************************************
名称:
电子密码锁
时间:
2014年8月2日16:
33:
48WRITEBY:
Kengkeng
TodayisValentine'
sDay
程序功能:
1:
开机1302显示时间,按下key15:
开门键进入输入密码界面
2:
输入密码输入错误超过三次电子锁锁死倒计时60s之后重新设置蜂鸣器快速响
3:
输入正确进入菜单页面两个选择key13:
开门key10:
修改密码
4:
修改已输入密码可由key12键清除重新输入
5:
选择key13开门打开继电器显示倒计时15s开门蜂鸣器慢响提示15s内开门
否则15后关门关闭继电器并自动返回时间页面
6:
选择key10修改密码共两次两次密码一致时设置成功否则会一直提示输入密码
7:
修改的密码存入2402中上电读出
8:
修改密码无限循环直到输入正确为止可以使用key11:
返回键返回
9:
在10s内无任何按键按下时自动返回时间页面可重新