
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 43
DEBUG "Installed device is not DS1822", CR
DEBUG "-- Code = ",HEX2 romData(0)
END
Show_Data:
DEBUG Home, "DS1822 Data",CR,CR
DEBUG "Serial Number : "
FOR idx = 6 TO 1
DEBUG HEX2 romData(idx)
NEXT
DEBUG CR," Checksum : ",HEX2 romData(7),CR,CR
Show_Raw:
GOSUB Get_Temp
DEBUG " Raw Input : ",BIN16 tempIn,CR,CR
Display_Temperatures:
DEBUG " Temp C : ", SDEC tempC,DegSym,CR
DEBUG " Temp F : ", SDEC tempF,DegSym,CR
PAUSE 1000
GOTO Main
END
' -----[ Subroutines ]----------------------------------------------------------
'
' This subroutine checks to see if any 1-Wire devices are present on the
' bus. It does NOT search for ROM codes
'
Device_Check:
devCheck = 0
OWOUT OWpin,OW_FERst,[SearchROM] ' reset and start search
OWIN OWpin,OW_BitMode,[devCheck.Bit1,devCheck.Bit0]
RETURN
Get_Temp:
OWOUT OWpin,OW_FERst,[SkipROM,CnvrtTemp] ' send conversion command
PAUSE 500 ' give it some time
OWOUT OWpin,OW_FERst,[SkipROM,RdScratch] ' go get the temperature
OWIN OWpin,OW_BERst,[tLo,tHi]
tSign = sign ' save sign bit
tempC = tempIn
tempC = tempC >> 4 ' round to whole degrees
IF (tSign = 0) THEN NoNegC
tempC = tempC | $FF00 ' extend sign bits for negs
NoNegC:
tempF = tempC */ $01CD ' multiply by 1.8
IF tSign = 0 THEN NoNegF ' if neg, extend sign bits
tempF = tempF | $FF00
NoNegF:
tempF = tempF + 32 ' finish C -> F conversion
RETURN