logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Test czujników temperatury DS18B20

adass 03 Gru 2007 23:07 2321 5
REKLAMA
  • #1 4549123
    adass
    Poziom 25  
    Jak sprawdzić czujniki ds18b20 czy prawidłowo wskazują temperaturę bo słyszałem że są niektóre fabryczne ,,felerne,, .Umnie wszystkie 5 zawyżają o 2stC , a może jest błąd w kodzie. dziękuje

    $regfile = "M16def.dat"
    $crystal = 8000000



    '****** KONFIGURACJA PORTÓW *********

    Config Porta = Output 'wysw ABCDEFG
    Config Portc = Output 'zasilanie W4,W3, W2, W1, T4, T3, T2, T1
    Config Pind.7 = Output 'zasilanie z1
    Config Pind.6 = Output 'zasilanie z2
    Config Pind.5 = Output 'zasilanie z3
    Config Pind.4 = Output 'zasilanie z4
    Config Pind.3 = Output 'wysw przecinek
    Config Pind.2 = Output 'jasność
    Config Pinb.0 = Input 'przycisk godz
    Config Pinb.1 = Input 'przycisk min
    Config Pinb.2 = Input 'przycisk min-max

    Godz Alias Pinb.0
    Minuta Alias Pinb.1
    Maxi Alias Pinb.2



    Dim T1 As Single
    Dim T2 As Single
    Dim B1 As Byte , B2 As Byte , R As Byte
    Dim Tmp As String * 6
    Dim Znak As Byte
    R = &HFF
    Declare Sub 1wr
    Dim Bd(9) As Byte
    Dim T As Integer

    Dim T11 As Single
    Dim T21 As Single
    Dim C1 As Byte , C2 As Byte , R1 As Byte
    Dim Tmp1 As String * 6
    Dim Znak1 As String * 1
    R1 = &HFF
    Declare Sub 11wr
    Dim Cd(9) As Byte

    Dim Temp_zew As Word
    Dim Setki As Word
    Dim D As Word
    Dim J As Word
    Dim X As Word
    Dim Y As Word

    Dim Temp_wew As Word
    Dim Setki1 As Word
    Dim D1 As Word
    Dim J1 As Word
    Dim X1 As Word
    Dim Y1 As Word

    '******* KONFIGURACJA RTC *********
    Dim Godzina1 As Byte ' zminenne do rozbicia na cyfry
    Dim Godzina2 As Byte
    Dim Minuta1 As Integer
    Dim Minuta2 As Integer
    Dim Sekunda1 As Integer
    Dim Sekunda2 As Integer
    Config Sda = Portd.1 'definiujemy pin SDA
    Config Scl = Portd.0 'definiujemy pin SCL
    Dim M As Byte 'minuty
    Dim H As Byte 'godziny
    Dim S As Byte 'sekundy

    '********* ZMIENNE DO OBSŁUGI WYŚWIETLACZA ************
    Dim Tt1 As Byte 'segment1
    Dim Tt2 As Byte 'segment2
    Dim T3 As Byte 'segment3
    Dim T4 As Byte 'segment4
    Dim W1 As Byte 'segment5
    Dim W2 As Byte 'segment6
    Dim W3 As Byte 'segment7
    Dim W4 As Byte
    Dim Z1 As Byte
    Dim Z2 As Byte
    Dim Z3 As Byte
    Dim Z4 As Byte


    '******* INNE ZMIENNE *********************************
    Dim Licznik As Byte
    Dim Dwukropek As Byte
    Dim Licz_ust As Byte
    Dim Jasn_wl As Byte
    Dim Jasn_wl1 As Integer
    Dim Jasn_wl2 As Integer
    Dim Jasn_wyl As Integer
    Dim Jasn_wyl1 As Integer
    Dim Jasn_wyl2 As Integer

    Jasn_wl = 7
    Jasn_wyl = 22

    '******** PĘTLA GŁÓWNA *******************************
    Praca:
    Do



    Gosub Zegar

    H = Makedec(h)
    M = Makedec(m)
    S = Makedec(s)
    Godzina1 = H / 10
    Godzina2 = H Mod 10
    Minuta1 = M / 10
    Minuta2 = M Mod 10
    Sekunda1 = S / 10
    Sekunda2 = S Mod 10

    Incr Licznik

    If Licznik = 1 Then
    Gosub Temperatura
    End If

    If Licznik = 100 Then
    'Portd.2 = 0
    Gosub Temperatura1
    End If

    If Licznik = 120 Then
    Gosub Temperatura2
    End If

    If Licznik = 220 Then
    Gosub Temperatura3
    End If

    If Licznik = 240 Then
    Licznik = 0
    End If

    Temp_zew = T1 * 10
    Setki = Temp_zew / 100
    D = Temp_zew / 10
    X = Setki * 10
    D = D - X
    Y = X + D
    Y = Y * 10
    J = Temp_zew - Y

    Temp_wew = T11 * 10
    Setki1 = Temp_wew / 100
    D1 = Temp_wew / 10
    X1 = Setki1 * 10
    D1 = D1 - X1
    Y1 = X1 + D1
    Y1 = Y1 * 10
    J1 = Temp_wew - Y1

    Tt1 = Godzina1
    Tt2 = Godzina2
    T3 = Minuta1
    T4 = Minuta2
    W1 = 26
    W2 = Setki1
    W3 = D1
    W4 = J1
    Z1 = Znak
    Z2 = Setki
    Z3 = D
    Z4 = J

    Gosub Wyswietl

    Debounce Pinb.2 , 0 , Ustaw

    If Jasn_wl <= H Then
    Portd.2 = 0
    Else
    Portd.2 = 1
    End If

    If Jasn_wyl <= H Then
    Portd.2 = 1
    'Else
    'Portd.2 = 1
    End If

    Loop

    Temperatura:
    Config 1wire = Portb.3
    11wr 'podprogram 1wr
    1wwrite &HCC 'komenda skip ROM
    1wwrite &H44
    Return

    Temperatura1:
    11wr 'podprogram 1wr
    1wwrite &HCC 'komenda skip ROM
    1wwrite &HBE 'komenda read
    C1 = 1wread() 'odczyt z termometru
    C2 = 1wread()
    11wr 'podprogram 1wr
    If C2 >= 248 Then 'w przypadku temperatur ujemnych
    C1 = R1 - C1 'Od 255 Odejmujemy B1
    C2 = R1 - C2 'od 255 odejmujemy B2
    Znak1 = "-"
    Else
    Znak1 = "+"
    End If
    T11 = C1 / 16 'Przesuniecie w pawo o 4 bajty
    T21 = C2 * 16 'przesuniecie w lewo o 4 bajty
    T11 = T11 + T21

    Sub 11wr 'podprogram resetujacy magistrale
    1wreset
    End Sub 'pozyskujemy temperaturę
    Return

    Temperatura2:
    Config 1wire = Portb.4
    1wr 'podprogram 1wr
    1wwrite &HCC 'komenda skip ROM
    1wwrite &H44
    Return
    'komenda convert T
    Temperatura3:
    1wr 'podprogram 1wr
    1wwrite &HCC 'komenda skip ROM
    1wwrite &HBE 'komenda read
    B1 = 1wread() 'odczyt z termometru
    B2 = 1wread()
    1wr 'podprogram 1wr
    If B2 >= 248 Then 'w przypadku temperatur ujemnych
    B1 = R - B1 'Od 255 Odejmujemy B1
    B2 = R - B2 'od 255 odejmujemy B2
    Znak = 10
    Else
    Znak = 26
    End If
    T1 = B1 / 16 'Przesuniecie w pawo o 4 bajty
    T2 = B2 * 16 'przesuniecie w lewo o 4 bajty
    T1 = T1 + T2
    'Tmp = Fusing(t1 , "###.&")
    'Waitms 50
    Sub 1wr
    1wreset
    End Sub
    Return

    Zegar:

    I2cstart
    I2cwbyte 162
    I2cwbyte 2
    I2cstop
    I2cstart
    I2cwbyte 163
    I2crbyte S , Ack 'pobieramy sekundy, minuty i godziny
    I2crbyte M , Ack
    I2crbyte H , Nack
    I2cstop
    Return

    Wyswietl:
    Incr Dwukropek
    If Dwukropek = 80 Then
    Dwukropek = 0
    End If

    Waitms 1
    Portc = &B01111111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    'Portd.3 = 1
    Porta = Lookup(tt1 , Tabela)

    Waitms 1
    Portc = &B10111111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    If Dwukropek < 40 Then
    Portd.3 = 0
    Else
    Portd.3 = 1
    End If
    Porta = Lookup(tt2 , Tabela)

    Waitms 1
    Portc = &B11011111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Porta = Lookup(t3 , Tabela)

    Waitms 1
    Portc = &B11101111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    'Portd.3 = 0
    If Dwukropek < 40 Then
    Portd.3 = 0
    Else
    Portd.3 = 1
    End If
    Porta = Lookup(t4 , Tabela)

    Waitms 1
    Portc = &B11110111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Porta = Lookup(w1 , Tabela)

    Waitms 1
    Portc = &B11111011
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Porta = Lookup(w2 , Tabela)

    Waitms 1
    Portc = &B11111101
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 0
    Porta = Lookup(w3 , Tabela)

    Waitms 1
    Portc = &B11111110
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Porta = Lookup(w4 , Tabela)

    Waitms 1
    Portc = &B11111111
    Portd.7 = 0
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Porta = Lookup(z1 , Tabela)

    Waitms 1
    Portc = &B11111111
    Portd.7 = 1
    Portd.6 = 0
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Porta = Lookup(z2 , Tabela)

    Waitms 1
    Portc = &B11111111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 0
    Portd.4 = 1
    Portd.3 = 0
    Porta = Lookup(z3 , Tabela)

    Waitms 1
    Portc = &B11111111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 0
    Portd.3 = 1
    Porta = Lookup(z4 , Tabela)

    Waitms 1
    Portc = &B11111111
    Portd.7 = 1
    Portd.6 = 1
    Portd.5 = 1
    Portd.4 = 1
    Portd.3 = 1
    Return

    Ustaw:
    Do

    Gosub Zegar
    H = Makedec(h)
    M = Makedec(m)
    S = Makedec(s)

    If Godz = 0 Then
    Incr Licz_ust
    If Godz = 0 And Licz_ust = 10 Then
    Incr H
    Licz_ust = 0
    If H >= 24 Then
    H = 0
    End If
    End If
    End If


    If Minuta = 0 Then
    Incr Licz_ust
    If Minuta = 0 And Licz_ust = 10 Then
    Incr M
    Licz_ust = 0
    If M >= 60 Then
    M = 0
    End If
    End If
    End If

    Godzina1 = H / 10
    Godzina2 = H Mod 10
    Minuta1 = M / 10
    Minuta2 = M Mod 10
    Sekunda1 = S / 10
    Sekunda2 = S Mod 10

    Tt1 = Godzina1
    Tt2 = Godzina2
    T3 = Minuta1
    T4 = Minuta2
    W1 = 27
    W2 = 20
    W3 = 14
    W4 = 26
    Z1 = 11
    Z2 = 2
    Z3 = 22
    Z4 = 20

    Gosub Wyswietl

    H = Makebcd(h)
    I2cstart
    I2cwbyte 162
    I2cwbyte 4
    I2cwbyte H
    M = Makebcd(m)
    I2cstart
    I2cwbyte 162
    I2cwbyte 3
    I2cwbyte M

    Debounce Pinb.2 , 0 , Jasno_wlacz

    Loop

    Jasno_wlacz:
    Do

    If Godz = 0 Then
    Incr Licz_ust
    If Godz = 0 And Licz_ust = 10 Then
    Incr Jasn_wl
    Licz_ust = 0
    If Jasn_wl >= 24 Then
    Jasn_wl = 0
    End If
    End If
    End If

    Jasn_wl1 = Jasn_wl / 10
    Jasn_wl2 = Jasn_wl Mod 10

    Tt1 = Jasn_wl1
    Tt2 = Jasn_wl2
    T3 = 10
    T4 = 10
    W1 = 30
    W2 = 22
    W3 = 20
    W4 = 21
    Z1 = 26
    Z2 = 26
    Z3 = 31
    Z4 = 21

    Gosub Wyswietl

    Debounce Pinb.2 , 0 , Jasno_wylacz

    Loop

    Jasno_wylacz:
    Do

    If Godz = 0 Then
    Incr Licz_ust
    If Godz = 0 And Licz_ust = 10 Then
    Incr Jasn_wyl
    Licz_ust = 0
    If Jasn_wyl >= 24 Then
    Jasn_wyl = 0
    End If
    End If
    End If

    Jasn_wyl1 = Jasn_wyl / 10
    Jasn_wyl2 = Jasn_wyl Mod 10

    Tt1 = Jasn_wyl1
    Tt2 = Jasn_wyl2
    T3 = 10
    T4 = 10
    W1 = 30
    W2 = 22
    W3 = 20
    W4 = 21
    Z1 = 26
    Z2 = 0
    Z3 = 12
    Z4 = 12

    Gosub Wyswietl

    Debounce Pinb.2 , 0 , Praca

    Loop

    End


    Tabela:
    Data &B01000000 '0
    Data &B01111001 '1
    Data &B0100100 '2
    Data &B00110000 '3
    Data &B00011001 '4
    Data &B00010010 '5
    Data &B00000010 '6
    Data &B01111000 '7
    Data &B00000000 '8
    Data &B00010000 '9
    Data &B10111111 ' 10 - kreska
    Data &B11000110 '11 - C
    Data &B10001110 ' 12 - F
    Data &B11000010 ' 13 - G
    Data &B10000111 ' 14 - t
    Data &B10101111 ' 15 - r
    Data &B10010001 ' 16 - y
    Data &B10000011 ' 17 - b
    Data &B10001011 ' 18 - H
    Data &B11111001 ' 19 - I
    Data &B10010010 ' 20 - S
    Data &B10101011 ' 21 - n
    Data &B10001000 ' 22 - A
    Data &B10100001 ' 23 - d
    Data &B10001100 ' 24 - P
    Data &B10000110 ' 25 - E
    Data &B11111111 ' 26 - NIC
    Data &B11000001 ' 27 - u
    Data &B11110111 ' 28 - kreska dół
    Data &B11111110 ' 29 - kreska góra
    Data &B11100001 ' 30 - j
    Data &B10100011 ' 31 - o
  • REKLAMA
  • #2 4549591
    rmajda
    Poziom 20  
    To chyba nie ten dział !!!
  • REKLAMA
  • #3 4549628
    hefid
    Spoczywaj w Pokoju
    Post był raportowany.
    Przeniosłem z: DIY Pozostałe i Newsy
  • REKLAMA
  • #4 4846116
    don diego
    Poziom 32  
    Po rozkazie konwersji temperatury musisz odczekać około 750ms.
  • REKLAMA
  • #5 4869653
    adass
    Poziom 25  
    Taka modyfikacja nie rozwiązuje problemu ( cykliczny zanik świecenia wyświetlaczy na około 1sek).
    Kod:
    Temperatura2:
    Config 1wire = Portb.4
    1wr 'podprogram 1wr
    1wwrite &HCC 'komenda skip ROM
    1wwrite &H44 'rozkaz konwersji temperatury
    wait 1 'odczekanie jednej sekundy
    Return
  • #6 4870329
    don diego
    Poziom 32  
    Odczekać, czyli dać spokój DS'owi. Przez ten czas możesz na przykład wyświetlać dane, które odebrałeś wcześniej.
REKLAMA