mmbasic_original:read_temperature_from_dallas_ds18b20
Read Temperature from Dallas DS18B20
This module is part of the original MMBasic library. It is reproduced here with kind permission of Hugh Buckle and Geoff Graham. Be aware it may reference functionality which has changed or is deprecated in the latest versions of MMBasic.
FUN1WIRE.BAS
Print "The temperature is: " Format$(GetTemp(18), "%2.1f") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Function to get the temperature from a Dallas DS18B20. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Fun GetTemp(PinNbr) Local T1, T2, b, t OWReset PinNbr ' reset OWWrite PinNbr, 1, 2, &hcc, &h44 ' start conversion Pause 100 t = Timer Do If Timer - t > 1000 Then Error "Sensor not responding" OWRead PinNbr, 4 , 1 , b ' conversion done? Loop Until b = 1 OWWrite PinNbr, 1, 2, &hcc, &hbe ' command read data OWRead PinNbr, 2, 2, T1, T2 ' get the data GetTemp = ((T2 And &b111) * 256 + T1) / 16 If T2 And &b1000 Then GetTemp = -GetTemp ' adjust if < 0 End Fun
mmbasic_original/read_temperature_from_dallas_ds18b20.txt · Last modified: 2024/02/24 16:31 by gerry