
There are 3 digital temperature sensors, so be sure to get the correct one. There is the 1820, 18S20 and 18B20. The 18S20 is the successor to the 1820, and does not drift over time. The 18B20 does offer faster conversions, but for me, the 18S20 more more readily available, and suits my applications fine. Be aware that the 18B20 does require different methods of temperature conversion then that described in this manual for the 18S20.
The basic wiring diagram
Note the PIC's power supply/oscillator are not shown
Be sure to attach the pull-up resistor to the databus, this is a requirement of the Dallas 1-Wire system. This code communicates with the 18S20 with its 64 bit address, you can attach multiple units to the databus, but be sure that you know the 64 bit address so that the correct device is addressed. To ascertain what the device's 64 bit address is, see the 1 Wire introduction section. Be aware that the 64 bit address information is the inner 8 pieces of information in the serial commands, the first and last piece's of information are commands for the device addressed.
Device 16F877
XTAL 4
Declare LCD_TYPE ALPHA ' Type of LCD Used is Alpha
Declare LCD_DTPIN PORTB.4 ' The control bits B0,B1,B2,B3
Declare LCD_RSPIN PORTB.2 ' RS pin on B4
Declare LCD_ENPIN PORTB.3 ' E pin on B5
Declare LCD_LINES 2 ' Amount of LCD lines
Declare LCD_INTERFACE 4 ' Interface method is 4 bit
PORTB_PULLUPS = true
ALL_DIGITAL = TRUE
SYMBOL DQ = Portb.0 'Place the DS1820 on bit 1 of PORTA
Dim Sign as Byte
Dim Cnt as Byte
Dim Count_Per_Deg as Byte
Dim Temp as Word
Dim Temp_Dec as Byte
Delayms 150 ' Let LCD warm up
Cls
' Send a command that creates the degree
Print $FE,$40,$06,$09,$09,$06,$00,$00,$00,$00
' symbol on the LCD, to print it, simply address
' the character as 0, eg,
' Print At 1, 1, Value, 0, "Degrees"
Again:
'Send calculate temperature command
OWRITE DQ, 1,[$55,$10,$31,$C5,$C8,$00,$00,$00,$F4,$44]
' FF I1 I2 I3 I4 I5 I6 CRC
' FF - Family, Ix - Address bytes,
' CRC - checksum
REPEAT
DELAYMS 25 ' Wait until conversion is complete
OREAD DQ,4,[Cnt] ' Keep reading low pulses until
UNTIL Cnt <> 0 ' the DS1820 is finished
'Send read scratchpad command
OWRITE DQ,1,[$55,$10,$31,$C5,$C8,$00,$00,$00,$F4,$BE]
' FF I1 I2 I3 I4 I5 I6 CRC
' FF - Family, Ix - Address bytes,
' CRC - checksum checksum
OREAD DQ,2,[Temp.LOWBYTE,Temp.HIGHBYTE,Cnt,Cnt,Cnt,Cnt,Cnt,Count_Per_Deg]
' Each Cnt is 1/16 of a degree, therefore 100/16 = 6.25, and that's our decimal value
Temp_Dec = (6.25 * Cnt)
' Bits 8-15 are 1 for a negative temperature and 0 for a positive
If Temp.8=1 Then
' If negative then drop the first bit, and invert the value
Temp=(Temp.LowByte ^ $FF) >> 1
' If Cnt = 0 then increment Temp, as the 1820 does not do this
If Cnt = 0 then Temp = Temp + 1
' Change the sign to a negative
Sign = "-"
Else
' If positive then drop the first byte
Temp=(Temp >> 1)
' And change the sign value to positive
Sign = "+"
' Invert the decimal value
Temp_Dec = 100 - Temp_Dec
Endif
' Display the data on the LCD
Print At 1,1, Sign, Dec Temp, ".", Dec DIG Temp_Dec, 1, 0,"C "
Goto Again
Comments
Hi, i simulate as in the youtube video but i only get "-0.5 degree sign C" but i don't get different temp values. I adjust the 18S20 but it only shows the same "-0.5 degree sign C".
My pic is a pic16f84a and here is my program:
*removed to tidy up the comment*
What program are you simulating with? Or have you physically built the circuit?
What program do you use to capture the simulation to a videofile?
i need program about
gmail.com
using keypad wwith proton code
communication pic to pic
yours
ahmed zaky
automation.zaky
Use the hardware Uart commands (HRSIN HRSOUT)

Theres a lot of information in the PDS help file
Does anaybody know how to use a 18B20?
Thanks in advance
Well, searching here turns up 63 hits for the DS18B20. Perhaps somebody does know how to use one!
Proton Basic is the same as Amicus Basic. Graham's recent article on using a DS18B20 with an Amicus board should be a good starting point.
digital-diy.com/home/amicus18/code-examples/215-amicus18-ds18b20-sensor.html
Thanks John.
www.protonbasic.co.uk/showthread.php/59884-Temperature-Sensor-Project-for-newbies-Part-3
You are right.. isn't hard to use the search tool and find a working example for the 18B20.
I would like to share the next link. Its a very good example from Barry. for using the 18B20.