{{ ''*********************************************** ''* Program DS1620_JT2.spin ''* Author: Jon Titus 04-19-2013 Rev. 8 ''* Copyright 2013 ''* Released under Apache 2 license ''* Program used to configure and read a 9-bit ''* temperature value from DS1620 Digital ''* Thermometer and Thermostat. This program ''* does not use the thermostat functions. ''* Based on program DS1620, (C) 2006 Parallax, Inc. ''* DS1620 operates in free-run mode. ''*********************************************** }} CON Read_Temp = $AA ' read temperature Read_Counter = $A0 ' read counter Read_Slope = $A9 ' read slope Start_Convert = $EE ' start conversion Stop_Convert = $22 ' stop conversion Write_Config = $0C ' write config register Read_Config = $AC ' read config register VAR word data_DS1620, clock_DS1620, reset_DS1620, started OBJ io : "shiftio" 'shiftio.spin delay : "timing" 'timing.spin '' Initializes DS1620 for free-run with host CPU PUB start(data_pin, clock_pin, rst_pin) data_DS1620 := data_pin 'DQ pin (1) on DS1620 clock_DS1620 := clock_pin 'CLK pin (2) on DS1620 reset_DS1620 := rst_pin 'RST pin (3) on DS1620 set_high(reset_DS1620) io.shiftout(data_DS1620, clock_DS1620, io#LsbFirst, Write_Config, 8) 'write to DS1620 config register io.shiftout(data_DS1620, clock_DS1620, io#LsbFirst, %10, 8) 'set DS1620 for free-run set_low(reset_DS1620) 'deactivate DS1620 delay.pause1ms(10) 'allow EEPROM write operation set_high(reset_DS1620) 'reactivate DS1620 io.shiftout(data_DS1620, clock_DS1620, io#LsbFirst, Start_Convert, 8) 'start conversions set_low(reset_DS1620) 'pull reset to logic-0 started := -1 'set Started "flag" to true ''Get temperature value from DS1620 and shift into tc in proper bit order '' Returns temperature in binary, 0.5-degree Celsius units PUB gettempc | tc if started 'If DS1620 started, proceed set_high(reset_DS1620) 'activate DS1620 io.shiftout(data_DS1620, clock_DS1620, io#LsbFirst, Read_Temp, 8) 'send "read temp" command tc := io.shiftin(data_DS1620, clock_DS1620, io#LsbPre, 9) 'read temp in 0.5 C units set_low(reset_DS1620) 'deactivate DS1620 return tc PRI set_high(pin) outa[pin] := 1 'write a logic-1 to pin identified in calling command dira[pin] := 1 'make this pin an output PRI set_low(pin) outa[pin] := 0 'write a logic-0 to pin identified in calling command dira[pin] := 1 'make this pin an output ''-----end of DS1620_JT2.spin-----