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

Jak poprawić odczyty SHT15 w Bascom51 bez zmiennych typu Single?

pablo666gliwice 15 Lis 2006 19:56 974 0
REKLAMA
  • #1 3228294
    pablo666gliwice
    Poziom 14  
    Posty: 115
    Pomógł: 6
    Ocena: 38
    Mam pytanie, opracowywal ktos kompletna procedure odczytu SHT? Skopiowalem ten kod z sampla do AVR , troszke poprawilem (na 89S52) i sie odczytuje..ale wyswietla wiekszosc czasu 18,9stopnia i 42,6 % wilgotnosci Troche malo prawdopodobne wyniki ale reaguje na chuchniecie (chyba tak sie to pisze) Wilgotnosc podskakuje do 82% pozniej gwaltownie spada do 35% i znowu stabilne do znudzenia 42,6%!! Moze cos jest nie tak w obliczeniach Jak uniknac stosowania zmiennych single i zrobic to tylko na wordach. Jak ktos ma jakies doswiadczenie w programowaniu tego czujnika prosze o pomoc
    
    Dim Ctr As Byte
    Dim Dataword As Word
    Dim Command As Byte
    Dim Dis As String * 20
    
    Dim Calc As Single
    Dim Calc2 As Single
    Dim Rhlinear As Single
    Dim Rhlintemp As Single
    Dim Tempc As Single
    Dim Tempf As Single
    
    Const C1 = -4
    Const C2 = 0.0405
    Const C3 = -0.0000028
    Const T1c = .01
    Const T2 = .00008
    Const T1f = .018
    
    Dim Datavalue As Word
    Dim Databyte As Byte
    ************w petli co sekunde
    
       Command = &B00000011
       Call Getit           'Get the temperature, puts result in "dataword" for us
          '
    '   Tempf = T1f * Dataword
    '   Tempf = Tempf - 40
    
       Tempc = T1c * Dataword       'get celcius for later calculations and for "the rest of the world"
       Tempc = Tempc - 40
    
       Dis = Fusing(tempc , ###.#)
       Lcd " T " ; Dis ; " " ; Chr(0) ; "C  "
    
       Command = &B00000101
       Call Getit           'get the humidity
    
       Calc = C2 * Dataword
       Calc2 = Dataword * Dataword       'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
       Calc2 = C3 * Calc2
       Calc = Calc + C1
       Rhlinear = Calc + Calc2
    
       'Dis = Fusing(rhlinear , "##.##")
       'Print "Humidity adjusted for linear = " ; Dis
    
    
       Calc = T2 * Dataword
       Calc = Calc + T1c
       Calc2 = Tempc - 25
       Calc = Calc2 * Calc
       Rhlintemp = Calc + Rhlinear
    
       Dis = Fusing(rhlintemp , ##.#)
       Lowerline
       Lcd "RH " ; Dis ; " %  "
    Sub Getit
    
    'start with "transmission start"
    Set Sck
    Reset Dataout
    Reset Sck
    Set Sck
    Set Dataout
    Reset Sck
    
    'now send the  command
    Shiftout Dataout , Sck , Command , 1
    
    '   Ddrb = &B11111101                    'datain is now input
    '   Config Pinb.1 = Input                'datain
       Set Sck              'click one more off
       Reset Sck
    '   Waitus 10            'no idea why, but it doesn't work without it!
    '   Delay
       $asm
        nop
        nop
       $end Asm
       Bitwait Dataout , Reset       'wait for the chip to have data ready
    
       Shiftin Dataout , Sck , Databyte , 1       'get the MSB
       Datavalue = Databyte
    
    '   Ddrb = &B11111111
    '   Config Pinb.1 = Output
    
       Reset Dataout        'this is the tricky part- Lot's of hair pulling- have to tick the ack!
       Set Sck
       Reset Sck
    
    '   Ddrb = &B11111101                    'datain is now input
    '   Config Pinb.1 = Input
    
       Shiftin Dataout , Sck , Databyte , 1       'get the LSB
       Shift Datavalue , Left , 8
       Datavalue = Datavalue Or Databyte
       'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
       Dataword = Datavalue
    
    '   Ddrb = &B11111111
    '   Config Pinb.1 = Output
    
       Reset Dataout
       Set Sck
       Reset Sck
    
    '   Ddrb = &B11111101                    'datain is now input
    '   Config Pinb.1 = Input
    
       Shiftin Dataout , Sck , Databyte , 1       'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
       'Print "CRC value was - " ; Databyte
    
    '   Ddrb = &B11111111
    '   Config Pinb.1 = Output
    
       Set Dataout
       Set Sck
       Reset Sck
    End Sub
    [tex]
    te linijki z apostrofem sa nieaktywne [/tex]
  • REKLAMA
REKLAMA