Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 42
' 1-Wire Support
'
OW_FERst CON %0001 ' Front-End Reset
OW_BERst CON %0010 ' Back-End Reset
OW_BitMode CON %0100
OW_HighSpd CON %1000
ReadROM CON $33 ' read ID, serial num, CRC
MatchROM CON $55 ' look for specific device
SkipROM CON $CC ' skip rom (one device)
SearchROM CON $F0 ' search
' DS1822 control
'
CnvrtTemp CON $44 ' do temperature conversion
RdScratch CON $BE ' read scratchpad
NoDevice CON %11 ' no device present
DS1822 CON $22 ' device code
DegSym CON 176
' -----[ Variables ]------------------------------------------------------------
'
devCheck VAR Nib ' device check return ocde
idx VAR Byte ' loop counter
romData VAR Byte(8) ' ROM data from DS1820
tempIn VAR Word ' raw temperature
sign VAR tempIn.Bit11 ' 1 = negative temperature
tLo VAR tempIn.LowByte
tHi VAR tempIn.HighByte
tSign VAR Bit
tempC VAR Word ' Celsius
tempF VAR Word ' Fahrenheit
' -----[ EEPROM Data ]----------------------------------------------------------
'
' -----[ Initialization ]-------------------------------------------------------
'
Initialize:
DEBUG CLS
PAUSE 250 ' allow DEBUG screen to open
' -----[ Main Code ]------------------------------------------------------------
'
Main:
GOSUB Device_Check ' look for device
IF (devCheck <> NoDevice) THEN Get_ROM
No_Device_Found:
DEBUG CLS,"No DS1822 present.", CR
DEBUG "-- Insert device and re-start."
END
Get_ROM
OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC
IF (romData(0) = DS1822) THEN Show_Data