' $regfile = "4433def.dat" '$crystal = 4000000 'Definition der Konstanten Const Read_rom = &H33 ' DS1820 Commands Const Skip_rom = &HCC Const Convertt = &H44 Const Read_ram = &HBE Const Write_ram = &H4E Const Copy_ram = &H48 Const Recall_ee = &HB8 Const Read_power = &HB4 Config 1wire = Portd.2 'use this pin Dim Ar(9) As Byte , A As Byte , I As Byte , Temperatur As Integer Dim Halb As Byte Dim Vorzeichen As Byte Dim Busy As Byte Cls Do Wait 1 Disable Interrupts 1wreset ' 1wire Reset 1wwrite Skip_rom ' Read ROM command 1wwrite Convertt ' Measure Temperature Do Busy = 1wread() Loop Until Busy = &HFF ' Wait for end of conversion 1wreset ' 1wire Reset 1wwrite Skip_rom ' Skip ROM command 1wwrite Read_ram ' Read Scratch command Ar(1) = 1wread() Ar(2) = 1wread() 1wreset ' 1wire Reset Print Ar(1) Enable Interrupts Print "Test" Print Ar(1) 'Temperaturwert Print Ar(2) ; 'positiv oder negativ 0 = positiv 1 = negativ Vorzeichen = Ar(2) And 1 ' positiv oder negativ 0 = positiv 1 = negativ If Vorzeichen = 1 Then 'bei negativen Werten müssen alle Bits invertiert werden und 1 dazu addiert werden Toggle Ar(1) 'alle Bits invertieren Ar(1) = Ar(1) + 1 'plus 1 Temperatur = Ar(1) / 2 Else Temperatur = Ar(1) / 2 End If If Vorzeichen = 1 Then Lcd " - " ; Temperatur ; "."; Else Lcd "+ " ; Temperatur ; "."; End If Halb = Ar(1) And 1 ' 0 , 5 Grad If Halb = 1 Then Lcd "5" Else Lcd "0" Lcd " C" Loop End