'{$STAMP BS2} ' DS1620_1.BS2 ' ' Illustrates how to measure temperature using DS1620 3-Wire Thermometer ' ' BS2 DS1620 ' ' Pin2 (term 7) -------------------- DQ (term 1) ' Pin1 (term 6) -------------------- CLk (term 2) ' Pin0 (term 5) -------------------- RST (term 3) ' ' ' Debug statements were included only to see what is going on. ' ' Program configures 1620 for CPU operation, starts conversion, makes ' 10 measurments and stop conversion. ' ' copyright H. Paul Roach, MSU, March 13, '97 ' o_byte VAR Byte ' byte sent to DS1620 i_9_bit VAR Word ' reaw temperature data from 1620 T_C VAR Word n VAR Byte ' index times VAR Byte ' number of measurements DIRS = $f0ff IN CON 0 OUT CON 1 RST CON 0 CLK CON 1 DQ CON 2 DQ_OUT VAR OUT2 DQ_IN VAR IN2 DQ_DIR VAR DIR2 main GOSUB config_1620 ' configure 1620 GOSUB start_convert ' continuous conversion FOR times=1 TO 10 ' make 10 measurments GOSUB meas T_C = i_9_bit/2 DEBUG DEC T_C SLEEP 60 ' one minute between readings NEXT GOSUB stop_convert ' stop conversion process to save power STOP config_1620 ' send command $0c followed by $02 to configure ' for CPU mode LOW RST HIGH CLK HIGH RST ' initiate by bringing RST high o_byte = $0c GOSUB out_byte o_byte = $02 GOSUB out_byte LOW RST PAUSE 200 ' give some time for the internal programming RETURN start_convert ' send command $ee to cause continuous conversion HIGH CLK HIGH RST o_byte = $ee GOSUB out_byte LOW RST RETURN meas ' send command $aa to read data and then read HIGH CLK HIGH RST o_byte = $aa GOSUB out_byte GOSUB get_9_bits LOW RST RETURN stop_convert ' send command $22 to stop the conversions HIGH CLK HIGH RST o_byte = $22 GOSUB out_byte LOW RST RETURN out_byte ' outputs byte in o_byte, beginning with least ' significant bit DQ_DIR=OUT FOR n = 0 TO 7 DQ_OUT = o_byte & $01 'least significant bit LOW CLK DEBUG DEC DQ_OUT HIGH CLK o_byte = o_byte >> 1 'shift data 1 place right NEXT DEBUG 13 RETURN get_9_bits ' reads 9 bits from 1620 beginning with least ' significant bit DQ_DIR = IN i_9_bit = 0 FOR n = 0 TO 8 LOW CLK i_9_bit = (i_9_bit >> 1) | (DQ_IN << 8) DEBUG DEC DQ_IN HIGH CLK NEXT DQ_DIR=OUT DEBUG 13 RETURN