ds18b20显示温度不正确
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/02 16:07:29
ds18b20显示温度不正确
#include
#include
sbit DQ=P1^7;
sbit led=P1^0;
#define uchar unsigned char
#define uint unsigned char
uchar code table[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
uchar data sex[3];
uchar num;
void delayus(uchar gaq)
{
while(gaq--);
}
void ds18b20rest() //复位
{
uchar x;
DQ=1;
delayus(2);
DQ=0;
delayus(80);
DQ=1;
delayus(5);
x=DQ;
delayus(18);
if(x) //判断初始化成功了么
led=0;
}
void ds18b20write(uchar date) //写函数
{
uchar i;
for(i=0;i>=1;
}
}
uchar ds18b20read() //读函数
{
uchar i,date;
for(i=0;i>=1;
DQ=1;
if(DQ)
date=date|0x80;
delayus(7);
}
return(date) ;
}
void main()
{
uchar a,b;
uint temp,temp_i;
float temp_f;
TMOD=0x10;
TH0=0xfb;
TL0=0xe0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
ds18b20rest();
ds18b20write(0xcc);
ds18b20write(0x44);
delayus(255);
ds18b20rest();
ds18b20write(0xcc);
ds18b20write(0xbe);
a=ds18b20read();
b=ds18b20read();
temp=b;
temp
#include
#include
sbit DQ=P1^7;
sbit led=P1^0;
#define uchar unsigned char
#define uint unsigned char
uchar code table[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
uchar data sex[3];
uchar num;
void delayus(uchar gaq)
{
while(gaq--);
}
void ds18b20rest() //复位
{
uchar x;
DQ=1;
delayus(2);
DQ=0;
delayus(80);
DQ=1;
delayus(5);
x=DQ;
delayus(18);
if(x) //判断初始化成功了么
led=0;
}
void ds18b20write(uchar date) //写函数
{
uchar i;
for(i=0;i>=1;
}
}
uchar ds18b20read() //读函数
{
uchar i,date;
for(i=0;i>=1;
DQ=1;
if(DQ)
date=date|0x80;
delayus(7);
}
return(date) ;
}
void main()
{
uchar a,b;
uint temp,temp_i;
float temp_f;
TMOD=0x10;
TH0=0xfb;
TL0=0xe0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
ds18b20rest();
ds18b20write(0xcc);
ds18b20write(0x44);
delayus(255);
ds18b20rest();
ds18b20write(0xcc);
ds18b20write(0xbe);
a=ds18b20read();
b=ds18b20read();
temp=b;
temp
只能测试0---15.9度,说明你只读取温度的低八位,也就是a=ds18b20read();
从程序上看,你的定义的uint.#define uint unsigned char
定义错误,更改成#define uint unsigned int
所以在你temp
从程序上看,你的定义的uint.#define uint unsigned char
定义错误,更改成#define uint unsigned int
所以在你temp
ds18b20显示温度不正确
DS18B20温度显示的问题
ds18b20负温度显示问题
ds18b20 为什么读不出温度
DS18B20温度转换
用LCD1602和DS18B20显示温度和时间C语言程序
关于ds18b20的温度补偿
ds18b20温度是几位的呀
ds18b20 温度读回程序
单片机从ds18b20读出的数据经过怎样的处理用于显示,只用说正数温度就行啦
用DS18B20单总线温度传感器实现一个温度计,测温范围0~100度,精度+/-0.25度,温度用数码管显示
在运行数字温度计仿真(proteus)时,怎样初始化温度? 为什么只显示0,我的DS18B20读取温度程序应该没问题