Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 33
' -----[ Initialization ]--------------------------------------------------
'
Initialize:
PAUSE 500 ' let DEBUG window open
' -----[ Main Code ]-------------------------------------------------------
'
Main:
DEBUG CLS
GOSUB Device_Check ' look for device
IF (devCheck <> NoDevice) THEN Display_ROM
No_Device_Found:
DEBUG "No 1-Wire device present."
END
Display_ROM:
OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC
IF (romData(7) < $FF) THEN Show_Device
DEBUG CLS,"Bad device?"
END
Show_Device
DEBUG "Dallas 1 -Wire ID : ", HEX2 romData(0), " ("
GOSUB Display_Device_Type
DEBUG ")",CR
DEBUG " Serial Number : "
FOR idx = 6 TO 1
DEBUG HEX2 romData(idx)
NEXT
DEBUG CR, " Checksum : ", HEX2 romData(7),CR,CR
DEBUG " Stamp Data : ",IHEX2 romData(0)
FOR idx = 1 TO 7
DEBUG ",",IHEX2 romData(idx)
NEXT
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
' This subroutine is used to display the part number of a 1-Wire device.
' The text data and pointers to it are stored in the EE of a different
' program slot.