'=========================================================== '= Dallas temperature sensor processor = '= = '= Manfred Mornhinweg, July 2001 = '=========================================================== 'Variables: Temp var Word 'Temperature CRem var byte 'Counts remaining CperC var byte 'Counts per Celsius addr var byte(8) 'Sensor address c var byte 'Universal counter sens var nib 'Sensor number sign var byte 'sign character 'Constants: ip CON 16 '0 'serial input pin op CON 16 '1 'Serial output port ic CON 16884 'Serial input configuration oc CON 16884 'Serial output configuration bp CON 15 'Sensor bus pin 'Startup SEROUT op,oc,["Type s for setup",13] SERIN ip,ic,3000,Mainloop,[c] IF c <> "s" THEN Mainloop 'Setup SEROUT op,oc,["Welcome to the EEROM setup",CR,CR,"Type i for sensor identification,",CR,"x to exit setup",CR] Cmdinput: SERIN ip,ic,[c] IF c="i" then Ident IF c="x" then Mainloop GOTO CmdInput Ident: 'identify sensors SEROUT op,oc,["Connect sensor to be IDed, then enter sensor number in one hex character.",CR] SERIN ip,ic,[HEX1 sens] OWOUT 15,1,[$33] OWIN 15,2,[str addr\8] 'get sensor ROM address FOR c=0 to 7 WRITE (sens*8+c),addr(c) 'write into EEROM NEXT SEROUT op,oc,["Sensor ROM address is "] FOR c=0 to 7 SEROUT op,oc,[hex2 addr(c)," "] next SEROUT op,oc,["and has been stored as sensor #",HEX sens,".",CR,CR,"Type n for next sensor or x to exit.",CR] ask: SERIN ip,ic,[c] IF c="n" THEN Ident: IF c="x" THEN MainLoop GOTO ask Mainloop: 'sens=0 repeat: OWOUT 15,1,[$CC,$44] 'make all sensors convert temperature CheckForDone: PAUSE 25 OWIN 15,4,[temp] IF temp=0 THEN CheckForDone PAUSE 100 'for safety, different sensors FOR sens=0 TO 15 FOR c=0 TO 7 READ (sens*8+c), addr(c) 'read sensor address from EEROM NEXT OWOUT 15,1,[$55,str addr\8,$BE] 'ask specific sensor for data OWIN 15,2,[Temp.Lowbyte,Temp.highbyte,CRem,CRem,CRem,CRem,CRem,CPerC] temp=temp>>1 'strip half-degree bit temp=temp<<8 'leave just sign on the left. High byte=integers temp=temp-64 'discount half step of basic resolution temp=temp-(CRem*16) 'add fraction IF temp.bit15=1 then Negative sign=" " GOTO Adjready Negative: temp=-temp sign="-" AdjReady: SEROUT op,oc,[DEC2 sens+1,":"] IF temp=4400 then NoSensor SEROUT op,oc, [sign,DEC2 temp.HIGHBYTE,".",dec2 temp.LOWBYTE*100/256] GOTO SensorOK NoSensor: SEROUT op,oc,["......"] 'for nonexistent sensors SensorOK: IF sens=15 then Char30 SEROUT op,oc,[CR] GOTO Odone Char30: SEROUT op,oc,[30] 'for QuaT compatibility Odone: NEXT GOTO repeat