DS18B20 Question


Results 1 to 7 of 7

Threaded View

  1. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 Question

    Quote Originally Posted by ozarkshermit View Post
    I notice that when the temperature "changes direction", in other words, when it first starts to increase or decrease, the first reading of the DS18B20 does not change. After that it works fine, updates each time a new read takes place.


    Ken
    1) what the hell do you mean by that ???

    2) reading your datasheet may show you the conversion need some time to be read ... depending on the resolution you use.

    3) This one ( by bruce ... ) is correct, but for DS1820 - the old model without "B" or "S" - see Datasheet for end of conversion condition
    Code:
    temperature VAR WORD ' Temperature storage
    count_remain VAR BYTE ' Count remaining
    count_per_c VAR BYTE ' Count per degree C
    
    DQ VAR PORTC.0 ' One-wire data pin
    
    
    ' Define LCD registers and bits
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 1
    
    
    ADCON1 = 7 ' Set PORTA and PORTE to digital
    Low PORTE.2 ' LCD R/W line low (W)
    
    
    mainloop: OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
    
    waitloop: OWIn DQ, 4, [count_remain] ' Check for still busy converting
    IF count_remain = 0 Then waitloop
    
    OWOut DQ, 1, [$CC, $BE] ' Read the temperature
    OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
    
    ' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
    temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"
    
    ' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
    temperature = (temperature */ 461) + 3200
    LCDOut $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"
    
    Pause 1000 ' Display about once a second
    
    GoTo mainloop ' Do it forever
    Alain
    Last edited by Acetronics2; - 19th December 2014 at 18:24.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. ds18b20 code
    By leemarrow in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd March 2016, 16:14
  2. Quick DS18B20 question
    By gti_uk in forum General
    Replies: 4
    Last Post: - 21st June 2009, 18:24
  3. Ds18b20
    By ahmed_salah in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 14th June 2009, 16:21
  4. Ds18b20..
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th June 2008, 17:29
  5. using the DS18B20
    By lerameur in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2006, 14:09

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts