PDA

View Full Version : Multi DS18b20 Code help.



sccsltd
- 18th December 2009, 04:47
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.


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


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.

Jerson
- 18th December 2009, 05:35
I've made a few changes to your code. I haven't checked for correctness, but, you get the idea



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

sccsltd
- 18th December 2009, 06:13
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..


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