Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I need help with DS1820

Status
Not open for further replies.

peterzatko

New Member
i need help with DS1820 temperature sensor one-wire.

whats wrong in my code

i need read temperature on PORTB.7 and if temperature is 25°C then 1 is on PORTB.0

i dont use LCD

Please help

main:

PORTB = 00000000
TRISB = 10000000

read_temperature:
PORTB.0 = 0
Ow_Reset(PORTB,7)
Ow_Write(PORTB,7,$CC)
Ow_Write(PORTB,7,$44)
Delay_us(120)

Ow_Reset(PORTB,7)
Ow_Write(PORTB,7,$CC)
Ow_Write(PORTB,7,$BE)

temp = Ow_Read(PORTB,7)
temp = (Ow_Read(PORTB,7) << 8) + temp

Delay_ms(500)

IF temp = 25 then PORTB.0 = 1
else PORTB.0 = 0
end if
delay_ms(500)
goto read_temperature

end.
 
It is usually not good programming to check for an exact value of temp....I would try changing the program to check for either higher than 25 or lower than 25 or
some window of values (such as 20<temp>30). Also I noticed you don't initialize the DS1820 in your code. Which compiler are you using?
 
A pull up resistor pulls the signal up to a voltage level until it changes, it basically stops it from floating and gives it a reference voltage without pulling any or much current.

The first thing to check is what PIC you are using and is any other peripheral multiplexed on that particular pin, you should have some debugging output such as RS232 for example if you don't have a LCD as your temperature sensor might never reach the temperature required, or the values may not be as expected.

You can check the return values from the OW functions in Mikro B, might be worth seeing if it can actually find your temperature sensor by reading the result of OW_Reset, check the help manual for more info on that, I think it returns '0' if no device is found.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top