单片机中使用DS18B20温度传感器C语言程序(参考1)/********************************************************************************DS18B20测温程序硬件:AT89S52(1)单线ds18b20接P2
2(2)七段数码管接P0口(3)使用外部电源给ds18b20供电,没有使用寄生电源软件:KeiuVision3**********************************************************************************/#include"reg52
h"#include"intrins
h"#defineucharunsignedchar#defineuintunsignedintsbitds=P2^2;sbitdula=P2^6;sbitwela=P2^7;ucharflag;uinttemp;//参数temp一定要声明为int型ucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//不带小数点数字编码ucharcodetable1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//带小数点数字编码/*延时函数*/voidTempDelay(ucharus){while(us--);}voiddelay(uintcount)//延时子函数{uinti;while(count){i=200;while(i>0)i--;count--;}}/*串口初始化,波特率9600,方式1*/voidinit_com(){TMOD=0x20;