Action
These routines can be used to communicate with Dallas Semiconductors 1Wire-devices.
Syntax 1 for use with the CONFIG 1WIRE statement
1WRESET
1WWRITE var1 [ , bytes]
var2 = 1WREAD( [ bytes])
Syntax 2 for use with multiple devices/pins
1WRESET pin
1WWRITE var1 [ , bytes] pin
var2 = 1WREAD( [ bytes] [, pin])
var2 = 1WREAD( [pin])
Pin is the port pin to use with the device such as P1.1
Remarks
1WRESET |
Reset the 1WIRE bus. The error variable ERR will return 1 if an error occurred. |
1WWRITE var1 |
Sends the value of var1 to the bus. Optional is the number of bytes that mist be sent. var1 is a numeric variable or constant. |
var2 = 1WREAD() |
Reads a byte from the bus and places it into var2. Optional is the number of bytes that must be read. var2 is a number variable. |
Example
'--------------------------------------------------------------
' 1WIRE.BAS
' demonstrates 1wreset, 1wwrite and 1wread()
' pull-up of 4K7 required to VCC from P.1
' DS2401 serial button connected to P1.1
'--------------------------------------------------------------
Config 1wire = P1.1 'use this pin
Dim Ar(8) As Byte , A As Byte , I As Byte
1wreset 'reset the device
Print Err 'print error 1 if error
1wwrite &H33 'read ROM command
For I = 1 To 8
Ar(i) = 1wread() 'place into array
Next
For I = 1 To 8
Printhex Ar(i); 'print output
Next
Print 'linefeed
'You can also use multiple pins
'alias the pin first
Tsensor Alias P1.2
'the optional argument specifies the pin to use
1wreset Tsensor 'reset
1wwrite &H33 Tsensor 'write value to Tsensor
1wwrite Ar(1) , 2 Tsensor 'write 2 bytes to Tsensor
A = 1wread(tsensor) 'return byte from Tsensor
Ar(1) = 1wread(2 , P1.2) 'read 2 bytes from Tsensor
End