📄 1wirecount.bas
字号:
'------------------------------------------------------------------------------
' 1wirecount.bas
' (c) 2002 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
Print
'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
Print
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -