课程设计论文-基于ds18b20的多点温度测量系统内容摘要:

接很生疏, 需要多加练习。 建议 希望在以后的学习中能过再多做类似本设计的练习,提高动手能力,夯实基础知识。 5 附录 原件明细表 DS18B20 两个、 AT89S52 一块、 74HC573 一块、按钮开关 3个、 10K 电阻三个、 电阻两个、 10uf 电解电容一个、 四位八段数码管一个。 设计原理图 参看上面的仿真图。 设计的主程序: include define uchar unsigned char define uint unsigned int sbit DS=P2^0。 //定义温度传感器的数据引脚 sbit button1=P3^5。 //定义按钮开关的控制位脚 sbit button2=P3^6。 12 uint temp。 // 温度值 sbit dula=P2^6。 uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}。 uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd, 0x87,0xff,0xef}。 uchar code ROM_CODE1[]={0x28,0xaa,0x4b,0x27,0x03,0x00,0x00,0x06}。 uchar code ROM_CODE2[]={0x28,0x1b,0x40,0x12,0x03,0x00,0x00,0x8f}。 void delay(uint count) //延时函数 { uint i。 while(count) { i=200。 while(i0) i。 count。 } } void dsreset() //18B20 复位,初始化函数 { 13 uint i。 DS=0。 i=103。 while(i0)i。 DS=1。 i=6。 while(i0)i。 } bit tmpreadbit() // 读 1位数据函数 { uint i。 bit dat。 DS=0。 i++。 i++。 DS=1。 i++。 i++。 dat=DS。 i=8。 // 短延时 while(i0)i。 return (dat)。 } uchar tmpread() //读 1字节函数 { uchar i,j,dat。 dat=0。 for(i=1。 i=8。 i++) { 14 j=tmpreadbit()。 dat=(j7)|(dat1)。 //读出的数据最低位在最前面,这样刚好一个字节在 DAT 里 } return(dat)。 } void tmpwritebyte(uchar dat) //write a byte to ds18b20 向 1820 写一个字节数据函数 { uint i。 uchar j。 bit testb。 for(j=1。 j=8。 j++) { testb=datamp。 0x01。 dat=dat1。 if(testb) //write 1 { DS=0。 i++。 i++。 DS=1。 i=8。 while(i0)i。 } else { DS=0。 //write 0 i=8。 while(i0)i。 DS=1。 15 i++。 i++。 } } } void match_rom(uchar fp) //匹配 ROM ID { char k。 t。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。