1WIRECOUNT/de
m (1 revision) |
(→Siehe auch) |
||
(4 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | + | = <span class="f_Header">Funktion</span><br/> = | |
− | + | Dieser Befehl ermittelt die Anzahl von 1wire-Slaves am Bus. | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
Line 17: | Line 17: | ||
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Beschreibung</span><br/> = |
<div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 4px"> | <div style="text-align: left; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 4px"> | ||
{| style="border: solid 2px #000000; border-spacing:0px; border-collapse: collapse" border="1" cellpadding="1" cellspacing="0" width="604" | {| style="border: solid 2px #000000; border-spacing:0px; border-collapse: collapse" border="1" cellpadding="1" cellspacing="0" width="604" | ||
Line 25: | Line 25: | ||
| style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | | style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | ||
− | + | Eine WORD-Variable, die die Anzahl Geräte am Bus anzeigt. | |
|- style="text-align:left; vertical-align:top" | |- style="text-align:left; vertical-align:top" | ||
Line 32: | Line 32: | ||
| style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | | style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | ||
− | + | Der Name des PORT PINx Registers wie z.B. PINB oder PIND. | |
|- style="text-align:left; vertical-align:top" | |- style="text-align:left; vertical-align:top" | ||
Line 39: | Line 39: | ||
| style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | | style="width:100%; border: solid 1px #000000" valign="top" width="100%" | | ||
− | + | Die Pin-Nummer im Bereich von 0-7. Darf eine numerische Konstante oder Variable sein. | |
|} | |} | ||
Line 45: | Line 45: | ||
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | + | Die Variable muß vom Typ Word oder Integer sein. | |
− | + | Die 1wirecount()-Funktion kann benutzt werden, um zu ermitteln, wie oft die 1wsearchNext()-Funktion aufgerufen werden muß, um alle IDs vom Bus zu bekommen. | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | + | Die 1wirecount-Function benötigt 4 Bytes vom SRAM. | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | ___1w_bitstorage , Byte | + | ___1w_bitstorage , Byte zur Speicherung von Bits : |
− | lastdeviceflag | + | lastdeviceflag Bit 0 |
− | id_bit | + | id_bit Bit 1 |
− | cmp_id_bit | + | cmp_id_bit Bit 2 |
− | search_dir | + | search_dir Bit 3 |
___1wid_bit_number, Byte | ___1wid_bit_number, Byte | ||
Line 81: | Line 81: | ||
= <span class="f_Header">ASM</span><br/> = | = <span class="f_Header">ASM</span><br/> = | ||
− | + | Folgende Assembler-Routinen werden von der mcs.lib aufgerufen. | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | _1wire_Count : ( | + | _1wire_Count : (ruft auf _1WIRE, _1WIRE_SEARCH_FIRST , _1WIRE_SEARCH_NEXT) |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | + | Übergebene Parameter : R24 : Pin-Nummer, R30 : Port , Y+0,Y+1 : 2 Bytes vom Software-Stack, X : Zeiger auf den Frame Space | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | + | Rückgabe von Y+0 und Y+1 mit dem Zählerwert. Wird auf die Zielvariable kopiert. | |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
Line 99: | Line 99: | ||
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Siehe auch</span><br/> = |
− | [[1WWRITE]] , [[1WRESET]] , [[1WREAD|1WREAD ]], [[1WSEARCHFIRST]], [[1WSEARCHNEXT]] , [[Using the 1 WIRE protocol|Using the 1wire protocol]] | + | [[CONFIG 1WIRE]] , [[1WWRITE]] , [[1WRESET]] , [[1WREAD|1WREAD ]] , [[1WSEARCHFIRST]] , [[1WSEARCHNEXT]] , [[1WVERIFY]] , [[Using the 1 WIRE protocol|Using the 1wire protocol]] |
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
Line 109: | Line 109: | ||
<span style="font-family: 'Arial'; color: #000000"> </span> | <span style="font-family: 'Arial'; color: #000000"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Beispiel</span><br/> = |
<source lang="bascomavr"> | <source lang="bascomavr"> | ||
Line 126: | Line 126: | ||
− | $hwstack = 32 ' | + | $hwstack = 32 'Grundeinstellung 32 für den Hardware Stack |
− | $swstack = 10 ' | + | $swstack = 10 'Grundeinstellung 10 für den Software Stack |
− | $framesize = 40 ' | + | $framesize = 40 'Grundeinstellung 40 für den Frame Space |
− | Config 1wire = Portb.0 ' | + | Config 1wire = Portb.0 'Angabe des Pins |
− | ' | + | 'Am STK200 muß Jumper B.0 gesteckt sein |
− | + | 'Folgende Bytes werden von der Scan-Routine benötigt | |
− | ' | + | '___1w_bitstorage , Byte zur Speicherung von Bits : |
− | '___1w_bitstorage , Byte | + | ' lastdeviceflag Bit 0 |
− | ' lastdeviceflag | + | ' id_bit Bit 1 |
− | ' id_bit | + | ' cmp_id_bit Bit 2 |
− | ' cmp_id_bit | + | ' search_dir Bit 3 |
− | ' search_dir | + | |
'___1wid_bit_number, Byte | '___1wid_bit_number, Byte | ||
'___1wlast_zero, Byte | '___1wlast_zero, Byte | ||
'___1wlast_discrepancy , Byte | '___1wlast_discrepancy , Byte | ||
− | '___1wire_data , | + | '___1wire_data , String * 7 (8 Bytes) |
− | '[DIM | + | '[DIM benutzte Variablen] |
− | ' | + | 'Mindestens 8 Bytes zur Speicherung der ID werden gebraucht |
Dim Reg_no(8) As Byte | Dim Reg_no(8) As Byte | ||
− | ' | + | 'ein Schleifenzähler und ein Word/Integer für die Anzahl der IDs am Bus |
Dim I As Byte , W As Word | Dim I As Byte , W As Word | ||
− | ' | + | 'Suchen des ersten Teilnehmers am Bus |
Reg_no(1) = 1wsearchfirst() | Reg_no(1) = 1wsearchfirst() | ||
− | For I = 1 To 8 ' | + | For I = 1 To 8 'Ausgabe der ID im Hex-Format |
Print Hex(reg_no(i)); | Print Hex(reg_no(i)); | ||
Next | Next | ||
Line 166: | Line 165: | ||
Do | Do | ||
− | ' | + | 'Suche nach anderen Teilmnehmern |
Reg_no(1) = 1wsearchnext() | Reg_no(1) = 1wsearchnext() | ||
For I = 1 To 8 | For I = 1 To 8 | ||
Line 172: | Line 171: | ||
Next | Next | ||
Print | Print | ||
− | Loop Until Err = 1 | + | Loop Until Err = 1 'Schleife bis zum ersten Fehler am Bus |
− | ' | + | 'Wenn ERR = 1 ist, wurde kein weiterer Teilnehmer gefunden |
− | ' | + | 'Man kann auch die Anzahl der Teilnehmer am Bus zählen lassen |
W = 1wirecount() | W = 1wirecount() | ||
− | ' | + | 'Es ist WICHTIG zu beachten, daß die 1wirecount-Function ein Word/Integer zurückgibt |
− | ' | + | 'Die Ergebnis-Variable muß vom Typ Word oder Integer sein |
− | ' | + | 'Man kann sie natürlich in eine Byte-oder Long-Variable übertragen |
Print W | Print W | ||
− | ' | + | 'als Bonus die nächste Routine : |
− | ' | + | ' zuerst das Array mit einer existierenden ID füllen |
Reg_no(1) = 1wsearchfirst() | Reg_no(1) = 1wsearchfirst() | ||
− | ' | + | ' um ein Byte zu ändern und das Err-Flag zu testen, nächste Zeile auskommentieren |
'Reg_no(1) = 2 | 'Reg_no(1) = 2 | ||
− | ' | + | 'jetzt eine Prüfung, ob die ID existiert |
1wverify Reg_no(1) | 1wverify Reg_no(1) | ||
Print Err | Print Err | ||
− | 'err =1 | + | 'err =1 wenn die ID, welche mit Reg_no() übergeben wurde, nicht existiert |
− | ' | + | 'optionaler Aufruf mit Angabe der Pinnummer: 1wverify reg_no(1),pinb,1 |
− | + | ||
− | ' | + | |
− | 'W = 1wirecount(pinb , 1) ' | + | 'wie bei den anderen 1-Wire Befehlen/Funktionen, wird die Angabe von Port und Pinnummer unterstützt |
+ | 'W = 1wirecount(pinb , 1) 'als Beispiel am Pin PINB.1 | ||
End | End | ||
</source><br/>{{Languages}} | </source><br/>{{Languages}} | ||
[[Category:BASCOM_Language_Reference/de]] | [[Category:BASCOM_Language_Reference/de]] |
Latest revision as of 19:30, 1 March 2013
Contents |
Funktion
Dieser Befehl ermittelt die Anzahl von 1wire-Slaves am Bus.
Syntax
var2 = 1WIRECOUNT()
var2 = 1WIRECOUNT( port , pin)
Beschreibung
var2 |
Eine WORD-Variable, die die Anzahl Geräte am Bus anzeigt. |
port |
Der Name des PORT PINx Registers wie z.B. PINB oder PIND. |
pin |
Die Pin-Nummer im Bereich von 0-7. Darf eine numerische Konstante oder Variable sein. |
Die Variable muß vom Typ Word oder Integer sein.
Die 1wirecount()-Funktion kann benutzt werden, um zu ermitteln, wie oft die 1wsearchNext()-Funktion aufgerufen werden muß, um alle IDs vom Bus zu bekommen.
Die 1wirecount-Function benötigt 4 Bytes vom SRAM.
___1w_bitstorage , Byte zur Speicherung von Bits :
lastdeviceflag Bit 0
id_bit Bit 1
cmp_id_bit Bit 2
search_dir Bit 3
___1wid_bit_number, Byte
___1wlast_zero, Byte
___1wlast_discrepancy , Byte
ASM
Folgende Assembler-Routinen werden von der mcs.lib aufgerufen.
_1wire_Count : (ruft auf _1WIRE, _1WIRE_SEARCH_FIRST , _1WIRE_SEARCH_NEXT)
Übergebene Parameter : R24 : Pin-Nummer, R30 : Port , Y+0,Y+1 : 2 Bytes vom Software-Stack, X : Zeiger auf den Frame Space
Rückgabe von Y+0 und Y+1 mit dem Zählerwert. Wird auf die Zielvariable kopiert.
Siehe auch
CONFIG 1WIRE , 1WWRITE , 1WRESET , 1WREAD , 1WSEARCHFIRST , 1WSEARCHNEXT , 1WVERIFY , Using the 1wire protocol
Beispiel
'-------------------------------------------------------------------------------- 'name : 1wireSearch.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : demonstrates 1wsearch 'micro : Mega48 'suited for demo : yes 'commercial addon needed : no '-------------------------------------------------------------------------------- $regfile = "m48def.dat" $crystal = 4000000 $hwstack = 32 'Grundeinstellung 32 für den Hardware Stack $swstack = 10 'Grundeinstellung 10 für den Software Stack $framesize = 40 'Grundeinstellung 40 für den Frame Space Config 1wire = Portb.0 'Angabe des Pins 'Am STK200 muß Jumper B.0 gesteckt sein 'Folgende Bytes werden von der Scan-Routine benötigt '___1w_bitstorage , Byte zur Speicherung von Bits : ' lastdeviceflag Bit 0 ' id_bit Bit 1 ' cmp_id_bit Bit 2 ' search_dir Bit 3 '___1wid_bit_number, Byte '___1wlast_zero, Byte '___1wlast_discrepancy , Byte '___1wire_data , String * 7 (8 Bytes) '[DIM benutzte Variablen] 'Mindestens 8 Bytes zur Speicherung der ID werden gebraucht Dim Reg_no(8) As Byte 'ein Schleifenzähler und ein Word/Integer für die Anzahl der IDs am Bus Dim I As Byte , W As Word 'Suchen des ersten Teilnehmers am Bus Reg_no(1) = 1wsearchfirst() For I = 1 To 8 'Ausgabe der ID im Hex-Format Print Hex(reg_no(i)); Next Print Do 'Suche nach anderen Teilmnehmern Reg_no(1) = 1wsearchnext() For I = 1 To 8 Print Hex(reg_no(i)); Next Print Loop Until Err = 1 'Schleife bis zum ersten Fehler am Bus 'Wenn ERR = 1 ist, wurde kein weiterer Teilnehmer gefunden 'Man kann auch die Anzahl der Teilnehmer am Bus zählen lassen W = 1wirecount() 'Es ist WICHTIG zu beachten, daß die 1wirecount-Function ein Word/Integer zurückgibt 'Die Ergebnis-Variable muß vom Typ Word oder Integer sein 'Man kann sie natürlich in eine Byte-oder Long-Variable übertragen Print W 'als Bonus die nächste Routine : ' zuerst das Array mit einer existierenden ID füllen Reg_no(1) = 1wsearchfirst() ' um ein Byte zu ändern und das Err-Flag zu testen, nächste Zeile auskommentieren 'Reg_no(1) = 2 'jetzt eine Prüfung, ob die ID existiert 1wverify Reg_no(1) Print Err 'err =1 wenn die ID, welche mit Reg_no() übergeben wurde, nicht existiert 'optionaler Aufruf mit Angabe der Pinnummer: 1wverify reg_no(1),pinb,1 'wie bei den anderen 1-Wire Befehlen/Funktionen, wird die Angabe von Port und Pinnummer unterstützt 'W = 1wirecount(pinb , 1) 'als Beispiel am Pin PINB.1 End
Languages | English • Deutsch |
---|