Pin - is the input pin.
Variable - receives the data byte read.
Read temperature from a DS18B20 digital temperature sensor and store in variable.
The conversion takes up to 750ms. Readtemp carries out a full 12 bit conversion and then rounds the result to the nearest full degree Celsius (byte value). For the full 12 bit value use the readtemp12 command. The temperature is read back in whole degree steps, and the sensor operates from -55 to +125 degrees Celsius. Note that bit 7 is 0 for positive temperature values and 1 for negative values (ie negative values will appear as 128 + numeric value).
Note the readtemp command does not work directly with the older DS1820 or DS18S20 as they have a different internal resolution. However example 2 below shows a workaround for the DS18S20. The readtemp command is not designed to be used with parasitically powered DS18B20 sensors (DS18B20-PAR) as the 5V pin of the sensor must always be connected.
This command cannot be used on the following pins due to silicon restrictions:
||C.3 = fixed input, C.0 = fixed output
||C.3 = fixed input, B.0 = fixed output
||C.3 = fixed output, C.4, C.5 = fixed input
|20M, 20M2, 20X2
||C.6 = fixed input, A.0 = fixed output
Effect of increased clock speed
This command only functions at 4MHz. M2, X1 and X2 parts automatically use the internal 4MHz resonator for this command.