求助:写了个用DS18B20程序但是不知道为什么只显示85摄氏度求各位帮我看看该怎么办
[复制链接]
#include<reg51.h>
#include<absacc.h>
#include<intrins.h>
sbit DQ=P1^3;
unsigned char a[6]={0x40,0x40,0x40,0x40,0x40,0x40};
unsigned char b[ ]={0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9};
unsigned char code c[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay (unsigned char i)
{
while(i--);
}
void reset1820 ()
{
DQ=1;_nop_();
DQ=0;
delay(100);
DQ=1;
delay(12);
}
unsigned char rd1820()
{
unsigned char i,d=0;
for (i=0;i<8;i++)
{
DQ=0;
d>>=1;
DQ=1;_nop_();
if (DQ)d|=0x80;
delay(12);
}
return d;
}
void wr1820 (unsigned char d)
{
unsigned char i;
for(i=0;i<8;i++)
{
DQ=0;_nop_();
DQ=d&0x01;
delay(12);
DQ=1;
d>>=1;
}
}
void chag (unsigned char x[],unsigned char y[])
{
y[5]=0x39;
y[0]=0;
if((x[1]&0xf8)==0xf8)
{
x[1]=~x[1];
x[0]=~x[0]+1;
if(x[0]==0) x[1]=x[1]+1;
y[0]=0x40;
}
y[4]=b[x[0]&0x0f];
y[4]=c[y[4]];
x[1]=(x[1]&0x0f)<<4;
x[0]=(x[0]&0xf0)>>4;
x[0]=x[0]|x[1];
y[1]=x[0]/100;
y[2]=(x[0]%100)/10;
y[3]=c[x[0]%10]|0x80;
if(y[1]!=0) y[1]=c[y[1]];
if((y[1]!=0)|(y[2]!=0))
y[2]=c[y[2]];
}
void disp (unsigned char n)
{
unsigned char i,j;
for(j=0;j<n;i++)
{
for(i=0;i<6;i++)
{
P1=(P1&0XF8)+i;
XBYTE[0X7FFF]=a[i];
delay(300);
}
}
}
void main ()
{
unsigned char t[2];
while(1)
{
reset1820();
if(DQ==0)
{
delay (15000);
wr1820 (0xcc);
wr1820 (0x44);
reset1820();
delay (15000);
wr1820 (0xcc);
wr1820 (0xbe);
t[0]=rd1820 ();
t[1]=rd1820 ();
delay(15000);
chag (t,a);
}
disp(100);
}
}
|