DS18B20 temperature sensors

I’m working with a DS18B20 temperature sensor.

When I use the code in the manual I get a syntax error on the “Wait” statement:

temp var word
convert var long
counter var byte
main
owout P0,1,main,$cc,$44] ;note 1
Wait
owin P0,0,[temp] ;note 2
if temp = 0 then wait ;note 3
owout P0,1,main,$cc,$be] ;note 4
owin P0,0,[temp.byte0,temp.byte1] ;note 5
convert = float temp fdiv 2.0 ;note 6
debug "Temperature = ",real convert," C",13] ;note 7
goto main

When I try this code as soon as I hit the owout statement it appears to reset the BAP and go back to the beginning of the program. Is this a bug with the owout statement? Has anyone else gotten this to work?

[code]temp var word
convert var long

main
Pause 1000
SEROUT s_out, I4800, “line 7”, 10, 13]
owout P0,1,conton,$CC,$44]
conton

SEROUT s_out, I4800, “line 9”, 10, 13]
Pause 1000
owout P0,1,main,$CC,$BE]

SEROUT s_out, I4800, “line 13”, 10, 13]

temp = temp >> 4

owin P0,0,[temp.byte0,temp.byte1]
convert = (temp * 10) / 2
SEROUT s_out, I4800, “Temperature = “,real convert,” C”,13]
goto main
[/code]

I have not tried the temperature sensor or the like, but I think the sample code in the old manual needs help…

I believe in your first post you are running into a case where the word WAIT is now a reserved keyword. If you change this and the if that refers to it to a different label name it helps.

Next you will run into the line: convert = float temp fdiv 2.0 ;note 6
I ran into several issues here, one you are trying to assign a floating pint to a variable that is defined as a long and likewise try to display it as a real value on the next line. So needed to switch the type of convert to float.

Next FDIV is not defined…

I have not used the OWIN/OWOUT code but looking at the description, do you have a sensor plugged into P0? Do you have the appropriate pull-up resistor connected? If I understand this code, if the OWOUT fails it will jump back to MAIN: which is at the beginning of your code, so are you sure that the processor is resetting?

Sorry I can not help more.
Kurt

Sensor is on P0. I have a 4.7k resistor (see pic below).

I changed my code and as soon as it hits OWOUT it jumps above the main label and starts at skipme = 1
I also commented out the first OWOUT in the code but when it hit the second the same thing happened. Then I commented both of them out and it hung on the OWIN until it must have hit a timeout and then it moved forward but the value in the buffer was zero.

[code]temp var word
convert var long

skipme var long

skipme = 1
main
Pause 1000
SEROUT s_out, I4800, “line 7”, 10, 13]
if skipme = 1 then
owout P0,1,continue01,$CC,$44]
skipme = 2
endif
continue01

SEROUT s_out, I4800, “line 9”, 10, 13]
Pause 1000
owout P0,1,continue02,$CC,$BE]

continue02

SEROUT s_out, I4800, “line 13”, 10, 13]

temp = temp >> 4

owin P0,0,[temp.byte0,temp.byte1]
convert = (temp * 10) / 2
SEROUT s_out, I4800, “Temperature = “,real convert,” C”,13]
goto main [/code]

I specifically bought these temp sensors because the manual had the sample code. I thought this one was going to be a piece of cake!

Below is a picture of the sensor on the right with the 4.7k pull-up resistor. The project on the left is another temp sensor I can’t get working!

http://www.otherrobots.com/lynxmotion/DS18B20TempSensor.jpg

This is code from an older version of the compiler where floating point was not fully integrated like it is now. Send me an email with the code and I’ll update it for you. I also think I have the 18B20 around here somewhere so I can test it myself. [email protected]

The code:

temp var word convert var long counter var byte main owout P0,1,main,$cc,$44] ;note 1 Wait owin P0,0,[temp] ;note 2 if temp = 0 then wait ;note 3 owout P0,1,main,$cc,$be] ;note 4 owin P0,0,[temp.byte0,temp.byte1] ;note 5 convert = float temp fdiv 2.0 ;note 6 debug "Temperature = ",real convert," C",13] ;note 7 goto main

The manual:

basicmicro.com/downloads/doc … o_8000.pdf

Thanks for helping out on this. I have a hexapod. I’d like to stick these on my hottest servos and go to sleep when they get too hot. Then wake back up again once they cool down.

I’ve got your email now. I’ve still got to go through my boxes and fine one of these. I’m pretty sure we got some new ones in a couple months ago for testing in situations just like this but I just moved and everything is boxed up. If I can’t find them I’ll have to put in a Digikey order so it may be next week in that case before I can figure out the problem.