完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
部分程序如下:
uchar code sn1[]={"0x28,0x9D,0x7A,0x04,0x00,0x00,0x80,0xB7"};//序列号 uchar code sn2[]={"0x28,0xFF,0xBF,0xEA,0xA4,0x15,0x03,0xA3"}; uchar code sn3[]={"0x28,0xFF,0xE1,0xD0,0x89,0x16,0x03,0x16"}; void match_b20rom(uchar a) //匹配ROM { char j; Ds18b20_WriteByte(0x55); if(a==1) { for(j=0;j<8;j++) Ds18b20_WriteByte(sn1[j]); } if(a==2) { for(j=0;j<8;j++) Ds18b20_WriteByte(sn2[j]); } if(a==3) { for(j=0;j<8;j++) Ds18b20_WriteByte(sn3[j]); } } int Ds18b20_ReadTemp(uchar z)//读取温度 { int temp0 = 0;int j; uchar tmh, tml; if(Ds18b20_Init()==1) { ds_flag=1; return ds_flag; } else { ds_flag=0; Ds18b20_Init() ; if(z==1) match_b20rom(1); //选择匹配的B20 if(z==2) match_b20rom(2); if(z==3) match_b20rom(3); //Ds18b20_WriteByte(0xcc); //先写入转换命令跳过ROM操作命令 Ds18b20_WriteByte(0x44); //温度转换命令 j++; j++; Ds18b20_Init() ; if(z==1) match_b20rom(1); //选择匹配的B20 if(z==2) match_b20rom(2); if(z==3) match_b20rom(3); //Ds18b20_WriteByte(0xcc); //跳过ROM操作命令 Ds18b20_WriteByte(0xbe); //发送读取温度命令 tml = Ds18b20_ReadByte(); //读取温度值共16位,先读低字节 tmh = Ds18b20_ReadByte(); //再读高字节 temp0 = tmh; temp0 <<= 8; temp0 |= tml; return temp0; } } void main(void) {uint tk=0; int i; int tk1=0; lcd_init(); delay1ms(50); while(1) {tk1=Ds18b20_ReadTemp(2); tk=Temperature(tk1); // read_b20sn(); if(ds_flag==0) { for(i=0;i<9;i++) {write_dat(dis1[i]);} b20display(tk) ;//显示温度 } else { lcd_pos(2,0); for(i=0;i<6;i++) {write_dat(dis1[i]);} } } } 为什么多点测温的时候就是就是出不来??? |
|
相关推荐
4 个讨论
|
|
你正在撰写讨论
如果你是对讨论或其他讨论精选点评或询问,请使用“评论”功能。
265 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
789 浏览 0 评论
1306 浏览 2 评论
787 浏览 0 评论
【RA4M2-SENSOR开发板评测】Analogue+Timers综合测试
1587 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16902 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 11:06 , Processed in 0.815861 second(s), Total 51, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
6161