' {$STAMP BS2pe} ' {$PBASIC 2.5} 'Wait for the eb500 radio to be ready '------------------------------------ PAUSE 1000 ' delay between readings,1000ms pause to allow the EB500 to initialize 'connect to remote device SEROUT 1,84,["con 00:0c:84:00:77:3D",CR] SERIN 0,84,[WAIT("ACK",CR)] 'wait for the connection to be established and switch to data mode waitForConnection: IF IN5 = 0 THEN waitForConnection HIGH 6 PAUSE 300 ' -----[ Program Description ]--------------------------------------------- ' ' This program measures temperature using the Dallas Semiconductor DS1620 ' temperature sensor. Resolution is 0.5 degrees Celsius. ' -----[ I/O Definitions ]------------------------------------------------- DQ CON 3 ' DS1620.1 (data I/O) Clock CON 2 ' DS1620.2 Reset CON 1 ' 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 ' -----[ Initialization ]------------------------------------------------- Setup: HIGH Reset ' alert the DS1620 SHIFTOUT DQ, Clock, LSBFIRST, [WrCfg, %10] ' use with CPU; free-run LOW Reset PAUSE 10 '-------[Setting T_Hi]------------------------------------------------------- HIGH Reset ' Tells the DS1620 that a command is coming. SHIFTOUT DQ, Clock, LSBFIRST, [WrHi,$40\9] ' Command to set DS1620 TH to 32. LOW Reset ' Completes the command cycle. PAUSE 10 '-------[Setting T_Lo]------------------------------------------------------- HIGH Reset ' Tells the DS1620 that a command is coming. SHIFTOUT DQ, Clock, LSBFIRST, [WrLo,$3E\9] ' Command to set DS1620 TH to 31. LOW Reset ' Completes the command cycle. PAUSE 10 '------------------------------------------ HIGH Reset SHIFTOUT DQ, Clock, LSBFIRST, [StartC] ' start conversions LOW Reset Init_Graph: SEROUT 1,84, ["!RSET", CR] ' clear graph SEROUT 1,84, ["!SPAN 25,35", CR] ' disply 70 - 80 degrees SEROUT 1,84, ["!AMUL 0.1", CR] ' convert from tenths SEROUT 1,84, ["!CLMM"] ' clear min/max values SEROUT 1,84, ["!TMAX 3600", CR] ' 1 hour scale SEROUT 1,84, ["!PNTS 60", CR] ' graph every second SEROUT 1,84, ["!MAXS", CR] ' stop when graph full SEROUT 1,84, ["!TSMP ON", CR] ' enable time stamping SEROUT 1,84, ["!TITL Temperature Monitoring", CR] ' set window title SEROUT 1,84, ["!USRS Temperature in Celsius", CR] ' graph legend SEROUT 1,84, ["!CLRM", CR] ' clear messages SEROUT 1,84, ["Reset and monitoring temperature", CR]' message box SEROUT 1,84, ["!PLOT ON", CR] ' enable plotting ' -----[ Program Code ]---------------------------------------------------- Main: 'DO GOSUB Read_DS1620 ' get the temperature tempIn.BYTE1 = -sign ' extend sign bit tC = tempIn * 5 ' convert to tenths SEROUT 1,84, [DEC tC, CR] 'DEBUG DEC tC, CR ' send to Stamp Plot Lite PAUSE 990 ' wait about 1 second GOTO Main ' do it again ' -----[ 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 RETURN