DS1620 -BS2e-code - How to turn on a light using a thermometer ?
guy20sanjose
Posts: 13
Hello
I'm using a bs2e on a board of education and a DS1620 thermometer. I'd like to know how to write some code to the program below to turn a light on and of with setting temp points. Any help is appreciated.
' {$STAMP BS2e}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program measures temperature using the Dallas Semiconductor DS1620
' temperature sensor. Resolution is 0.5 degrees Celsius.
'
[ I/O Definitions ]
Page 162 StampWorks
DQ CON 0 ' DS1620.1 (data I/O)
Clock CON 1 ' DS1620.2
Reset CON 2 ' DS1620.3
'
[ Constants ]
RdTmp CON $AA ' read temperature
WrHi CON $01 ' write TH (high temp)
WrLo CON $02 ' write TL (low temp)
RdHi CON $A1 ' read TH
RdLo CON $A2 ' read TL
RdCntr CON $A0 ' read counter
RdSlope CON $A9 ' read slope
StartC CON $EE ' start conversion
StopC CON $22 ' stop conversion
WrCfg CON $0C ' write config register
RdCfg CON $AC ' read config register
DegSym CON 186 ' degrees symbol
'
[ Variables ]
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT8 ' 1 = negative temperature
tC VAR Word ' Celsius
tF VAR Word ' Fahrenheit
tHi VAR Word
tLo VAR Word
'
[ Initialization ]
Setup:
HIGH Reset ' alert the DS1620
SHIFTOUT DQ, Clock, LSBFIRST, [WrCfg, %10] ' use with CPU; free-run
LOW Reset
PAUSE 10
HIGH Reset
SHIFTOUT DQ, Clock, LSBFIRST, [StartC] ' start conversions
LOW Reset
DEBUG CLS,
"DS1620 ", CR,
"
"
'
[ Program Code ]
Main:
DO
GOSUB Read_DS1620 ' get the temperature
Display_C:
DEBUG CRSRXY, 0, 2,
(tC.BIT15 * 13 + " "),
DEC (ABS tC / 10), ".", DEC1 (ABS tC),
DegSym, " C", CLREOL
Display_F:
DEBUG CRSRXY, 0, 3,
(tF.BIT15 * 13 + " "),
DEC (ABS tF / 10), ".", DEC1 (ABS tF),
DegSym, " F", CLREOL
PAUSE 1000 ' delay between readings
LOOP
'
[ Subroutines ]
Read_DS1620:
HIGH Reset ' alert the DS1620
SHIFTOUT DQ, Clock, LSBFIRST, [RdTmp] ' give command to read temp
SHIFTIN DQ, Clock, LSBPRE, [tempIn\9] ' read it in
LOW Reset ' release the DS1620
tempIn.BYTE1 = -sign ' extend sign bit
tC = tempIn * 5 ' convert to tenths
IF (tC.BIT15 = 0) THEN ' temp C is positive
tF = tC */ $01CC + 320 ' convert to F
ELSE ' temp C is negative
tF = 320 - ((ABS tC) */ $01CC) ' convert to F
ENDIF
ENDIF
RETURN
How to turn a light on when tF > 88 F, turn off when tF < 88 F ? What code and where do I need to add?
Thank again.
Comments
I don't understand this code:
SHIFTOUT 15,14,LSBFIRST,[1,15\9] ' upper threshold=15/2=7.5 deg C
How do I make change to it to make it upper threshold = 28 deg C ?
Please help
SHIFTOUT 15,14,LSBFIRST,[1,56\9] ' upper threshold=56/2=28 deg C
The \9 after the 56 simply tells the Stamp to shift out 9 bits. That is what is required by the DS1620, so that it can do temperatures both above and below freezing.