Action
This statement returns the number of 1wire devices found on the bus.
Syntax
var2 = 1WIRECOUNT(array )
Remarks
var2 |
A word variable that is assigned with the number if found 1wire devices on the bus. |
Array |
A variable or array that should be at least 8 bytes long. It is used to store the 1wire ID’s while counting. |
The 1wireCount function uses the 1wSearchFirst() and 1wSearchNexy functions internally.
See also
1WIRE , 1WSEARCHFIRST, 1WSEARCHNEXT
Example
'---------------------------------------------------------------------------
' 1wirecount.bas
' (c)1995-2006 MCS Electronics
' demonstration of using multiple devices
'--------------------------------------------------------------------------
'chip we use
$regfile = "89s8252.dat"
'crystal attached
$crystal = 12000000
'baud rate
$baud = 4800
'wait for 500 mili secs
Waitms 500
'the pins we use
'connect a 4K7 resistor from the data pin to VCC
Config 1wire = P1.0
'we need an array of 8 bytes to hold the result
Dim Ar(8) As Byte
'we also need a counter variable and a word variable
Dim I As Byte , W As Word
'some ids of 1wire chips I tested
' 01 51 B5 8D 01 00 00 56
' 01 84 B3 8D 01 00 00 E5
Print "start"
'get the number of connected 1wire device
W = 1wirecount(ar(1))
'print if there was an error and how many sensors are available
Print "ERR " ; Err ; " count " ; W
'now get the data from the first 1wire device on the bus
Ar(1) = 1wsearchfirst()
'print the ID
For I = 1 To 8
Printhex Ar(i);
Next
'I assume that there are more than 1 1wire devices
Do
'get the next device
Ar(1) = 1wsearchnext()
For I = 1 To 8
Printhex Ar(i);
Next
Loop Until Err = 1
'when ERR is 1 it means there are no more devices
' IMPORTANT : 1wsearchfirst and next functions do require that you use the SAME array
'In this example this is ar(1)
'once you know the ID, you can address a specific device
End