-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDS18B20T.OPL
48 lines (39 loc) · 1.18 KB
/
DS18B20T.OPL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
DS18B20T:(SP$)
REM Convert DS18B20 Scratch pad to temperature
REM Byte 4 of the scratch pad memory contains the configuration register
REM (c) Copyright 2024 nofitnessforpurpose All Rights Reserved
REM Revision : 0.1
REM Modified : NotFitForPurpose
REM Date : 30 Nov 2024
REM +----+----+----+----+----+----+----+----+
REM : B0 : B1 : B2 : B3 : B4 : B5 : B6 : B7 :
REM +---------------------------------------+
REM B0 = Temperature LSB
REM B1 = Temperature MSB
REM B2 = th Register
REM B3 = tl Register
REM B4 = Configuration Register
REM B5 = Reserved ($FF)
REM B6 = Reserved
REM B7 = Reserved ($10)
REM B8 = CRC
LOCAL b% : REM Scaling setting
LOCAL l, m : REM LSB - MSB
LOCAL t : REM Calculated temperature
REM Verify checksum
m = FLT(ASC(MID$(SP$, 2, 1))) * 256
l = ASC(MID$(SP$, 1, 1))
t = m + l
REM Get resolution from B4 of the Scratch Pad B4 bits 5 and 6
b% = ASC(MID$(SP$, 5, 1)) AND 96
REM Scale the raw values to temperature in Deg. C
IF b% = 96
t = t * 0.0625 : REM 12 Bit
ELSEIF b% = 64
t = t * 0.125 : REM 11 Bit
ELSEIF b% = 32
t = t * 0.250 : REM 10 Bit
ELSEIF b% = 0
t = t * 0.500 : REM 9 Bit
ENDIF
RETURN t