( 2 Votes )

images1_copy

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

1W20Read20Address1

Note the PIC's power supply/oscillator are not shown

 

Simulation


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.

Proton Tutorial - DS18S20
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 

 
0 #1 help 2010-01-16 01:35

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*

Quote
 
 
0 #2 Graham 2010-01-16 01:36

What program are you simulating with? Or have you physically built the circuit?

Quote
 
 
0 #3 2010-03-12 14:26

What program do you use to capture the simulation to a videofile?

Quote
 
 
0 #4 ahmed zaky 2010-04-25 23:06

i need program about
using keypad wwith proton code

communication pic to pic

yours
ahmed zaky

Quote
 
 
0 #5 picem 2010-05-01 06:33

Use the hardware Uart commands (HRSIN HRSOUT)

Theres a lot of information in the PDS help file

Quote
 
 
0 #6 Bas A 2010-07-27 19:43

Does anaybody know how to use a 18B20?
Thanks in advance

Quote
 
 
0 #7 Jon Chandler 2010-07-28 00:40

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

Quote
 
 
0 #8 Bas A 2010-07-29 17:41

Thanks John.
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.
www.protonbasic.co.uk/showthread.php/59884-Temperature-Sensor-Project-for-newbies-Part-3

Quote
 

Forum Feed

New Articles



Not Quite Trivial - A Tip for using the Software UART with the PICKit 2 +

Not Quite Trivial - A Tip for using the Software UART with the PICKit 2
This tip is almost trivial, but it's a D'uh moment too.  Just in case anyone else has missed the obvious. here's a quick tip.   I usually use Swordfish's hardware UART routines and I don't recommend Swordfish's software UART for input, where there...
Author: Jon Chandler

Simulating Analog Sensor Inputs +

Simulating Analog Sensor Inputs
When developing an embedded application using analog sensor inputs, testing at specific sensor levels can be difficult.  For example, in my icemaker controller project, actions need to occur at certain water levels.  Using the actual sensor...
Author: Jon Chandler

Simple Signal Generator - Revised +

Simple Signal Generator - Revised
I recently had use for the simple signal generatorI described before for testing out some piezo buzzers I got for next to nothing.  I reloaded the code onto a TAP-28 board...
Author: Jon Chandler

Reliable Header Connectors +

Reliable Header Connectors
Header pins are ubiquitous on dev boards.  Jumpers can be used to make connections during tests and code development but real-world applications need reliable connections.  Connectors for single row headers have always been a problem for me,...
Author: Jon Chandler

Swordfish Module - NMEA2 +

Swordfish Module - NMEA2
I had a couple of issues when using David Barkers module NMEA.bas on my Big GPS Clock project. In particular, variables were being corrupted making the program very unstable. I'm not familiar...
Author: Graham

10 Keys on One Port Pin? +

10 Keys on One Port Pin?
I'm working on a control system that will have several relays, a bunch of LEDs and a number of switches.  I was rapidly running out of port pins on a TAP-28 board to handle all the desired I/O.  Possible solutions included adding an I2C port...
Author: Jon Chandler
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Member Access



Whos Online

 We have 16 guests and 3 members online


showcase

Graham reviews the Sure Electronics 915Mhz Wireless Transceivers...

More


showcase

This program provides a means to benchmark the speeds of different cards and software configurations

More


showcase

Jon Chandler shares a method to achieve reliable results with single header connectors

More

TAP-28 Dev Board


showcase

The TAP-28 is an excellent development board. You can contact Jon (the author) to get some cheap

More

Member Access