大学毕设论文__基于51单片机的密码锁设计程序 下载本文

内容发布更新时间 : 2024/12/24 20:16:34星期一 下面是文章的全部内容请认真阅读。

#include \

void write_ds1302_byte(uchar dat) { uchar i; for(i=0;i<8;i++) { T_IO=dat&0x01; T_CLK=1; T_CLK=0; dat=dat>>1; } }

uchar read_ds1302_byte() { uchar i; for(i=0;i<8;i++) { ACC=ACC>>1; ACC7=T_IO; T_CLK=1; T_CLK=0; } return (ACC); }

void write_ds1302_dat(uchar addr,uchar dat) { T_EN=0; T_CLK=0; T_EN=1; write_ds1302_byte(addr); write_ds1302_byte(dat); T_CLK=1; T_EN=0; }

uchar read_ds1302_data(uchar addr) { uchar date; 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); }

void set_real_time(uchar *pclock) { uchar i,addr=0x80; EA=0; write_ds1302_dat(0x8e,0x00); for(i=0;i<7;i++) { write_ds1302_dat(addr,*pclock); pclock++; addr+=2; }

// write_ds1302_dat(0x8e,0x80); EA=1; }

void get_real_time(uchar Curtime[]) { uchar j; uchar address=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

#define uchar unsigned char #define uint unsigned int

sbit T_IO=P2^5; sbit T_CLK=P2^4; sbit T_EN=P1^0;

sbit ACC0=ACC^0; sbit ACC7=ACC^7;

void write_ds1302_byte(uchar dat); uchar read_ds1302_byte();

void write_ds1302_dat(uchar addr,uchar dat); uchar read_ds1302_data(uchar addr); void set_real_time(uchar *pclock); void get_real_time(uchar Curtime[]);

#endif

#include \ #include \

void lcd_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; }

void write_com(uchar command) /*LCD1602 命令字写入*/ {

lcd_busy_wait(); lcd_rs_port = 0; lcd_rw_port = 0; lcd_en_port = 0;

lcd_data_port = command; lcd_en_port = 1;

lcd_en_port = 0; }

void write_data(uchar dat)