Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 54
' -----[ Constants ]------------------------------------------------------------
'
' 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 specif ic device
' DS2890 control
'
RdPot CON $F0 ' read pot position
WrPot CON $0F ' write pot position
RdCtrl CON $AA ' read control register
WrCtrl CON $55 ' write control register
IncPot CON $C3 ' increment resistance
DecPot CON $99 ' decrement resistance
Release CON $96 ' release new pot setting
' -----[ Variables ]------------------------------------------------------------
'
romData VAR Byte(8) ' ROM data from device
idx VAR Byte
temp VAR Byte
potLevel VAR By te
rcValue VAR Word
' -----[ EEPROM Data ]----------------------------------------------------------
'
' -----[ Initialization ]-------------------------------------------------------
'
Get_SN:
DEBUG CLS
PAUSE 250 ' let debug window open
DEBUG "DS2980 - 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
DEBUG CLS
DEBUG "DS2980 - Setting control register"
Set_Ctrl:
' wiper 1, charge pump off
OWOUT OWpin, OW_FERst, [MatchROM, STR romData\8, WrCtrl, %00001100]
OWIN OWpin, OW_BERst, [temp] ' read back ctrl data
IF (temp = $FF) THEN Set_Ctrl ' $FF = invalid ctrl reg val
PAUSE 1000