第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/11/21 17:28:13 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{ 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

搜索更多关于: 基于单片机的数字电子时钟 - 图文 的文档
基于单片机的数字电子时钟 - 图文.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9ev5i1ji6c7b3ef98nfk_7.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top