PDA

View Full Version : Reading temperature using multi DS18B20



KVLV
- 7th February 2008, 07:26
- chip use: pic16F876A running @ 20MHz, 2x20 alphanumeric LCD, DS18B20, MAX233

- software: when first power up the PIC scans for the DS18B20 and store ID ROM in the PIC's ram for later use. When the reads temperature and display the reading to the 2x20 LCD, also send out the temperature reading to RS232 for data logging.

-schematic included.

Please give credit to Mr. E, Jimbab, Bruce... as I copied some of their subroutines and modified.

Comments are welcome.

Thanks for reading.

In the zip file, you will find the pbp program and a pdf file for schematic.

Pic_User
- 7th February 2008, 17:01
Hi KV,

Thanks for a great piece of work!

Thanks also to, Mr. E, Jimbab, Bruce and others. The helpers on this forum are heroes to all of us.

This is really nice to have the whole package. Schematic, and code working together. A real contribution to the forum. Thanks for the extra work of putting it together and posting it for all.

Great,
-Adam-

duncan303
- 7th February 2008, 17:58
Hi KVLC

An exception to the rule :) The whole kaboosh

Glad I logged on

got some 18b20's around, makes me want to fire them up.

youve put a lot of thought into this, great preparation! and presentation.

A real gem:D

Thankyou

skimask
- 7th February 2008, 18:05
An exception to the rule :)

True statement...Think I'm going to order a few more and have a play with them...

The example is fine, looks great...

How long do you suppose it'll take before somebody asks for code rewritten for different PICs, running at different speeds, adding in their own applications, using different versions of the '1820 (DS1820, DS18S20, etc.)...

nukte
- 3rd November 2008, 01:58
Your DS18B20 program is fantastic, and I would like to experiment with it.
You mention in your header, I should also see schematic 876DS18B20_ID_ROM_A.PBP.SCHDOC, but I can't find it anywhere. I can figure out most of the schematic from the code, but I will be using a serial LCD for my display, and need to know the type of LCD you used so that I might convert the codes.
Thanks again for a really well thought out piece of code

mister_e
- 3rd November 2008, 02:01
Everything is in the PDF file in the ZIP file.

nukte
- 3rd November 2008, 03:35
Sorry, I just don't see the part number for the LCD used . Thanks

mister_e
- 3rd November 2008, 08:14
Any 2x20 character LCD based on Hitachi HD44780 controller, or equivalent, would do.

nukte
- 4th November 2008, 01:12
Thanks, I'll use the Hitachi codes for the conversion to my serial LCD

solidus
- 22nd January 2009, 00:21
I have problem to simulate the codes with proteus 7.4sp3. Program stuck at searching DS screen! Any idea friends ? And I dont need to use MAX233.What should I do with the codes ?

mister_e
- 22nd January 2009, 00:44
Proteus don't stuck... proteus sucks :D

Try it on real world hardware.. sure enough it will work!

However, you may try to upload your files here (code, proteus files and compiled .HEX) so if anyone have waste cash on Proteus would be able to check it for you.

KVLV
- 19th April 2009, 09:15
Updated:
I use part of the OP program to control a broken oil heater, this time I use solid state relays.
the attachment included with the .pbp file and schematic in .pdf also 2 non-modified Instant Interrupt routines from Darrel Taylor << Thanks.

thinktank
- 8th October 2009, 09:27
I wish to implement a PIC16F877 based temperature controller. A LM35DZ temperature sensing IC is connected to RA0 and 10bit A/D value is used to obtain voltage values at regular intervals. The value of the obtained temperature ( LM35DZ is calibrated to 10mV/0 C) is displayed on a HD44780 LCD module which is connected on PortB and using 4-bit data lines (RB4 to RB7). The deviation from the set-point temperature is used to compute a PID output and this output is used to generate PWM control signals. Both CCP modules of the PIC16F877 are used CCP1 being connected to the gate of the heater driving NMOSFET (IRL1004) and CCP2 also to the gate of the fan driving NMOSFET. The duty cycle has to be varied in proportionto the amount of deviation.

If you have any constructive advice do not hesitate to offer it or if anyone can hook me up with a similar design or relevant source code. I am familiar with both C and Basic programming languages. My regular email is [email protected] .Thanks in advance.

BertMan
- 24th September 2011, 18:08
I am having some troubles understanding the read temperature portion of this code. Take the following exerpt from the code:
W1:
OWIN DQ,4,[busy] ' Check for still busy converting
IF busy = 0 THEN W1' Still busy?, then loop
owout dq,1,[$55,S[(L*8)+0],S[(L*8)+1],S[(L*8)+2],S[(L*8)+3],S[(L*8)+4],S[(L*8)+5],S[(L*8)+6],S[(L*8)+7],$BE]
OWIN dq, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
HotOrCold:
IF Cold_Bit = Real_Cold THEN ' If Cold_Bit = 1, it's below "0" LcdDeg C
Sign = "-" ' Display - symbol for negative temp
Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise LcdDeg C
endif

if cold_bit = 0 then
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise LcdDeg C
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
endif

1. Okay so, under HotOrCold:, about 10 lines down you are assigning TempC to DIV32 10. No problems there. Then you assign TempC to (R_Temp & $0FF0) >> 4. Does this not just overwrite the value of TempC that you just assigned?

2. Under HotOrCold: again. 3 lines down. What is the "~" for? Couldn't find any documentation on this from the picbasic help file. And what does the +1 do?

Heckler
- 24th September 2011, 18:29
I think I can answer your last question...

~ is Bitwise NOT... meaning to invert each bit

For the other question I can not help... I have yet to understand exactly what the DIV32 function does.

BertMan
- 24th September 2011, 20:10
Thanks! That clears that up. Do you know why the +1 on the end?

The DIV32 command allows you to divide the 32 bit number held in internal registers. But that's not really important here. More importantly, why do we assign TEMPC, then reassign it again on the next line of code without using it.

mtroutt
- 3rd November 2017, 20:48
Thanks for posting your code. I was having difficulty with negative readings and converting to an integer. I saw what I was doing wrong, corrected my code and now I can read negative temperatures.
thanks,