Witam wszystkich forumowiczow. Mam problem z termometrem dwu punktowym na DS1820. Problem polega na tym ze jesli temp jest dodatnia to wszystko jest ok ale problem mam z ujemnymi. Rozdzielczosc jest do 0.1 stopnia. Jezeli temperatura spadnie ponizej zera to jej wartosc wynosi 0.1 czyli -1 stopien. Wydzielilem z 0.1 jedynke i jest Ok ale jezeli temp wynosi +0.1 to wyskakuje mi -1 stopien:(. Jak sie z tym uporac? Ponizej program.
$regfile = "m16def.dat"
$crystal = 8000000
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pb.4 , Db5 = Pb.5 , Db6 = Pb.6 , Db7 = Pb.7 , E = Pb.3 , Rs = Pb.2
Config 1wire = Portb.0
Dim Iodczyt(9) As Byte
Dim It1 As Single
Dim It2 As Single
Dim It3 As Single
Dim Igotowa As String * 4
Dim Itemp As Integer
Dim Itemperatura As Single
Dim Odczyt(9) As Byte
Dim T1 As Single
Dim T2 As Single
Dim T3 As Single
Dim Gotowa As String * 4
Dim Temp As Integer
Dim Temperatura As Single
Dim Ujemna As Byte
Dim Cyfra As String * 1
Dim Ujemna1 As Byte
Dim Cyfra1 As String * 2
Dim Dsid1(8) As Byte
Dim Dsid2(8) As Byte
Dsid1(1) = 1wsearchfirst()
Dsid1(1) = 1wsearchnext()
Do
Cls
1wreset
1wwrite &H44
1wverify Dsid1(1) 'wysyłamy adres pierwszego czujnika
1wwrite &HBE
Waitms 750
Iodczyt(1) = 1wread(9)
1wreset
1wwrite &H44
1wverify Dsid2(1) 'wysyłamy adres drugiego czujnika
1wwrite &HBE
Waitms 750
Odczyt(1) = 1wread(9)
1wreset
1wwrite &HCC
1wwrite &H44
'---------------------------------
It3 = It2
Itemp = Makeint(iodczyt(1) , Iodczyt(2))
Itemperatura = Itemp / 2
It1 = Iodczyt(8) - Iodczyt(7)
It1 = It1 / Iodczyt(8)
Itemperatura = Itemperatura - 0.25
It2 = Itemperatura + It1
Igotowa = Fusing(it2 , "##.#")
Cyfra1 = Mid(igotowa , 1 , 2)
Ujemna1 = Val(cyfra1)
If Ujemna1 < 10 Then
Cyfra = Mid(igotowa , 3 , 1)
Ujemna = Val(cyfra)
End If
T3 = T2
Temp = Makeint(odczyt(1) , Odczyt(2))
Temperatura = Temp / 2
T1 = Odczyt(8) - Odczyt(7)
T1 = T1 / Odczyt(8)
Temperatura = Temperatura - 0.25
T2 = Temperatura + T1
Gotowa = Fusing(t2 , "###.#")
Lcd Igotowa
Lowerline
Lcd Gotowa
If Ujemna1 = 0 Then
Cls
Locate 1 , 1
Lcd "Zew. -" ; Ujemna
Locate 2 , 1
Lcd "Dom" ; Gotowa
End If
Wait 1
Loop
End