Name:
readtemp
Syntax:

READTEMP pin,variable

Pin - is the input pin.

Variable - receives the data byte read.

Description:

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 with the older DS1820 or DS18S20 as they have a different internal resolution. This command is not designed to be used with parasitically powered DS18B20 sensors, the 5V pin of the sensor must always be connected.

This command cannot be used on the following pins due to silicon restrictions:

08M, 08M2 C.3 = fixed input, C.0 = fixed output
14M, 14M2 C.3 = fixed input, B.0 = fixed output
18M2 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.

Applies To:
All (except 08, 18, 28)
See Also:
Related Create:
Share:
Print:

Read temperature

Read a DS18B20 temperature sensor on pin C.1 and report the temperature

Code Example:
main:	readtemp C.1,b1		; read value into b1
	if b1 > 127 then neg	; test for negative
	serout B.7,N2400,(#b1)	; transmit value to serial LCD
	goto loop
neg:
	let b1 = b1 - 128	; adjust neg value
	serout B.7,N2400,(“-”)	; transmit negative symbol
	serout B.7,N2400,(#b1)	; transmit value to serial LCD
	goto main
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.

Comments

  • Login to leave a comment.