温度显示的数字时钟设计课程设计报告(编辑修改稿)内容摘要:

eSecond%10 + 39。 039。 TimeTimeString[8] = 39。 39。 } else { TimeTimeString[6] = 39。 39。 TimeTimeString[7] = 39。 39。 TimeTimeString[8] = 39。 39。 } TimeDateString[9] = 39。 \039。 } void baoshi(SYSTEMTIME *Time) { if(TimeHour22amp。 amp。 TimeHour8amp。 amp。 TimeMinute/10==0amp。 amp。 TimeMinute%10==0amp。 amp。 TimeSecond/10==0amp。 amp。 TimeSecond%10==0) music()。 } void naozhong(SYSTEMTIME *Time) { if(TimeMinute%10==(f%10)amp。 amp。 TimeMinute/10==(f/10)amp。 amp。 TimeHour%10==(h%10)amp。 amp。 TimeHour/10==(h/10)amp。 amp。 TimeSecond%10==(m%10)amp。 amp。 TimeSecond/10==(m/10)) music()。 } void Initial_DS1302(void) //时钟芯片初始化 { unsigned char Second=Read1302(DS1302_SECOND)。 if(Secondamp。 0x80) //判断时钟芯片是否关闭 { Write1302(0x8e,0x00)。 //写入允许 Write1302(0x8c,0x07)。 //以下写入初始化时间 日期 :07/07/ : 3. 时间 : 23:59:55 Write1302(0x88,0x07)。 Write1302(0x86,0x25)。 Write1302(0x8a,0x07)。 Write1302(0x84,0x23)。 Write1302(0x82,0x59)。 Write1302(0x80,0x55)。 Write1302(0x8e,0x80)。 //禁止写入 } } /***********ds18b20 子程序 *************************/ /***********ds18b20 延迟子函数(晶振 12MHz ) *******/ void delay_18B20(unsigned int i) { while(i)。 } /**********ds18b20 初始化函数 **********************/ void Init_DS18B20(void) { unsigned char x=0。 DQ = 1。 //DQ 复位 delay_18B20(8)。 //稍做延时 DQ = 0。 //单片机将 DQ 拉低 delay_18B20(80)。 //精确延时 大于 480us DQ = 1。 //拉高总线 delay_18B20(14)。 x=DQ。 //稍做延时后 如果 x=0 则初始化成功 x=1 则初始化失败 delay_18B20(20)。 } /***********ds18b20 读一个字节 **************/ unsigned char ReadOneChar(void) { uchar i=0。 uchar dat = 0。 for (i=8。 i0。 i) { DQ = 0。 // 给脉冲信号 dat=1。 DQ = 1。 // 给脉冲信号 if(DQ) dat|=0x80。 delay_18B20(4)。 } return(dat)。 } /*************ds18b20 写一个字节 ****************/ void WriteOneChar(uchar dat) { unsigned char i=0。 for (i=8。 i0。 i) { DQ = 0。 DQ = datamp。 0x01。 delay_18B20(5)。 DQ = 1。 dat=1。 } } /**************读取 ds18b20 当前温度 ************/ void ReadTemp(void) { unsigned char a=0。 unsigned char b=0。 unsigned char t=0。 Init_DS18B20()。 WriteOneChar(0xCC)。 // 跳过读序号列号的操作 WriteOneChar(0x44)。 // 启动温度转换 delay_18B20(100)。 // this message is wery important Init_DS18B20()。 WriteOneChar(0xCC)。 //跳过读序号列号的操作 WriteOneChar(0xBE)。 //读取温度寄存器等(共可读 9 个寄存器) 前两个就是温度 delay_18B20(100)。 a=ReadOneChar()。 //读取温度值低位 b=ReadOneChar()。 //读取温度值高位 temp_value=b4。 temp_value+=(aamp。 0xf0)4。 } void temp_to_str() //温度数据转换成液晶字符显示 { TempBuffer[0]=temp_value/10+39。 039。 //十位 TempBuffer[1]=temp_value%10+39。 039。 //个位 TempBuffer[2]=0xdf。 //温度符号 TempBuffer[3]=39。 C39。 TempBuffer[4]=39。 \039。 } void naoz() { if(hide_h2) { nao[0]=h/10+39。 039。 nao[1]=h%10+39。 039。 } else { nao[0]=39。 39。 nao[1]=39。 39。 } nao[2]=39。 :39。 if(hide_f2) { nao[3]=f/10+39。 039。 nao[4]=f%10+39。 039。 } else { nao[3]=39。 39。 nao[4]=39。 39。 } nao[5]=39。 :39。 if(hide_m2) { nao[6]=m/10+39。 039。 nao[7]=m%10+39。 039。 } else { nao[6]=39。 39。 nao[7]=39。 39。 } nao[8]=39。 \039。 } void Delay1ms(unsigned int count) { unsigned int i,j。 for(i=0。 icount。 i++) for(j=0。 j120。 j++)。 } /*延时子 程序 */ void mdelay(uint delay) { uint i。 for(。 delay0。 delay) {for(i=0。 i62。 i++) //1ms 延时 . {。 } } } void outkey() //跳出调整模式 ,返回默认显示 { uchar Second。 if(out==0||wireless_1==1) { mdelay(8)。 count=0。 hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0。 Second=Read1302(DS1302_SECOND)。 Write1302(0x8e,0x00)。 //写入允许 Write1302(0x80,Secondamp。 0x7f)。 Write1302(0x8E,0x80)。 //禁止写入 done=0。 while(out==0)。 while(wireless_1==1)。 } } void outkey1() //跳出调整模式 ,返回默认显示 { uchar Second。 if(out==0||wireless_1==1) { mdelay(8)。 count=0。 hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0。 Second=Read1302(DS1302_SECOND)。 Write1302(0x8e,0x00)。 //写入允许 Write1302(0x80,Secondamp。 0x7f)。 Write1302(0x8E,0x80)。 //禁止写入 key=0。 while(out==0)。 while(wireless_1==1)。 } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// void Upkey()//升序按键 { Up=1。 if(Up==0||wireless_2==1) { mdelay(8)。 switch(count) {case 1: temp=Read1302(DS1302_SECOND)。 //读取秒数 temp=temp+1。 //秒数加 1 up_flag=1。 //数据调整后更新标志 if((tempamp。 0x7f)0x59) //超过 59 秒 ,清零 temp=0。 break。 case 2: temp=Read1302(DS1302_MINUTE)。 //读取分数 temp=temp+1。 //分数加 1 up_flag=1。 if(temp==0) { music()。 delay(2)。 } if(temp0x59) //超过 59 分 ,清零 temp=0。 break。 case 3: temp=Read1302(DS1302_HOUR)。 //读取小时数 temp=temp+1。 //小时数加 1 up_flag=1。 if(temp0x23) //超过 23 小时 ,清零 temp=0。 break。 case 4: temp=Read1302(DS1302_WEEK)。 //读取星期数 temp=temp+1。 //星期数加 1 up_flag=1。 if(temp0x7) temp=1。 break。 case 5: temp=Read1302(DS1302_DAY)。 //读取日数 temp=temp+1。 //日数加 1 up_flag=1。 if(temp0x31) temp=1。 break。 case 6: temp=Read1302(DS1302_MONTH)。 //读取月数 temp=temp+1。 //月数加 1 up_flag=1。 if(temp0x12) temp=1。 break。 case 7: temp=Read1302(DS1302_YEAR)。 //读取年数 temp=temp+1。 //年数加 1 up_flag=1。 if(temp0x85) temp=0。 break。 default:break。 } while(Up==0)。 while(wireless_2==1)。 } } void Upkey1()//升序按键 { Up=1。 if(Up==0||wireless_2==1) { mdelay(8)。 switch(count) {case 1: m=m+1。 //秒数加 1 up_flag=1。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。