电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

18B20温度传感器C语言编程实例

5页
  • 卖家[上传人]:鲁**
  • 文档编号:494038423
  • 上传时间:2023-01-01
  • 文档格式:DOCX
  • 文档大小:13.15KB
  • / 5 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、温度传感器C语言编程实例#include #includevintrins.h 含有nop_ ();#include /含有运算#define uchar unsigned char#define uint unsigned intsbit DQ=P3人7;/数据、时钟线uchar duanma=0XFC,0X60,0XDA,0XF2,0X66,0XB6,0XBE,0XE0, 0XFE,0XF6;uint wendu; /定义温度值存储位置/ uchar bdata date; 原来是用来移动数据的float f_num;因为温度传感器的精度为0.0625所以设一个float行的变量/ sbit d=dateA0;void delay_ms(uint ms)uchar i,j; for(i=ms;i0;i-) for(j=110;j0;j-);void delay_us() /25us 延时_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_

      2、nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_();/ 、/Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx ,init()初始化复位程序变量i;还有一nop是用来延时的时序:1、2us、0、480us、等待确认;在延时20us、1/Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /void init()uint i;DQ=1;_nop_

      3、();DQ=0;delay_us();/1delay_us();/2delay_us();/3delay_us();/4delay_us();/5delay_us();/6delay_us();/7delay_us();/8delay_us();/9DQ=1;i=10;while(i-)&(DQ=1);i=10;while(i-);DQ=1;*1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* 1 Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx ,字节写:write_by

      4、te变量x用来产生for循环在写的过程中,0 和一是分开写的时序:0、15us、把数据植入、45us、1、重复前面、1当进行写数据时0和1是分开写的;但是时序也要分开写void write_byte(uchar date)/传递过来的参数是操作指令例如:0xcc, 0x44; 0xbe uchar x;bit testb; for(x=0;x=1;没去一次向左移动一次if(testb)DQ=0;_nop_();_nop_();DQ=1;delay_us();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_(); DQ=1;delay_us();elseDQ=0;_nop_();_nop_();DQ=0;delay_us();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_(); DQ=1;DQ=1;位读程序:这

      5、样做的目的是为了把程序写的更有条理性 而且程序的类型是bit型的,因此返回值为bit型的 时序:0、15us、把数据置入、45us、1/Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /bit read_bit()bit bt;DQ=1;_nop_();_nop_();DQ=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();DQ=1;_nop_();_nop_();_nop_();_nop_(); bt=DQ;return bt;/ *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1

      6、* *1* / Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx a 字节读程序:为了将上面的位读程序组合起来变量:shuju是用来将独处的数据存入/Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /uchar read_byte()uchar n,k,shuju;shuju=0;for(n=0;n8;n+)k=read_bit();shuju=(k1);/这是一个将位数据转换成字节数据,先接受的是低位delay_us();return shuju;/ Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx

      7、 Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx启动温度转换: 在进行对传感器操作之前必须先写入初始化程序 先写入跳跃器件地址指令 0xcc 再写入启动温度转换指令 0x44*1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* / Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx

      8、Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /void start()init();delay_ms(1); write_byte(0xcc);write_byte(0x44);向18b20写入启动温度转换指令/ Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx温度转换及处理程序: 他的做用是将温度值读出因为读出0的数据是两个char型数据需要将它转换成一个uint型的 这样才能把显示做出来/Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /uint wenduchange()uchar a,b;init(); / 初始化;

      《18B20温度传感器C语言编程实例》由会员鲁**分享,可在线阅读,更多相关《18B20温度传感器C语言编程实例》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    监控施工 信息化课堂中的合作学习结业作业七年级语文 发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.