ds18b20显示温度不正确#include#includesbit DQ=P1^7;sbit led=P1^0;#define uchar unsigned char#define uint unsigned charuchar code table[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};uchar data sex[3];uchar num;void delayus(uchar
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/18 03:25:20
ds18b20显示温度不正确#include#includesbit DQ=P1^7;sbit led=P1^0;#define uchar unsigned char#define uint unsigned charuchar code table[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};uchar data sex[3];uchar num;void delayus(uchar
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
ds18b20显示温度不正确#include#includesbit DQ=P1^7;sbit led=P1^0;#define uchar unsigned char#define uint unsigned charuchar code table[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};uchar data sex[3];uchar num;void delayus(uchar
只能测试0---15.9度,说明你只读取温度的低八位,也就是a=ds18b20read();
从程序上看,你的定义的uint.#define uint unsigned char
定义错误,更改成#define uint unsigned int
所以在你temp