Read DS18S20


Closed Thread
Results 1 to 17 of 17

Thread: Read DS18S20

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Default

    Yes, my manual also says 12-bit. edited almost instantaneously! :-)

    I have got the P250a patch installed, can’t seem to find any newer?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    Yes, my manual also says 12-bit. edited almost instantaneously! :-)

    I have got the P250a patch installed, can’t seem to find any newer?
    There's a b patch out now.

    Show the code...

  3. #3
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Smile

    I will try to find and run the patch to find out if that’s the culprit.

    Thanks ski

  4. #4
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Cool

    Patch in place..... No, that did not cancel the compile error!
    Here’s the code:

    Code:
    READTEMP:
    
    OWOUT PORTA.5,1,[$CC, $44]                       ' SEND Start Temperature Conversion command
    
     
        OWOUT PORTA.5,1,[$CC, $BE]                   ' SEND Read Temperature command
    
     
        OWIN PORTA.5,0,[STR dq\9]                    ' Retrieve all 9 bytes of data
    
        RawTemp.Byte0 = dq[0]
    
        RawTemp.byte1 = dq[1]
    
        IF RawTemp.8 = 1 then                       ' Check IF temperature is a negative reading
    
     
    
            SignC = Negative
    
            RawTemp.lowbyte = RawTemp.lowbyte ^ 255               ' Invert data
    
            ELSE
    
            SignC = Positive
    
                     ENDIF
    
     
    
        dummy = RawTemp.0                                 ' Store the half degree indicator bit
    
     
    
        TempC = ((RawTemp.lowbyte) >> 1) * 100          ' Divide raw data by 2 to give real temperature
    
     
    
        TempC = TempC + (dummy * 50)                    ' Add the half degree is present
    
     
    
        IF SignC = Negative then                       ' Only proceed IF temperature is negative
    
     
    
            IF TempC => 1770 then   
    
                SignF = Negative
    
                TempF = (TempC + 5000) * 900
    
                TempF = div32 500
    
                TempF = TempF - 12200
    
                RETURN
    
     
    
                ELSE
    
                SignF = Positive
    
                TempF = (TempC + 5000) * 900
    
                TempF = div32 500
    
                TempF = 12200 - TempF
    
                RETURN
    
     
    
            ENDIF    
    
        ENDIF
    
        SignF = Positive
    
        TempF = TempC * 18 / 10 + 3200
    
        RETURN
    Thanks!

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


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Is not that much simpler than yout modifyer and the two following lines :

    Code:
    OWIN PORTA.5,0,[STR dq\9]                    ' Retrieve all 9 bytes of data
    
        RawTemp.Byte0 = dq[0]
    
        RawTemp.byte1 = dq[1]


    ( taken from a Malc C example )

    Code:
       OWIN    Porta.5, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]      ' Read two bytes / end comms
    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Unhappy

    Hi Alain,

    Your suggestion tested, does not compile due to multiple errors in the line.

    Made a search in the forum but could not find anything regarding the STR macro problem.

    Thanks.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I know that's not ALL of the code...

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


    Did you find this post helpful? Yes | No

    Thumbs down

    does not compile due to multiple errors in the line.

    Made a search in the forum but could not find anything regarding the STR macro problem.
    I can't believe it ...

    I can't ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  9. #9
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by skimask View Post
    I know that's not ALL of the code...
    You are correct; it’s not all the code. The rest of the code is working fine this is only going to be the part (subroutine) to measure temperature. And it’s also the part that does not compile.

    Thanks!

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Looks like you have dq defined as a WORD VS BYTE.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    You are correct; it’s not all the code. The rest of the code is working fine this is only going to be the part (subroutine) to measure temperature. And it’s also the part that does not compile.

    Thanks!
    The rest of the code may very well be working fine, but the rest of the code also has any setup/initialization/interrupts that you are using, therefore, is just as important as the code that's messing up.
    I must be making this up as I go or something...

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  3. Replies: 13
    Last Post: - 12th May 2009, 17:26
  4. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  5. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25

Members who have read this thread : 0

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