BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – OWIN
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 301
The demo program uses a Dallas Semiconductor DS1820 Digital
Thermometer device connected as follows. Note that the 4.7 kpull-up
resistor is required for proper operation.
Figure 5.22: DS1820 Circuit.
NOTE: The 4.7 k resistor is
required for proper operation.
Demo Program (OWIN_OWOUT.bsp)
' OWIN_OWOUT.bsp
' This program demonstrates interfacing to a Dallas Semiconductor DS1822
' 1-Wire Digital Thermometer chip using the BS2p's 1-Wire commands. Connect
' the BS2p, BS2pe, or BS2px to the DS1822 as shown in the diagram in the
' OWIN or OWOUT command description. This program uses a simplified
' approach that ignores the fractional portion of the temperature.
' {$STAMP BS2p}
' {$PBASIC 2.5}
DQ PIN 0 ' 1-Wire buss pin
RdROM CON $33 ' read serial number
MatchROM CON $55 ' match SN -- for multiple devices
SkipROM CON $CC ' ignore SN -- use for one device
CvrtTmp CON $44 ' start temperature conversion
RdSP CON $BE ' read DS1822 scratch pad
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT11 ' 1 = negative temperature
tLo VAR tempIn.BYTE0
tHi VAR tempIn.BYTE1
tSign VAR Bit ' saved sign bit
tempC VAR Word ' final Celsius temp
tempF VAR Word ' final Fahrenheit temp
Main:
DO
GOSUB Get_Temperature ' read temperature from DS1822
DEBUG HOME, ' display
"DS1822", CR,
"------", CR,
NOTE: This example program can be
used with the BS2p, BS2pe and BS2px
by changing the $STAMP directive
accordingly.