Read the code:
Unsigned char Ds18b20Read (void)
{
Unsigned char Value=https://bbs.csdn.net/topics/0x00;
Unsigned int I;
//ds18b20IO_1 ();
//Ds18b20Delay (3);
for(i=0; i<8; I++)
{
The Value & gt;>=1;
//down
Ds18b20OutputInitial ();
Ds18b20IO_0 ();
Ds18b20Delay (3);
//release
Ds18b20IO_1 ();
Ds18b20Delay (3);
If (P2IN & amp; BIT2)
The Value |=0 x80;
Ds18b20Delay (60);
}
The return Value.
}
Read:
Ds18b20Initial ();
Ds18b20Write (0 XCC);//skip reading the operation of the serial number column number
X44 Ds18b20Write (0);//start temperature conversion
Ds18b20Delay (2000);
Ds18b20Initial ();
Ds18b20Write (0 XCC);//skip reading the operation of the serial number column number
The xbe Ds18b20Write (0);//read temperature register (total 9 readable registers) is the first two temperature
V1=Ds18b20Read ();//low
V2=Ds18b20Read ();//high
Middle latency, with 2000 us tried 800 ms and 200 us each test data, the waveform:
From the response of reduction device can be normal response, and the equipment replacement, should not equipment problem, why this reply is a high level of information, where is the wrong the 18 b20 not be answered is low, or delay problem sequence is wrong? Ask for advice
CodePudding user response:
In the program did not reflect Ds18b20Delay (3); The delay time, the original poster can refer to the sequence diagram to see whether there is something wrong with the sequentialCodePudding user response:
18 b20 pair from the length of the demand is higher, should be accurateCodePudding user response:
Thank you two reply, I feel, I should be out of the reading, but they do not know how to start, I changed the time delay in two, is as follows:Unsigned char Value=https://bbs.csdn.net/topics/0x00;
Unsigned int I;
Ds18b20IO_1 ();
Ds18b20Delay (3);
for(i=0; i<8; I++)
{
The Value & gt;>=1;
//down
Ds18b20OutputInitial ();
Ds18b20IO_0 ();
Ds18b20Delay (10);
//release
Ds18b20IO_1 ();
Ds18b20Delay (3);
If (P2IN & amp; BIT2)
The Value |=0 x80;
Ds18b20Delay (47);
Ds18b20Delay (3);
}
The return Value.
Said, my understanding of the reading sequence:
1, the host for the output low, delay 10 us
2, release to input, delay 3 us waiting for stable
3, read, delay time of 1 and 2 less than 15 us
4, delay 47, gather together enough reading time slot of 60 us
5, recovery delay 3 us
I understand it right?
Another problem, manuals, data conversion is 12 about 750 ms, but looked at a lot of code not so long, will have an impact on, or the data to read, is the result of the transformation of last time?
thank you