Multi DS18b20 Code help.


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    6

    Default Multi DS18b20 Code help.

    Hi guys.

    im stumpped.

    i currently have my pic16f628 reading from 9 DS18b20 and outputting to the pc.
    working great except its now 2000 words.

    currently i query each device in turn with its hardcoded rom id.
    like so.

    Code:
        OWOUT DQ, 1, [$55,$28,$DE,$0E,$66,$02,$00,$00,$BD,$BE]
        OWIN DQ, 2, [Temp2.LOWBYTE,Temp2.HIGHBYTE]'
        TEMPnow2 = Temp2 + ofst30 
        if Temp2 = 65535 then
        Temp2 = 0
        tempnow2 = 480
        else
        hserout ["TEMP2 Raw:= ",dec4 Temp2,13]
        endif
    this works perfectly for me but thast code repeats for each DS18b20
    but i am trying to do something like the following

    Code:
    i=1
        h=0
        read h, id 
        while i<9
        OWOUT DQ, 1,[$55,id,$BE]
        OWIN DQ, 2, [Temps.LOWBYTE(i),Temps.LOWBYTE(i+1)]
        TEMPnows[i] = Temps[i] + ofst30 
        if Temps[i] = 65535 then
        Temps[i] = 0
        tempnows[i] = 480
        else
        hserout ["TEMP",dec i," Raw:= ",dec4 TEMPs[i],13]
        endif
        i=i+1
        h=h+8
        wend
    i have the rom id's stored in eeprom starting at 0
    the above code compiles but dont work,

    any ideas?

    thanks.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I've made a few changes to your code. I haven't checked for correctness, but, you get the idea

    Code:
    id  var byte[8]
    
        for i = 0 to 8
    
        ' read from eeprom address for the channel to ID
        for h=0 to 7
             read i*8+h, id+h
        next
    
        OWOUT DQ, 1,[$55,id+0,id+1,id+2,id+3,id+4,id+5,id+6,id+7,$BE]
        OWIN DQ, 2, [Temps.LOWBYTE(i),Temps.LOWBYTE(i+1)]
        TEMPnows[i] = Temps[i] + ofst30 
        if Temps[i] = 65535 then
        Temps[i] = 0
        tempnows[i] = 480
        else
        hserout ["TEMP",dec i," Raw:= ",dec4 TEMPs[i],13]
        endif
        i=i+1
        next

  3. #3
    Join Date
    Dec 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thats what i needed thanks.
    modified as below seems to be working fine.

    i had to add j and k to increment the lowbyte correctly.
    with i and i +1 it was over writing the previous bytes.
    j increments even and k increments odd prob not the best way to do it but hey it works..

    Code:
    j=0
    k=1
    for i = 0 to 8
        for h=0 to 7
             read i*8+h, id[h]
        next
        OWOUT DQ, 1,[$55,id[0],id[1],id[2],id[3],id[4],id[5],id[6],id[7],$BE]
        OWIN DQ, 2, [Temps.LOWBYTE[j],Temps.LOWBYTE[k]]
        TEMPnows[i] = Temps[i] + ofst30 
        if Temps[i] = 65535 then
        Temps[i] = 0
        tempnows[i] = 480
        else
        hserout ["TEMP",dec i," Raw:= ",dec4 TEMPs[i],13]
        endif
        j=j+2
        k=k+2
        next

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 20:48
  2. Please help with code for DS18B20
    By fratello in forum mel PIC BASIC Pro
    Replies: 109
    Last Post: - 28th April 2013, 22:12
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  4. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  5. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26

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