Home > other >  DS18B20 procedures where to write the wrong will lead to full display 0
DS18B20 procedures where to write the wrong will lead to full display 0

Time:09-24

#include
#include
# define uint unsigned int
# define uchar unsigned char

Sbit DQ=P1 ^ 4;
Uchar tad []={xa4 xc0 0, 0 xf9, 0, 0 xb0, 0 x99, 0 x92, 0 x82, 0 xf8, 0 x80, 0 x90};
Uchar yi; Er;
Uchar wendu;

Void allinit (void);
Void disp (void);
Uchar DS18b20_shiyong (void);

Void main (void)
{
Allinit ();
While (1)
{
Wendu=DS18b20_shiyong ();

Yi=wendu/10; Er=wendu % 10;

Disp ();
}
}

Void allinit (void)
{
The P2=0 xa0; P0=0x00;
The P2=0 x80; P0=0 XFF;
The P2=0 xc0; P0=0 XFF;
The P2=0 xe0-0xfc; P0=0 XFF;
}

Void delay (uint I)
{
Uint j, k;
for(j=0; jFor (k=0; K<845; K++);
}

Void Delay100us ()//@ 11.0592 MHz
{
Unsigned char I, j;

_nop_();
_nop_();
I=2;
J=15;
Do
{
While (- j);
} while (I);
}

Void Delay500us ()//@ 11.0592 MHz
{
Unsigned char I, j;

_nop_();
_nop_();
I=6;
J=93;
Do
{
While (- j);
} while (I);
}

Void DS18b20_init (void)
{
DQ=0;
Delay500us ();
DQ=1;
Delay500us ();
}

Void DS18b20_xie uchar (dat)
{
Uint I;
for(i=0; i<8; I++)
{
DQ=0;
DQ=dat& 0 x01;
Delay100us ();
DQ=1;
Dat>=1;
}
}

Uchar DS18b20_du (void)
{
Uint I, temp.
for(i=0; i<8; I++)
{
DQ=0;
Temp>=1;
DQ=1;
If (DQ==1)
{
Temp=temp | 0 x80;
}
Delay100us ();
}
return temp;
}

Uchar DS18b20_shiyong (void)
{
Uchar gao di, temp.
DS18b20_init ();
DS18b20_xie (0 XCC);
X44 DS18b20_xie (0);
Delay500us ();
Delay500us ();

DS18b20_init ();
DS18b20_xie (0 XCC);
The xbe DS18b20_xie (0);

Di=DS18b20_du ();
Gao=DS18b20_du ();

Temp=gao<4.
Temp=temp | (di> 4);

return temp;
}

Void disp (void)
{
The P2=0 xc0; P0=0x01;
The P2=0 xe0-0xfc; P0=tad (yi), delay(5);

The P2=0 xc0; P0=0x02;
The P2=0 xe0-0xfc; P0=tad (er), delay(5);
}

CodePudding user response:

18 b20 stricter demands on time, you can try to delay longer and have a look
  • Related