Figure 5.20: DS1820 Circuit.
NOTE: The 4.7 kΩ resister is
required for proper operation.
5: BASIC Stamp Command Reference – OWIN
The Demo Program uses a Dallas Semiconductor DS1820 Digital
Thermometer device connected as follows. Note that the 4.7 k Ω pull-up
resister is required for proper operation.
2
Demo Program (I2C.bsp)
p
' This program demonstrates interfacing to a Dallas Semiconductor DS1820 1-wire Digital
' Thermometer chip using the BS2p's 1-wire commands. Connect the BS2p to the DS1820
' as shown in the diagram in the OWIN or OWOUT command description.
' This code reads the Counts Remaing and Counts per Degree C registers in the DS1820
' chip in order to provide a more accurate temperature reading (down to 1/100th of a
' degree). It also calculates degrees Fahrenheit. NOTE: The algebraic equations used
' will not work properly with negative temperatures.
'{$STAMP BS2p}
Temp
VAR
CRem
VAR
CPerC
VAR
Start:
OWOUT 0, 1, [$CC, $44]
CheckForDone:
PAUSE 25
OWIN 0, 4, [Temp]
IF Temp = 0 THEN CheckForDone
OWOUT 0, 1, [$CC, $BE]
OWIN 0, 2, [Temp.LOWBYTE,Temp.HIGHBYTE,CRem,CRem,CRem,CRem,CRem,CPerC]
'Calculate temperature in degrees C
Temp = Temp>>1*100-25+((CPerC*100-(CRem*100))/CPerC)
DEBUG HOME, DEC3 Temp/100, ".", DEC2 Temp-(Temp/100*100), " C", CR
'Calculate temperature in degrees F
Temp = Temp*/461+3200
DEBUG DEC3 Temp/100, ".", DEC2 Temp-(Temp/100*100), " F"
GOTO Start
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 203
DS1820
(PR35)
1 2 3
Vss
4.7 k
DQ
P0
'STAMP directive (specifies a BS2p)
WORD
'Holds the temperature value
BYTE
'Holds the counts remaining value
BYTE
'Holds the Counts per degree C value
'Send Calculate Temperature command
'Wait until conversion is done
'Here we just keep reading low pulses until
'the DS1820 is done, then it returns high.
'Send Read ScratchPad command
Vdd
Ω
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?