Datasheet

Jon Waddington
31
pulse, followed by the “Skip ROM” command. This skips the ROM transmission and the
code then transmits the “ConvertT” command which notifies the DS18B20 to start
converting the temperature.
The code then transmits read slots on the bus and the DS18B20 continues to transmit ‘0’
until the conversion is complete and it transmits a ‘1’.
The code continues by transmitting another “Skip ROM” command and the “Read
Scratchpad” command. The “Read Scratchpad” command notifies the DS18B20 to begin
transmitting the contents of the Scratchpad, starting with the first byte, the least
significant bit of the temperature, and finishing with the CRC.
After receiving the first two bytes and joining them together, the code transmits a reset
pulse which informs the DS18B20 that no more information is to be received.
PRI readtc | tc
'' Reads temperature from DS1820
ow.reset
ow.write(SKIP_ROM)
ow.write(CVRT_TEMP)
repeat ' let conversion finish
tc := ow.rdbit
until (tc == 1)
ow.reset
ow.write(SKIP_ROM)
ow.write(RD_SPAD)
tc := ow.read ' lsb of temp
tc |= ow.read << 8 ' msb of temp
ow.reset
return tc
The “showc” method is shown below, this shows the temperature on the television
screen in degrees Celsius. It begins by shifting the bits left 16 places as the variable is
32 bits in length. This is to check if the temperature is positive or negative. If it is
negative, a minus sign is shown and the sign of the variable is changed.
The variable is shifted back to the right 16 bits and then shifted another 4 bits to discard
the lower 4 bits. The temperature is then displayed on the screen, followed by “°C”.
PRI showc (tc) | t', dp