完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
#include
#include #define uchar unsigned char #define uint unsigned int uint temp; // variable of temperature ***it DS=P1^0; //define interface void delay1(uchar count) { while(count>0) count--; } void reset(void) //send reset and initialization command { DS=0; delay1(100); DS=1; delay1(4); delay1(200); } bit read_bit(void) //read a bit { bit temp; DS=0; _nop_(); DS=1; _nop_(); temp=DS; delay1(200); return temp; } uchar read_byte(void) //read a byte date { uchar i,byte=0; bit j; for(i=0;i<8;i++) { byte=_cror_(byte ,1); j=read_bit(); if(j==0) byte=byte|0x00; else byte=byte|0x80; } return byte; } void write_byte(uchar command) //write a byte to ds18b20 { uchar i; for(i=0;i<8;i++) { if((command & 0x01)==0) { DS=0; delay1(8); DS=1; _nop_(); } else { DS=0; _nop_(); DS=1; delay1(8); } command=_cror_(command,1); } } void tmpchange(void) //DS18B20 begin change { reset(); write_byte(0xcc); //直接向18b20发送温度变换命令 write_byte(0x44); //启动18b20进行温度转换 } uint tmp() //get the temperature { float tt; uchar a,b; reset(); write_byte(0xcc); //直接向18b20发送温度变换命令 write_byte(0xbe); //读取温度寄存器的温度值 a=read_byte();//读低八位 b=read_byte();//读高八位 temp=b; temp<<=8; //two byte compose a int variable temp=temp|a; tt=temp*0.0625; temp=tt*10+0.5; return temp; } |
|
相关推荐
1个回答
|
|
|
18b20的芯片资料对照看一下就明白了
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
265 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
789 浏览 0 评论
1306 浏览 2 评论
787 浏览 0 评论
【RA4M2-SENSOR开发板评测】Analogue+Timers综合测试
1587 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16901 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 04:35 , Processed in 0.714473 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1930