当前位置: 首页 > ops >正文

单片机学习笔记.单总线one-wire协议(这里以普中开发板DS18B20为例)

硬件原理图: 


 DS18B20数据图:

 

 


首先根据原理图定义对应引脚:

sbit OneWire_DQ=P3^7;

 one-wire时序图:

one-wire初始化:

初始化时序分析: 

unsigned char OneWire_Init(void)
{unsigned char AckBit;OneWire_DQ=1;OneWire_DQ=0;Delay500us();OneWire_DQ=1;Delay70us();AckBit=OneWire_DQ;Delay500us();return AckBit;
}

one-wire读/写 1位:

one-wire读/写 1位 时序分析: 


 写一个位:

//写一个位
void OneWire_SendBit(unsigned char Bit)
{OneWire_DQ=0;Delay14us();//10usOneWire_DQ=Bit;Delay54us();//50usOneWire_DQ=1;
}

 接收一位: 

//接收一位
unsigned char OneWire_ReciveBit(void)
{unsigned char Bit;OneWire_DQ=0;Delay9us();//5usOneWire_DQ=1;Delay9us();//5usBit=OneWire_DQ;Delay54us();//50usreturn Bit;
}

  写入1个字节:

//写入一个字节
void OneWire_SendByte(unsigned char Byte)
{unsigned char i;for(i=0;i<8;i++){OneWire_SendBit(Byte&(0x01<<i));}
}

 发送1个字节: 

//发送1个字节
unsigned char OneWire_ReciveByte(void)
{unsigned char Byte=0x00;unsigned char i;for(i=0;i<8;i++){if(OneWire_ReciveBit()){Byte|=(0x01<<i);}}return Byte;
}

http://www.xdnf.cn/news/15972.html

相关文章:

  • 【测试开发】---Bug篇
  • 同步本地文件到服务器上的Docker容器
  • day60-可观测性建设-全链路监控各种客户端
  • 基于 Vue,SPringBoot开发的新能源充电桩的系统
  • MSTP技术
  • 4.组合式API知识点(2)
  • 微算法科技(NASDAQ: MLGO)探索优化量子纠错算法,提升量子算法准确性
  • Unity之C# 脚本与Unity Visual Scripting 交互
  • linux初识网络及UDP简单程序
  • 如何给手机充电才不伤电池?
  • css3地球转动模型(动态数据)
  • 快手视觉算法面试30问全景精解
  • spring事务?
  • uniapp 报错 Not found ... at view.umd.min.js:1的问题
  • Vue3 学习教程,从入门到精通,Vue3 循环语句(`v-for`)语法知识点与案例详解(13)
  • 渗透第2次作业
  • 学习游戏制作记录(战斗系统简述以及击中效果)7.22
  • Mixed Content错误:“mixed block“ 问题
  • Kotlin 中的单例模式(Singleton)与对象声明
  • SpringBoot+Mybatis+MySQL+Vue+ElementUI前后端分离版:权限管理(三)
  • Android开发:Java与Kotlin深度对比
  • 用ffmpeg 进行视频的拼接
  • ni-app 对鸿蒙的支持现状
  • Redis的五大基本数据类型
  • 有关Spring的总结
  • 【每日算法】专题十七_多源 BFS
  • React基础(1)
  • 【HarmonyOS】ArkUI - 声明式开发范式
  • 空间曲线正交投影及其距离计算的理论与实践
  • Anaconda 路径精简后暴露 python 及工具到环境变量的配置记录 [二]