>1;}}uchar"> >1;}}uchar" />
欢迎来到天天文库
浏览记录
ID:14385053
大小:191.50 KB
页数:29页
时间:2018-07-28
《大学毕设论文__基于51单片机的密码锁设计程序.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、#include"1302.h"voidwrite_ds1302_byte(uchardat){uchari;for(i=0;i<8;i++){T_IO=dat&0x01;T_CLK=1;T_CLK=0;dat=dat>>1;}}ucharread_ds1302_byte(){uchari;for(i=0;i<8;i++){ACC=ACC>>1;ACC7=T_IO;T_CLK=1;T_CLK=0;}return(ACC);}voidwrite_ds1302_dat(ucharaddr,uchardat){T_EN=0;T_CLK=0;T_EN=1;write_ds1302_byte(addr
2、);write_ds1302_byte(dat);T_CLK=1;T_EN=0;}ucharread_ds1302_data(ucharaddr){uchardate;T_EN=0;T_CLK=0;T_EN=1;write_ds1302_byte(addr);date=read_ds1302_byte();T_EN=0;T_CLK=0;return(date);}voidset_real_time(uchar*pclock){uchari,addr=0x80;EA=0;write_ds1302_dat(0x8e,0x00);for(i=0;i<7;i++){write_ds1302_dat(
3、addr,*pclock);pclock++;addr+=2;}//write_ds1302_dat(0x8e,0x80);EA=1;}voidget_real_time(ucharCurtime[]){ucharj;ucharaddress=0x81;EA=0;for(j=0;j<7;j++){Curtime[j]=read_ds1302_data(address);address+=2;}EA=1;}#ifndef__1302_H__#define__1302_H__#include#include#defineucharunsignedchar#
4、defineuintunsignedintsbitT_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#in
5、clude"delay.h"#include"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_rs_port=0;lcd_rw_port=0;lcd_en_port=0;lcd_data_port=command;lcd_en_po
6、rt=1;lcd_en_port=0;}voidwrite_data(uchardat){lcd_busy_wait();lcd_rs_port=1;lcd_rw_port=0;lcd_en_port=0;P0=dat;lcd_en_port=1;lcd_en_port=0;}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_b
7、usy_wait();lcd_rs_port=1;lcd_rw_port=0;lcd_en_port=0;P0=dat;lcd_en_port=1;lcd_en_port=0;}voidlcd_init()/*LCD1602初始化*/{lcd_delay(20);write_com(0x38);lcd_delay(100);write_com(0x38);lcd_delay(50);write_com(0x3
此文档下载收益归作者所有