Jack
The reason your PBP version did not work was because:
You attempted to convert C to F using the RAW temp from the DS18S20.
TEMP = ((TEMP*9/5)+32 )
Then tried to calculate the temp from the results.
Lcdout $fe, 1, dec (temp >> 1),".",dec(temp.0 * 5)," degrees C"
For the fun of it lets plug some numbers in assume 27.5 C is the temp today.
From the datasheet : The temperature sensor output has 9-bit resolution, which corresponds to 0.5°C steps.
so 27.5*2 = 55
Temp = (55*9/5) + 32 = 131
So Temp now is equal to 131.
Next we shift right 131>>1 same as temp/2 = 65.5
Hmmm 65.535 does that number ring a bell?
Wonder what would happen if you were to shift first then convert C to F like all of the other code posted does?
temp = (temp>>1*9/5) +32 = (27.5*9/5)+32 = 81.5 F
Hopefully this explains to you why it works in MikroBasic and not in PBP. The math is not broken, just the order of operation.
That is why I said check math, simple change would fix it.
Acetronic: I ask because you posted for jcleaver, would not take without asking first.![]()
Bookmarks