云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 基于单片机的数字电子时钟 - 图文

基于单片机的数字电子时钟 - 图文

  • 62 次阅读
  • 3 次下载
  • 2025/6/21 11:25:02

{ if(addr&0x01) { sda=1;

} else { sda=0; } sck=1; sck=0; addr=addr>>1;

}

for(i=0;i<8;i++) { if(d&0x01) { sda=1; } else { sda=0; } sck=1; sck=0; d=d>>1;

} rst=0;

}

unsigned char ds1302readbyte(unsigned char addr) { unsigned char i; unsigned char temp; rst=1;

addr=addr|0x01; for(i=0;i<8;i++) { if(addr&0x01) { sda=1;

} else {

sda=0;

22

}

}

} sck=1; sck=0; addr=addr>>1;

for(i=0;i<8;i++) { } rst=0; return temp;

temp=temp>>1; if(sda) { } else { } sck=1; sck=0;

temp&=0x7F; temp|=0x80;

void ds1302write(void) {

unsigned char i,tmp; }

void ds1302read(void)

23

for(i=0;i<8;i++) { }

ds1302writebyte(ds1302_control_add,0x00); ds1302writebyte(ds1302_sec_add,0x80);

ds1302writebyte(ds1302_year_add,time_buf[1]); ds1302writebyte(ds1302_date_add,time_buf[3]); ds1302writebyte(ds1302_day_add,time_buf[7]); ds1302writebyte(ds1302_hr_add,time_buf[4]); ds1302writebyte(ds1302_min_add,time_buf[5]); ds1302writebyte(ds1302_sec_add,time_buf[6]); ds1302writebyte(ds1302_day_add,time_buf[7]); ds1302writebyte(ds1302_control_add,0x80);

//关闭写保护 //年 //日 //周 //时 //分 //秒 //周

//暂停

tmp=time_buf1[i]/10; time_buf[i]=time_buf1[i]; time_buf[i]=time_buf[i]+tmp*16;

ds1302writebyte(ds1302_month_add,time_buf[2]); //月

{

unsigned char i,tmp; time_buf[1]=ds1302readbyte(ds1302_year_add); time_buf[3]=ds1302readbyte(ds1302_date_add); time_buf[4]=ds1302readbyte(ds1302_hr_add); time_buf[5]=ds1302readbyte(ds1302_min_add); time_buf[7]=ds1302readbyte(ds1302_day_add);

//年 //月 //日 //时 //分 //周

time_buf[2]=ds1302readbyte(ds1302_month_add);

time_buf[6]=(ds1302readbyte(ds1302_sec_add))&0x7F;//秒

for(i=0;i<8;i++) { tmp=time_buf[i]/16;

time_buf1[i]=time_buf[i]; time_buf1[i]=time_buf1[i]+tmp*10;

}

}

void ds1302init(void) { rst=0; sck=0;

ds1302writebyte(ds1302_sec_add,0x00); }

//DS18B20模块程序 #include\#include\bit Init_DS18B20(void) { bit dat=0; DQ = 1; DelayUs2x(5); DQ = 0; DelayUs2x(200); DelayUs2x(200); DQ = 1; DelayUs2x(50); dat=DQ; DelayUs2x(25); return dat; }

unsigned char ReadOneChar(void) {

unsigned char i=0; unsigned char dat = 0; for (i=8;i>0;i--)

24

{ DQ = 0; dat>>=1; DQ = 1; if(DQ) dat|=0x80; DelayUs2x(25); }

return(dat); }

void WriteOneChar(unsigned char dat) {

unsigned char i=0; for (i=8; i>0; i--) { DQ = 0; DQ = dat&0x01; DelayUs2x(25); DQ = 1; dat>>=1; }

DelayUs2x(25); }

unsigned int ReadTemperature(void) { unsigned char a=0; unsigned int b=0; float t=0; Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0x44); delay(10); Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0xBE); a=ReadOneChar(); b=ReadOneChar(); b<<=8; t=a+b; return(t);

}

//按键模块程序

25

搜索更多关于: 基于单片机的数字电子时钟 - 图文 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{ if(addr&0x01) { sda=1; } else { sda=0; } sck=1; sck=0; addr=addr>>1; } for(i=0;i>1; } rst=0; } unsigned char ds1302readbyte(unsigned char addr) { unsigned char i; unsigned char temp; rst=1; addr=addr|0x01; for(i=0;i<8;i++

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com