'' ***************************** '' * DS1620 * '' * (C) 2006 Parallax, Inc. * '' ***************************** '' '' This object provides essential inteface methods to the DS1620; using '' free-running mode while connected to a host. CON RD_TMP = $AA ' read temperature WR_TH = $01 ' write TH (high temp) WR_TL = $02 ' write TL (low temp) RD_TH = $A1 ' read TH RD_TL = $A2 ' read TL RD_CNTR = $A0 ' read counter RD_SLOPE = $A9 ' read slope CNV_START = $EE ' start conversion CNV_STOP = $22 ' stop conversion WR_CFG = $0C ' write config register RD_CFG = $AC ' read config register #0, TEMPC, TEMPF VAR long dpin, cpin, rst, started OBJ io : "shiftio" delay : "timing" PUB start(dataPin, clockPin, rstPin) '' Initializes DS1620 for free-run with host CPU dpin := dataPin cpin := clockPin rst := rstPin high(rst) ' activate sensor io.shiftOut(dpin, cpin, io#LSB_FIRST, WR_CFG, 8) ' write to config register io.shiftOut(dpin, cpin, io#LSB_FIRST, %10, 8) ' set for CPU, free-run low(rst) ' deactivate delay.pause1ms(10) ' allow EE write high(rst) ' reactivate io.shiftOut(dpin, cpin, io#LSB_FIRST, CNV_START, 8) ' start conversions low(rst) started~~ ' flag sensor as started PUB getTempC | tc '' Returns temperature in 0.1° C units '' -- resolution is 0.5° C if started high(rst) ' activate sensor io.shiftOut(dpin, cpin, io#LSB_FIRST, RD_TMP, 8) ' send read temp command tc := io.shiftIn(dpin, cpin, io#LSB_PRE, 9) ' read temp in 0.5° C units low(rst) ' deactivate sensor tc := tc << 23 ~> 23 ' extend sign bit tc *= 5 ' convert to 10ths return tc PUB getTempF | tf '' Returns temperature in 0.1° F units '' -- resolution is 0.9° F if started tf := getTempC * 9 / 5 + 320 ' convert tc to Fahrenheit return tf PUB setLoAlarm(alarm, mode) '' Sets low-level alarm '' -- alarm level is passed in 1° units if started if lookdown(mode : TEMPC, TEMPF) ' valid mode? case mode TEMPC : alarm <<= 1 ' convert to 0.5° units TEMPF : alarm := ((alarm - 32) * 5 / 9) << 1 ' convert to C, 0.5° units high(rst) io.shiftOut(dpin, cpin, io#LSB_FIRST, WR_TL, 8) ' select low temp register io.shiftOut(dpin, cpin, io#LSB_FIRST, alarm, 9) ' write alarm value low(rst) delay.pause1ms(10) ' allow EE write PUB setHiAlarm(alarm, mode) '' Sets high-level alarm '' -- alarm level is passed in 1° units if started if lookdown(mode : TEMPC, TEMPF) ' valide mode case mode TEMPC : alarm <<= 1 ' convert to 0.5° units TEMPF : alarm := ((alarm - 32) * 5 / 9) << 1 ' convert to C, 0.5° units high(rst) io.shiftOut(dpin, cpin, io#LSB_FIRST, WR_TH, 8) ' select hi temp register io.shiftOut(dpin, cpin, io#LSB_FIRST, alarm, 9) ' write alarm value low(rst) delay.pause1ms(10) ' allow EE write PRI high(pin) outa[pin]~~ ' write "1" to pin dira[pin]~~ ' make an output PRI low(pin) outa[pin]~ ' write "0" to pin dira[pin]~~ ' make an output