Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 51
' -----[ I/O Definitions ] ------------------------------------------------------
'
OWpin CON 15 ' 1 -Wire bus
' -----[ Constants ]------------------------------------------------------------
'
On CON 0 ' pull cathode to ground
Off CON 1
' 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
' -----[ Variables ]------------------------------------------------------------
'
romData VAR Byte(8) ' ROM data from device
idx VAR Nib
rndValue VAR Word ' random value
flags VAR rndValue.LowByte ' flags byte
ledFlag VAR flags.Bit7 ' LED flag
status VAR bit
' -----[ EEPROM Data ]----------------------------------------------------------
'
' -----[ Initialization ]-------------------------------------------------------
'
Get_SN:
DEBUG CLS
PAUSE 250 ' let debug window open
DEBUG "DS2405 - Reading serial number"
OWOUT OWpin,OW_FERst,[ReadROM] ' send Read ROM command
OWIN OWpin,OW_BERst,[STR romData\8] ' read serial number & CRC
DEBUG CR, " "
FOR idx = 6 TO 1 ' display serial number
DEBUG HEX2 romData(idx)
NEXT
PAUSE 1000
' -----[ Main Code ]------------------------------------------------------------
'
Main:
DEBUG CLS
DEBUG "DS2405 Digital Switch Demo (LED = flags.Bit7)"
Show_Flags
PAUSE 1000 ' delay between tests
GOSUB Shake_Flags ' randomize output
DEBUG Home, CR, CR, "Flags... ", BIN8 flags, CR
IF (ledFlag) THEN LED_On