Code:
$regfile = "m32def.dat"
$crystal = 8000000 'Externes Quarz 14,7456 Mhz
'Achtung: damit der ext. Quarz aktiv wird => die Fusebits entsprechend einstellen.
'Extern Cristal , bei mir alle Bits = 111 111
$baud = 19200
Declare Sub Writevalues(byval Wert As String)
'Config Clock = Soft
Enable Interrupts
Config Date = Mdy , Separator = .
Dim Btemp1 As Byte
Const Trkfile = "track.log"
Print "Wait for Drive"
' Include here you driver for Compactflash/HardDisk or other
$include "Config_MMC.bas" ' Does drive init too
If Gbdriveerror = 0 Then
' Include AVR-DOS Configuration and library
$include "Config_AVR-DOS.BAS"
Print "Init File System ... ";
Btemp1 = Initfilesystem(1) ' Partition 1
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
Print "Error: " ; Btemp1 ; " at Init file system"
Else
Print " OK"
Print "Filesystem: " ; Gbfilesystem
Print "FAT Start Sector: " ; Glfatfirstsector
Print "Root Start Sector: " ; Glrootfirstsector
Print "Data First Sector: " ; Gldatafirstsector
Print "Max. Cluster Nummber: " ; Glmaxclusternumber
Print "Sectors per Cluster: " ; Gbsectorspercluster
Print "Root Entries: " ; Gwrootentries
Print "Sectors per FAT: " ; Glsectorsperfat
Print "Number of FATs: " ; Gbnumberoffats
End If
Else
Print "Error during Drive Init: " ; Gbdriveerror
End If
Match_rom Alias &H55
Skip_rom Alias &HCC
Read_scratchpad Alias &HBE
Write_scratchpad Alias &H4E
Copy_scratchpad Alias &H48
Start_conversion Alias &H44
' Pin für 1wire Schnittstelle festlegen. => DS1820 am Port C.5
Config 1wire = Portc.7
Dim Ds1820id(32) As Byte
Dim Sc(9) As Byte , Tmp As Byte '????
Dim T As Integer , T1 As Integer
Dim I As Byte
Dim Id As Byte
Dim Nr As Word
Dim Actline As String * 20
'Die Adresse aller meiner DS1820 die ich vorher ausgelesen habe:
' DATA Bereich auslesen (IDs fest eingestellt)
'Restore Sensor_ids
' For I = 1 To 32
' Read Ds1820id(i)
'Next I
'IDs dynamisch ermitteln ...
Nr = 0
Ds1820id(1) = 1wsearchfirst()
Print "ID : " ; Hex(ds1820id(1)) ; Hex(ds1820id(2)) ; Hex(ds1820id(3)) ; Hex(ds1820id(4)) ; _
Hex(ds1820id(5)) ; Hex(ds1820id(6)) ; Hex(ds1820id(7)) ; Hex(ds1820id(8))
Do
Nr = Nr + 8
' Nächsten DS1820 suchen
Ds1820id(1 + Nr) = 1wsearchnext()
' Wenn kein Fehler, dann ausgeben
If Err = 0 Then
Print "ID : " ; Hex(ds1820id(1 + Nr)) ; Hex(ds1820id(2 + Nr)) ; Hex(ds1820id(3 + Nr)) ; Hex(ds1820id(4 + Nr)) ; _
Hex(ds1820id(5 + Nr)) ; Hex(ds1820id(6 + Nr)) ; Hex(ds1820id(7 + Nr)) ; Hex(ds1820id(8 + Nr))
Wait 1
End If
Loop Until Err = 1
1wreset
1wwrite Skip_rom
1wwrite Start_conversion 'Alle angeschlossenen DS1820 zum Messen veranlassen
Waitms 500 'Ausgabe alle 0,5 Sekunden
Nr = Nr - 7 '+1 -8
Do
Actline = ""
'Print "$1;1;;" ;
Actline = Actline + "$1;1;;"
For Id = 1 To Nr Step 8 'ID für alle 4 DS1820 1,9,17,25
Incr I
1wreset '1Wire Reseten
1wwrite &H55 'MATCHROM=>Adress.den DS1820 anhand des ROM Inhaltes
1wwrite Ds1820id(id) , 8 '8 Byte ID wird uebertragen
1wwrite &HBE 'READ SCATCHPAD => Liest alle Bytes des SP Memorys
Sc(1) = 1wread(9)
'T = Makeint(sc(1) , Sc(2)) 'komprimiert zwei Bytes in die Integervariable T
'Shift T , Right 'Die Nachkommastelle entfernen
'Locate I , 11 'Temperatur in ganzen Grad ausgeben
' Anzeige erfolgt so: T1=23 C
Tmp = Sc(1) And 1 ' 0.1C precision
If Tmp = 1 Then Decr Sc(1)
T = Makeint(sc(1) , Sc(2))
T = T * 50 : T = T - 25 : T1 = Sc(8) - Sc(7) : T1 = T1 * 100
T1 = T1 / Sc(8) : T = T + T1 : T = T / 10
'Print T ; ";" ;
Actline = Actline + Str(t)
Actline = Actline + ";"
Next Id
'Print "0"
Actline = Actline + "0"
Print Actline ' für Zeilenvorschub
Writevalues Actline
I = 0
1wreset
1wwrite Skip_rom
1wwrite Start_conversion 'Alle angeschlossenen DS1820 zum Messen veranlassen
Waitms 500 'Ausgabe alle 0,5 Sekunden
Loop
Sub Writevalues(wert As String)
Open "Test.txt" For Append As #6
Print #6 , Wert
Flush #6
Close #6
End Sub
End
Sensor_ids:
Data &H10 , &H8E , &HB0 , &H65 , &H01 , &H08 , &H00 , &H81
Data &H10 , &H7A , &H66 , &H65 , &H01 , &H08 , &H00 , &HED
Data &H10 , &H7B , &HD6 , &H60 , &H01 , &H08 , &H00 , &H14
Data &H10 , &H13 , &HFD , &H5F , &H01 , &H08 , &H00 , &H2C
Der macht nix anderes, als max. 4 DS1820 1Wire Tempsensoren zu suchen und auszulesen. Und er soll das Ergebnis seriell ausgeben und auf die SD Karte beamen.
Lesezeichen