DS18B20温度格式转换
来源:互联网 发布:excel中一行数据求和 编辑:程序博客网 时间:2024/05/17 07:03
#include <stdio.h>#include <stdint.h>/* DS18B20温度格式转换 */uint8_t tempIntPart[3];uint8_t tempDecPart[4];float convertToFloat(int16_t temperature) { float temp; temp = (float)temperature; temp /= 16.0f; return temp;}void splitIntPart(int16_t temperature) { uint8_t i; if (temperature & 0x8000) temperature = -temperature; temperature >>= 4; for (i = 0; i < 3; i++) { //逆向存 tempIntPart[i] = temperature % 10; temperature /= 10; }}void splitDecPart(int16_t temperature) { uint8_t decPart; if (temperature & 0x8000) temperature = -temperature; decPart = (uint8_t)(temperature & 0x000F); tempDecPart[0] = (decPart * 10) >> 4; tempDecPart[1] = ((decPart * 100) >> 4) % 10; tempDecPart[2] = ((decPart * 1000) >> 4) % 10; tempDecPart[3] = ((decPart * 10000) >> 4) % 10;}int main() { int16_t temperature = 0x00AB, i; printf("%f\n", convertToFloat(temperature)); splitIntPart(temperature); splitDecPart(temperature); for (i = 2; i >= 0; i--) printf("%hhd", tempIntPart[i]); printf("\n"); for (i = 0; i < 4; i++) printf("%hhd", tempDecPart[i]); printf("\n"); return 0;}
0 0
- DS18B20温度格式转换
- DS18B20温度转换与显示
- DS18B20的温度测量
- DS18B20温度模块.C
- 51+DS18B20测量温度
- 1602液晶显示DS18B20温度
- DS18B20温度测量
- DS18B20温度传感源代码
- stm32---DS18B20温度
- 单片机温度控制系统DS18B20
- 单片机ds18b20测量温度
- DS18B20温度报警器
- stm8 ds18b20读温度代码
- CC2530之DS18B20温度测量
- DS18B20显示温度并报警
- 树莓派3 读取DS18B20 温度
- DS18B20 LCD显示当前温度
- 单片机DS18b20 温度检测液晶显示
- Android系统回顾(八):网络通信(二)
- 【Tracking】【论文阅读随记一】-iccv11-Superpixel Tracking
- spring3 mvc中POST和GET乱码的解决
- app图片
- 完美解决.net2.0和.net4.0在同一个iis中共同运行
- DS18B20温度格式转换
- launcher之workspace
- Linux 通用Makefile模板
- Object-C 类,对象,运行时,isa
- Java用数组实现堆
- 例子解析C++的引用,传参,const的相关特点
- IOS开发之----Xcode非ARC项目中设置部分文件ARC支持
- 一些关于Deep Learn方面的资料,牛人主页,资源链接
- Length of the longest substring without repeating characters