Data Sheet
25
un t il ( (ad d r ~= ni l ) or (c o u n t > 100 ) )
ow. re s e t _ s e a rc h( p i n )
en d
if ( a d d r == ni l ) th e n
re t u r n re s u lt
en d
crc = ow.c r c 8 ( s t ri n g . s u b (a d d r, 1 , 7 ) )
if (c r c == add r : by te ( 8 )) th e n
if (( a d d r : b y te ( 1 ) == 0x10 ) or (a d d r : b y t e ( 1 ) == 0x28 ) ) th e n
-- pr in t ( " D ev i c e is a DS 1 8 S 2 0 fa m i l y de v i c e ." )
ow. re s e t ( p in )
ow. s e l e c t ( p i n , ad d r )
ow.w r i t e( p i n, 0x 4 4 , 1)
-- tm r.d e l ay ( 1 0 0 0 0 0 0 )
pr e s e n t = ow.re s et ( pi n )
ow. s e l e c t ( p i n , ad d r )
ow.w r i t e( p i n, 0 x B E , 1 )
-- pr in t ( " P = " . .p r e sen t )
da ta = ni l
da ta = st r i n g . c ha r(ow.re a d ( p i n ) )
fo r i = 1, 8 do
da ta = da ta .. st r i n g. c h a r ( o w. read ( p i n) )
en d
-- pr in t ( d a t a : b y t e ( 1 , 9 ) )
crc = ow. c rc 8 ( st r i n g .s u b ( da ta ,1, 8 ) )
-- pr in t ( " C RC= " . .c r c )
if (c r c == da t a : b y t e ( 9 ) ) th e n
if ( u n i t == ni l or un i t == C) th e n
t = (d a t a : b y te ( 1 ) + da ta: by te (2 ) * 25 6 ) * 62 5
el s ei f ( u n i t == F) th e n
t = (d a t a : b y te ( 1 ) + da ta: by te (2 ) * 25 6 ) * 11 2 5 + 32 0 0 0 0
el s ei f ( u n i t == K) th e n
t = (d a t a : b y te ( 1 ) + da ta: by te (2 ) * 25 6 ) * 62 5 + 273 1 5 0 0
el s e
re tu r n ni l
en d
t1 = t / 1 0 0 0 0
t2 = t % 10 0 0 0
-- pr in t ("Te m p e r at u r e =" ..t 1 . .". " . . t2 .. " Ce n tig r a d e " )
-- re s u l t = t1 . . " . " ..t 2
re tu r n t1 , t2
en d
tm r.w d c l r ( )
el s e