历史上的今天
今天是:2025年05月09日(星期五)
2019年05月09日 | DS18B20温度格式转换
2019-05-09 来源:eefocus
#include #include /* 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("%fn", 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; }
上一篇:51单片机与递归的问题
下一篇:将一个字节存储的2位BCD码解码
史海拾趣
|
--8位10进制频率计 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity ftctrl3 is port(clkk:in std_logic; cnt_en:out std_log ...… 查看全部问答> |
|
6410下,通过IROM_Fusing_Tool.exe制做SD卡启动盘,烧东西进去,SD卡的容量怎么没变化?隐藏了? 6410下,通过IROM_Fusing_Tool.exe制做SD卡启动盘,烧东西进去,SD卡的容量怎么没变化?隐藏了?… 查看全部问答> |
|
高级嵌入式软件工程师Sr. Embedded Software Engineer 岗位描述: 1、负责嵌入式软件和产品设计。 2、负责嵌入式软件开发。 任职要求: 1、通信、电子或计算机类相关专业,本科以上学历; 2、五年以上相关工作经验; 3、需要熟悉WINDOWS CE. ...… 查看全部问答> |
|
高薪聘Windows Mobile 底层驱动开发工程师(深圳南山) 高薪聘Windows Mobile 底层驱动开发工程师 公司网址:www.bitland.com.cn ,偶QQ549503575 ;E-mail:yangsq@bitland.com.cn 有兴趣的可以加我细聊 待 ...… 查看全部问答> |
|
电赛‘一目了然’历年元器件清单对比(2003--2011)excel格式 历年元器件清单对比 对比看更清楚!!! [ 本帖最后由 GTao_12345 于 2011-8-25 17:08 编辑 ]… 查看全部问答> |
|
SGSTM8-III 开发板使用STMS105S4芯片 含全套 的视频教程,需要的可以联系我 STM8 开发板的1602 液晶屏的效果图 、 12864 液晶的效果图 ADC结合数码管的效果图 ...… 查看全部问答> |
|
什么是伺服控制系统,衡量伺服控制系统性能的主要指标系统精度、稳定性、响应特性、工作频率四大方面,特别在频带宽度和精度方面。频带宽度简称带宽,由系统频率响应特性来规定,反映伺服系统的跟踪的快速性。带宽越大,快速性越好。伺服系统 ...… 查看全部问答> |




