DS1820 again


Closed Thread
Results 1 to 4 of 4

Thread: DS1820 again

  1. #1
    Join Date
    Nov 2005
    Posts
    13

    Default DS1820 again

    Hi,

    I'm trying to use code I found here to get a reading from a DS1820 device. Whatever I try, this always gives me a 'not present' error. But the brand new 1820 is right there and connected to PORTC.0

    I'm using a PIC16F876A for this project.

    Code:
    DEFINE OSC 4
    
    ' Allocate variables
    command var     byte            ' Storage for command
    i       var     byte            ' Storage for loop counter
    temp    var     word            ' Storage for temperature
    DQ      var     PORTC.0         ' Alias DS1820 data pin
    DQ_DIR  var     TRISC.0         ' Alias DS1820 data direction pin
    
            Pause 500               ' Wait for LCD to start
    
            Lcdout $fe, 1, "Temp in degrees C"      ' Display sign-on message
    
    
    ' Mainloop to read the temperature and display on LCD
    mainloop:
            Gosub init1820          ' Init the DS1820
    
            command = $cc           ' Issue Skip ROM command
            Gosub write1820
    
            command = $44           ' Start temperature conversion
            Gosub write1820
    
            Pause 2000              ' Wait 2 seconds for conversion to complete
    
            Gosub init1820          ' Do another init
    
            command = $cc           ' Issue Skip ROM command
            Gosub write1820
    
            command = $be           ' Read the temperature
            Gosub write1820
            Gosub read1820
    
            ' Display the decimal temperature
            Lcdout $fe, 1, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
    
            Goto mainloop           ' Do it forever
    
    
    ' Initialize DS1820 and check for presence
    init1820:
            Low DQ                  ' Set the data pin low to init
            Pauseus 500             ' Wait > 480us
            DQ_DIR = 1              ' Release data pin (set to input for high)
    
            Pauseus 100             ' Wait > 60us
            If DQ = 1 Then
                    Lcdout $fe, 1, "DS1820 not present"
                    Pause 500
                    Goto mainloop   ' Try again
            Endif
            Pauseus 400             ' Wait for end of presence pulse
            Return
    
    
    ' Write "command" byte to the DS1820
    write1820:
            For i = 1 to 8          ' 8 bits to a byte
                    If command.0 = 0 Then
                            Gosub write0    ' Write a 0 bit
                    Else
                            Gosub write1    ' Write a 1 bit
                    Endif
                    command = command >> 1  ' Shift to next bit
            Next i
            Return
    
    ' Write a 0 bit to the DS1820
    write0:
            Low DQ
            Pauseus 60              ' Low for > 60us for 0
            DQ_DIR = 1              ' Release data pin (set to input for high)
            Return
    
    ' Write a 1 bit to the DS1820
    write1:
            Low DQ                  ' Low for < 15us for 1
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1              ' Release data pin (set to input for high)
            Pauseus 60              ' Use up rest of time slot
            Return
    
    
    ' Read temperature from the DS1820
    read1820:
            For i = 1 to 16         ' 16 bits to a word
                    temp = temp >> 1        ' Shift down bits
                    Gosub readbit   ' Get the bit to the top of temp
            Next i
            Return
    
    ' Read a bit from the DS1820
    readbit:
            temp.15 = 1             ' Preset read bit to 1
            Low DQ                  ' Start the time slot
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1              ' Release data pin (set to input for high)
            If DQ = 0 Then
                    temp.15 = 0     ' Set bit to 0
            Endif
            Pauseus 60              ' Wait out rest of time slot
            Return
    
            End
    What am i doing wrong here? The LCD works OK, it's just the reading from the 1820 that won't work, i don't understand why, because it's so simple to connect.

    Thanks in advance,
    Steve

  2. #2
    Join Date
    Nov 2005
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Don't bother everyone, I didn't notice the line saying (BOTTOM VIEW) at the base of the IC lay-out, thus GND and VDD where connected the wrong way. Thank god it still lives and functions now.

    Steve

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Don't feel bad I did the exact same thing a week ago. However I wasn't so lucky I need to purchase a new sensor.

  4. #4
    Join Date
    Nov 2005
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Bummer...

    It's always these rather stupid mistakes you have to watch out for. I do recall i did exactly the same thing some time ago with a LM35 sensor, so it aint the first time this happened to me

    One of these days i'm gonna manage to wriggle a brandnew athlon64 into it's socket the wrong way around and see it go up in flames a little later, it's bound to happen one of these days

    Steve

Similar Threads

  1. Please help with 1-wire DS1820
    By hatuan291 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th March 2010, 13:51
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. DS1820 display with 7-seg 4 digits
    By chai98a in forum Code Examples
    Replies: 12
    Last Post: - 10th April 2008, 13:12
  4. DS1820 and 18f2550
    By rjones2102 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd October 2007, 18:11
  5. PIC lcd ds1820
    By wchpikus in forum mel PIC BASIC
    Replies: 2
    Last Post: - 24th May 2007, 14:46

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