作业帮 > 综合 > 作业

ds18b20,我想改变它的精度,让数码管显示能出小数点后一位,谁能帮我把程序改改?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/04 04:17:11
ds18b20,我想改变它的精度,让数码管显示能出小数点后一位,谁能帮我把程序改改?
//18B20单线温度检测的应用样例程序
#include
//
//18b20初始化函数
void Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1; //DQ复位
delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
delay(10);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(5);
}
//读一个字节
unsigned char ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
delay(5);
}
return(dat);
}
//写一个字节
void WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
delay(5);
DQ = 1;
dat>>=1;
}
delay(5);
}
//读取温度
unsigned char ReadTemperature(void)
{
unsigned char a=0;
unsigned char b=0;
long int t=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
delay(200);
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
a=ReadOneChar();
b=ReadOneChar();
b4;
t=b;
return(t);
}
要能在数码管上显示出来哦……包括小数点.
是八位共阳级的吗?试试我的程序吧 我自己改的 可以显示小数点后一位.
帮你写了很详细的备注信息,应该看的懂了把?你的悬赏分是0很杯具.
//