VOC Optimation
authorTobias <tm@tm3d.de>
Thu, 16 Jun 2016 12:11:57 +0000 (14:11 +0200)
committerTobias <tm@tm3d.de>
Thu, 16 Jun 2016 12:11:57 +0000 (14:11 +0200)
101 files changed:
DS18B20_BMP280/DS18B20_BMP280.atsln
DS18B20_BMP280/DS18B20_BMP280.c
DS18B20_BMP280/DS18B20_BMP280.cproj
DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.atsln
DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj
DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c
DS18B20_MAX44009/DS18B20_MAX44009.atsln
DS18B20_MAX44009/DS18B20_MAX44009.c
DS18B20_MAX44009/DS18B20_MAX44009.cproj
DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c
DS18B20_MAX44009_DS2438_SHT/DS18B20_MAX44009_DS2438_SHT.atsln
DS18B20_MAX44009_DS2438_SHT/DS18B20_MAX44009_DS2438_SHT.cproj
DS18B20_Thermocouble/DS18B20_TC.atsln
DS18B20_Thermocouble/DS18B20_TC.c
DS18B20_Thermocouble/DS18B20_TC.cproj
DS18B20_Thermocouble/Typ-J.csv
DS18B20_Thermocouble/convthermocouple.py
DS18B20_VOC/DS18B20_VOC.atsln
DS18B20_VOC/DS18B20_VOC.c
DS18B20_VOC/DS18B20_VOC.cproj
DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c
DS18B20_VOC_DS2438_SHT/DS18B20_VOC_DS2438_SHT.atsln
DS18B20_VOC_DS2438_SHT/DS18B20_VOC_DS2438_SHT.cproj
DS18B20_VOC_DS2438_SHT/MAX1164x.h [deleted file]
DS2406/DS2406.atsln
DS2406/DS2406.c
DS2406/DS2406.cproj
DS2406/OWDS2406.S
DS2423/DS2423.c
DS2423/DS2423.cproj
DS2423_BMP280/DS2423_BMP280.atsln
DS2423_BMP280/DS2423_BMP280.c
DS2423_BMP280/DS2423_BMP280.cproj
DS2438_DHT22/.gitignore
DS2438_DHT22/DS2438_DHT22 - Kopie.c
DS2438_DHT22/DS2438_DHT22.c
DS2438_DHT22/DS2438_DHT22.cproj
DS2438_DHT22/OWDS2438.S
DS2438_HIH9121/DS2438_9121.atsln
DS2438_HIH9121/DS2438_HIH9121.c
DS2438_HIH9121/DS2438_HIH9121.cproj
DS2438_SHT2X/DS2438_SHT2X.atsln
DS2438_SHT2X/DS2438_SHT2X.c
DS2438_SHT2X/DS2438_SHT2X.cproj
DS2450/DS2450.atsln
DS2450/DS2450.c
DS2450/DS2450.cproj
DS2450/OWDS2450.S
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.atsln
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.c
DS2450_SHT2X_BMP280_MAX44009/DS2450_SHT2X_BMP280_MAX44009.cproj
DS2450_SHT2X_BMP280_MAX44009/OWDS2450.S
common/I2C/BMP280.c
common/I2C/BMP280.h
common/I2C/MAX1164x.c
common/I2C/MAX1164x.h
common/I2C/MAX44009.c
common/I2C/MAX44009.h
common/I2C/SHT2x.c
common/I2C/SHT2x.h
common/I2C/TSL256x.c
common/I2C/TSL256x.h
common/I2C/USI_TWI_Master.c
common/I2C/USI_TWI_Master.h
common/OWCRC16.s
common/OWCRC8.s
common/OWConfig.s
common/OWDS18B20.S
common/OWDS18B20_DS2438.S
common/OWDS2423.S
common/OWDS2438.S
common/OWPinInterrupt.s
common/OWRomFunctions.s
common/OWRomFunctionsDual.s
common/OWSet_ATTINYX4.s
common/OWSet_ATTINYX5.s
common/OWTimerInterrupt.s
common/calibr.c
common/calibr.h
programmer/flash/flashp 2.7.bat
programmer/flash/flashp.bat
programmer/programmer.atsln
programmer/programmer/programmer.asm
programmer/programmer/programmer.asmproj
programmer/programmer/programmer_4mhz.asm
programmer/programmer/programmer_8MHz.asm
stest/fdiff.py
stest/find.py
stest/log_all1.py
stest/separate1.py
tools_cmd/owtools.sdf
tools_cmd/owtools.sln
tools_cmd/rwOW/crcutil.c
tools_cmd/rwOW/ibtmexcw.h
tools_cmd/rwOW/main.cpp
tools_cmd/rwOW/owerr.c
tools_cmd/rwOW/ownet.h
tools_cmd/rwOW/tmexlnk.c
tools_cmd/rwOW/tmexnet.c
tools_cmd/rwOW/tmexses.c
tools_cmd/rwOW/tmextran.c

index 764eb5c..c6afe44 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280", "DS18B20_BMP280.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280", "DS18B20_BMP280.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 4a78bad..261c78d 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/BMP280.h"
-
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-
-
-
-uint8_t owid[8]={0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40};/**/
-uint8_t config_info[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-
-
-
-
-
-int main(void){
-    PRR|=(1<<PRADC);  // adc for save Power
-       pack.temp=0x0550;
-       pack.config=0x7F;
-       pack.TH=75;
-       pack.TL=70;
-       pack.rrFF=0xFF;
-       pack.rr00=0;
-       pack.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       bmp280Init();
-       //DDRB|=(1<<PINB1);
-       gcontrol=1;
-       sei();
-    while(1)   {
-       
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1); //Dauer 5.4ms
-                       uint32_t P;
-                       int32_t t;
-                       bmp280ConvertInt(&t,&P,1);
-                       P=P-70000;
-                       P=P/20;
-                       uint16_t w=P;
-                       uint8_t t8=w>>4;
-                       uint8_t af=0;
-                       if (t8>pack.TH) af=1;
-                       if (t8<=pack.TL) af=1; 
-                       cli();
-                       pack.temp=w;
-                       //pack.temp++;
-                       alarmflag=af;
-                       sei();                  
-                       EXTERN_SLEEP();
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               //MCUCR&=~(1<<ISC01);
-               asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/BMP280.h"\r
+\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+\r
+\r
+\r
+uint8_t owid[8]={0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40};/**/\r
+uint8_t config_info[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       pack.temp=0x0550;\r
+       pack.config=0x7F;\r
+       pack.TH=75;\r
+       pack.TL=70;\r
+       pack.rrFF=0xFF;\r
+       pack.rr00=0;\r
+       pack.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       bmp280Init();\r
+       //DDRB|=(1<<PINB1);\r
+       gcontrol=1;\r
+       sei();\r
+    while(1)   {\r
+       \r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1); //Dauer 5.4ms\r
+                       uint32_t P;\r
+                       int32_t t;\r
+                       bmp280ConvertInt(&t,&P,1);\r
+                       P=P-70000;\r
+                       P=P/20;\r
+                       uint16_t w=P;\r
+                       uint8_t t8=w>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack.TH) af=1;\r
+                       if (t8<=pack.TL) af=1; \r
+                       cli();\r
+                       pack.temp=w;\r
+                       //pack.temp++;\r
+                       alarmflag=af;\r
+                       sei();                  \r
+                       EXTERN_SLEEP();\r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               //MCUCR&=~(1<<ISC01);\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 972c6c0..b41de76 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_BMP280</AssemblyName>
-    <Name>DS18B20_BMP280</Name>
-    <RootNamespace>DS18B20_BMP280</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\I2C\BMP280.c">
-      <SubType>compile</SubType>
-      <Link>BMP280.c</Link>
-    </Compile>
-    <Compile Include="..\common\OWDS18B20.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20.S</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="DS18B20_BMP280.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_BMP280</AssemblyName>\r
+    <Name>DS18B20_BMP280</Name>\r
+    <RootNamespace>DS18B20_BMP280</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\I2C\BMP280.c">\r
+      <SubType>compile</SubType>\r
+      <Link>BMP280.c</Link>\r
+    </Compile>\r
+    <Compile Include="..\common\OWDS18B20.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20.S</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_BMP280.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 0a5815e..1b9d0ed 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280_DS2438_SHT", "DS18B20_BMP280_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_BMP280_DS2438_SHT", "DS18B20_BMP280_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 971060d..9c39af3 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_DS2438</AssemblyName>
-    <Name>DS18B20_BMP280_DS2438_SHT</Name>
-    <RootNamespace>DS18B20_DS2438</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data>
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000789</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\I2C\SHT2x.c">
-      <SubType>compile</SubType>
-      <Link>SHT2x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\calibr.c">
-      <SubType>compile</SubType>
-      <Link>calibr.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
-      <SubType>compile</SubType>
-      <Link>BMP280.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20_DS2438.S</Link>
-    </Compile>
-    <Compile Include="DS18B20_DS2438.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_DS2438</AssemblyName>\r
+    <Name>DS18B20_BMP280_DS2438_SHT</Name>\r
+    <RootNamespace>DS18B20_DS2438</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data>\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000789</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\I2C\SHT2x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>SHT2x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\calibr.c">\r
+      <SubType>compile</SubType>\r
+      <Link>calibr.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">\r
+      <SubType>compile</SubType>\r
+      <Link>BMP280.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20_DS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_DS2438.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index d8b04bd..f7261e3 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/SHT2x.h"
-#include "../common/I2C/BMP280.h"
-#include "../common/calibr.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-
-uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
-uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
-uint8_t config_info1[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
-uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-volatile uint8_t wdcounter=3;
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-       #else
-       ISR(WDT_vect) {
-       
-#endif 
-       //sleep_disable();          // Disable Sleep on Wakeup
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-/*     if (timeout==2) {
-               DIS_TIMER;
-               EN_OWINT;
-               mode=OWM_SLEEP;
-       }
-       timeout++;*/
-       //sleep_enable();           // Enable Sleep Mode
-
-}
-
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack1_t;
-volatile pack1_t pack1;
-
-
-
-typedef union {
-       #if  defined(__AVR_ATtiny25__)
-       volatile uint8_t bytes[16];
-       #else
-       volatile uint8_t bytes[64];
-       #endif
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               #if  defined(__AVR_ATtiny25__)
-               #else
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-               #endif
-       };
-} pack2_t;
-volatile pack2_t pack2;
-
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-int testSW(void) {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-       __asm__ __volatile__ ("nop");
-       PORTB|=(1<<PORTB0); //Pullup
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       r=PINB&(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       PORTB&=~(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-       
-       
-}
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-       uint32_t P;
-       int32_t t;
-
-int main(void){
-    PRR|=(1<<PRADC);  // adc for save Power
-       PORTA=0xFF;
-       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-       DDRB|=(1<<PORTB0); //Als Ausgang und 0
-       
-       pack1.temp=0x0550;
-       pack1.config=0x7F;
-       pack1.TH=75;
-       pack1.TL=70;
-       pack1.rrFF=0xFF;
-       pack1.rr00=0;
-       pack1.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       //MCUCR &=~(1<<BODS);
-
-       
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-       if (testSW()) {
-               config_info2[5]=8;
-               }else{
-               config_info2[5]=7;
-       }
-       
-
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       
-       SHT2x_SoftReset();
-       SHT2x_ReadUserRegister(userRegister);
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg
-       // --- measure humidity with "Hold Master Mode (HM)" ---
-       //SHT2x_MeasurePoll(HUMIDITY, &sRH);
-       // --- measure temperature with "Polling Mode" (no hold master) ---
-       //SHT2x_MeasurePoll(TEMP, &sT);
-       //-- calculate humidity and temperature --
-       //temperatureC = SHT2x_CalcTemperatureC(sT);
-       //humidityRH = SHT2x_CalcRH(sRH);
-       bmp280Init();
-       gcontrol=1;
-       sei();
-    while(1)   {
-               if (gcontrol) {
-                       wdcounter=3;
-                       
-               }
-
-               if (wdcounter>2) {
-                       SHT2x_MeasurePoll(HUMIDITY, &sRH);
-                       // --- measure temperature with "Polling Mode" (no hold master) ---
-                       SHT2x_MeasurePoll(TEMP, &sT);
-                       //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT);
-                       humidityRH = SHT2x_CalcRH(sRH);
-                       humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;
-                       temperatureC=temperatureC*10.0-4.5;
-                        if (testSW()) {
-                                am2302_hum= humidityRH*10.0;
-                                am2302_temp=temperatureC*25.6;
-                                am2302_temp=am2302_temp-20;
-                                config_info2[5]=8;
-                                
-                                }else{
-                                
-                                double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                                //am2302_hum=0.318*hhum +76.0;
-                                am2302_hum=0.31*hhum +80;
-                                am2302_temp=temperatureC*25.6;
-                                am2302_temp=am2302_temp-20;
-                                config_info2[5]=7;
-                        }
-                       wdcounter=0;
-               }
-       
-               if (gcontrol==1) {
-                       
-                               bmp280ConvertInt(&t,&P,1);
-                               P=P-70000;
-                               P=P/20;
-                               uint16_t w=P;
-                               uint8_t t8=w>>4;
-                               uint8_t af=0;
-                               if (t8>pack1.TH) af=1;
-                               if (t8<=pack1.TL) af=1;
-                               cli();
-                               pack1.temp=w;
-                               //pack.temp++;
-                               alarmflag=af;
-                               sei();
-                               gcontrol=0;
-                               EXTERN_SLEEP(); 
-               }
-               if (gcontrol) {
-                       gcontrol=0;
-                       
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               //MCUCR&=~(1<<ISC01);
-               asm("SLEEP");
-   }
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/SHT2x.h"\r
+#include "../common/I2C/BMP280.h"\r
+#include "../common/calibr.h"\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+\r
+uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/\r
+uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/\r
+uint8_t config_info1[16]={0x02,0x03, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        \r
+uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        \r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+volatile uint8_t wdcounter=3;\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+       #else\r
+       ISR(WDT_vect) {\r
+       \r
+#endif \r
+       //sleep_disable();          // Disable Sleep on Wakeup\r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+/*     if (timeout==2) {\r
+               DIS_TIMER;\r
+               EN_OWINT;\r
+               mode=OWM_SLEEP;\r
+       }\r
+       timeout++;*/\r
+       //sleep_enable();           // Enable Sleep Mode\r
+\r
+}\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack1_t;\r
+volatile pack1_t pack1;\r
+\r
+\r
+\r
+typedef union {\r
+       #if  defined(__AVR_ATtiny25__)\r
+       volatile uint8_t bytes[16];\r
+       #else\r
+       volatile uint8_t bytes[64];\r
+       #endif\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               #if  defined(__AVR_ATtiny25__)\r
+               #else\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+               #endif\r
+       };\r
+} pack2_t;\r
+volatile pack2_t pack2;\r
+\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+int testSW(void) {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB|=(1<<PORTB0); //Pullup\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       r=PINB&(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB&=~(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+       \r
+       \r
+}\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+       uint32_t P;\r
+       int32_t t;\r
+\r
+int main(void){\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       PORTA=0xFF;\r
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+       \r
+       pack1.temp=0x0550;\r
+       pack1.config=0x7F;\r
+       pack1.TH=75;\r
+       pack1.TL=70;\r
+       pack1.rrFF=0xFF;\r
+       pack1.rr00=0;\r
+       pack1.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       //MCUCR &=~(1<<BODS);\r
+\r
+       \r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+       if (testSW()) {\r
+               config_info2[5]=8;\r
+               }else{\r
+               config_info2[5]=7;\r
+       }\r
+       \r
+\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       \r
+       SHT2x_SoftReset();\r
+       SHT2x_ReadUserRegister(userRegister);\r
+       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
+       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
+       // --- measure humidity with "Hold Master Mode (HM)" ---\r
+       //SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+       //SHT2x_MeasurePoll(TEMP, &sT);\r
+       //-- calculate humidity and temperature --\r
+       //temperatureC = SHT2x_CalcTemperatureC(sT);\r
+       //humidityRH = SHT2x_CalcRH(sRH);\r
+       bmp280Init();\r
+       gcontrol=1;\r
+       sei();\r
+    while(1)   {\r
+               if (gcontrol) {\r
+                       wdcounter=3;\r
+                       \r
+               }\r
+\r
+               if (wdcounter>2) {\r
+                       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+                       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+                       SHT2x_MeasurePoll(TEMP, &sT);\r
+                       //-- calculate humidity and temperature --\r
+                       temperatureC = SHT2x_CalcTemperatureC(sT);\r
+                       humidityRH = SHT2x_CalcRH(sRH);\r
+                       humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;\r
+                       temperatureC=temperatureC*10.0-4.5;\r
+                        if (testSW()) {\r
+                                am2302_hum= humidityRH*10.0;\r
+                                am2302_temp=temperatureC*25.6;\r
+                                am2302_temp=am2302_temp-20;\r
+                                config_info2[5]=8;\r
+                                \r
+                                }else{\r
+                                \r
+                                double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                                //am2302_hum=0.318*hhum +76.0;\r
+                                am2302_hum=0.31*hhum +80;\r
+                                am2302_temp=temperatureC*25.6;\r
+                                am2302_temp=am2302_temp-20;\r
+                                config_info2[5]=7;\r
+                        }\r
+                       wdcounter=0;\r
+               }\r
+       \r
+               if (gcontrol==1) {\r
+                       \r
+                               bmp280ConvertInt(&t,&P,1);\r
+                               P=P-70000;\r
+                               P=P/20;\r
+                               uint16_t w=P;\r
+                               uint8_t t8=w>>4;\r
+                               uint8_t af=0;\r
+                               if (t8>pack1.TH) af=1;\r
+                               if (t8<=pack1.TL) af=1;\r
+                               cli();\r
+                               pack1.temp=w;\r
+                               //pack.temp++;\r
+                               alarmflag=af;\r
+                               sei();\r
+                               gcontrol=0;\r
+                               EXTERN_SLEEP(); \r
+               }\r
+               if (gcontrol) {\r
+                       gcontrol=0;\r
+                       \r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               //MCUCR&=~(1<<ISC01);\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index bce8cd3..2f8dd6b 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_MAX44009", "DS18B20_MAX44009.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_MAX44009", "DS18B20_MAX44009.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 3447b6b..edf1be3 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX44009.h"
-
-
-extern void OWINIT();
-
-extern void EXTERN_SLEEP();
-
-
-uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/
-uint8_t config_info[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-uint8_t max_adr=0;
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-
-
-
-
-
-int main(void){
-    PRR|=(1<<PRADC);  // adc for save Power
-       pack.temp=0x0550;
-       pack.config=0x7F;
-       pack.TH=75;
-       pack.TL=70;
-       pack.rrFF=0xFF;
-       pack.rr00=0;
-       pack.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
-       
-       gcontrol=1;
-       //DDRB|=(1<<PINB1);
-       sei();
-    while(1)   {
-       
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1); //Dauer 2.3ms
-                       volatile double l=MAX44009getlux(max_adr);              
-                       if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
-                       //double l=1000;
-                       l=log(l)*10*16;
-                       uint16_t w=l;
-                       uint8_t t8=w>>4;
-                       uint8_t af=0;
-                       if (t8>pack.TH) af=1;
-                       if (t8<=pack.TL) af=1; 
-                       cli();
-                       pack.temp=w;
-                       //pack.temp++;
-                       alarmflag=af;
-                       sei();  
-                       EXTERN_SLEEP();         
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               //MCUCR&=~(1<<ISC01);
-               asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX44009.h"\r
+\r
+\r
+extern void OWINIT();\r
+\r
+extern void EXTERN_SLEEP();\r
+\r
+\r
+uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/\r
+uint8_t config_info[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+\r
+uint8_t max_adr=0;\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       pack.temp=0x0550;\r
+       pack.config=0x7F;\r
+       pack.TH=75;\r
+       pack.TL=70;\r
+       pack.rrFF=0xFF;\r
+       pack.rr00=0;\r
+       pack.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;\r
+       \r
+       gcontrol=1;\r
+       //DDRB|=(1<<PINB1);\r
+       sei();\r
+    while(1)   {\r
+       \r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1); //Dauer 2.3ms\r
+                       volatile double l=MAX44009getlux(max_adr);              \r
+                       if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045\r
+                       //double l=1000;\r
+                       l=log(l)*10*16;\r
+                       uint16_t w=l;\r
+                       uint8_t t8=w>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack.TH) af=1;\r
+                       if (t8<=pack.TL) af=1; \r
+                       cli();\r
+                       pack.temp=w;\r
+                       //pack.temp++;\r
+                       alarmflag=af;\r
+                       sei();  \r
+                       EXTERN_SLEEP();         \r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               //MCUCR&=~(1<<ISC01);\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 0eea7c8..6584971 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_MAX44009</AssemblyName>
-    <Name>DS18B20_MAX44009</Name>
-    <RootNamespace>DS18B20_MAX44009</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\OWDS18B20.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20.S</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">
-      <SubType>compile</SubType>
-      <Link>MAX44009.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="DS18B20_MAX44009.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_MAX44009</AssemblyName>\r
+    <Name>DS18B20_MAX44009</Name>\r
+    <RootNamespace>DS18B20_MAX44009</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\OWDS18B20.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20.S</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">\r
+      <SubType>compile</SubType>\r
+      <Link>MAX44009.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_MAX44009.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index affc509..f1d01be 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX44009.h"
-#include "../common/I2C/SHT2x.h"
-
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-
-uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
-uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
-uint8_t config_info1[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
-uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-volatile uint8_t wdcounter=5;
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       //sleep_disable();          // Disable Sleep on Wakeup
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-/*     if (timeout==2) {
-               DIS_TIMER;
-               EN_OWINT;
-               mode=OWM_SLEEP;
-       }
-       timeout++;*/
-       //sleep_enable();           // Enable Sleep Mode
-
-}
-
-int testSW(void) {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-       __asm__ __volatile__ ("nop");
-       PORTB|=(1<<PORTB0); //Pullup
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       r=PINB&(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       PORTB&=~(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-       
-       
-}
-
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack1_t;
-volatile pack1_t pack1;
-
-
-
-typedef union {
-       #if  defined(__AVR_ATtiny25__)
-       volatile uint8_t bytes[16];
-       #else
-       volatile uint8_t bytes[64];
-       #endif
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               #if  defined(__AVR_ATtiny25__)
-               #else
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-               #endif
-       };
-} pack2_t;
-volatile pack2_t pack2;
-
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-
-uint8_t max_adr=0;
-
-int main(void){
-    PRR|=(1<<PRADC);  // adc for save Power
-       pack1.temp=0x0550;
-       pack1.config=0x7F;
-       pack1.TH=75;
-       pack1.TL=70;
-       pack1.rrFF=0xFF;
-       pack1.rr00=0;
-       pack1.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-       if (testSW()) {
-               config_info2[5]=8;
-               }else{
-               config_info2[5]=7;
-       }
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
-       SHT2x_SoftReset();
-       SHT2x_ReadUserRegister(userRegister);
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg
-       // --- measure humidity with "Hold Master Mode (HM)" ---
-       SHT2x_MeasurePoll(HUMIDITY, &sRH);
-       // --- measure temperature with "Polling Mode" (no hold master) ---
-       SHT2x_MeasurePoll(TEMP, &sT);
-       //-- calculate humidity and temperature --
-       //temperatureC = SHT2x_CalcTemperatureC(sT);
-       //humidityRH = SHT2x_CalcRH(sRH);
-       
-       gcontrol=1;
-       sei();
-       //DDRB|=(1<<PINB1);
-    while(1)   {
-               if ((gcontrol==2)||(gcontrol==3)) {
-                       wdcounter=3;
-                       gcontrol=0;
-                       
-               }
-               
-               if (wdcounter>2) {
-                       //PORTB|=(1<<PINB1); //Dauer 440ms
-                       SHT2x_MeasurePoll(HUMIDITY, &sRH);
-                       // --- measure temperature with "Polling Mode" (no hold master) ---
-                       SHT2x_MeasurePoll(TEMP, &sT);
-                       //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0-4;
-                       humidityRH = SHT2x_CalcRH(sRH)*10.0+5;
-                       if (humidityRH>1000) humidityRH=1000;
-                       if (testSW()) {
-                               am2302_hum= humidityRH*10.0;
-                               am2302_temp=temperatureC*25.6;
-                               //
-                               config_info2[5]=8;
-                               
-                       }else{
-                               
-                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                               //am2302_hum=0.318*hhum +76.0;
-                               am2302_hum=0.31*hhum +80;
-                               am2302_temp=temperatureC*25.6;
-                               //am2302_temp=am2302_temp-45;
-                               config_info2[5]=7;
-                       }
-                       wdcounter=0;
-               }
-       
-               if (gcontrol==1) {
-                       gcontrol=0;
-                       l=MAX44009getlux(max_adr);              
-                       if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
-                       //double l=1000;
-                       l=log(l)*10*16;
-                       uint16_t w=l;
-                       uint8_t t8=w>>4;
-                       uint8_t af=0;
-                       if (t8>pack1.TH) af=1;
-                       if (t8<=pack1.TL) af=1; 
-                       cli();
-                       pack1.temp=w;
-                       //pack.temp++;
-                       alarmflag=af;
-                       sei();                  
-                       EXTERN_SLEEP();         
-               }
-               
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX44009.h"\r
+#include "../common/I2C/SHT2x.h"\r
+\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+\r
+uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/\r
+uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/\r
+uint8_t config_info1[16]={0x03,0x04, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        \r
+uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        \r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+volatile uint8_t wdcounter=5;\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       //sleep_disable();          // Disable Sleep on Wakeup\r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+/*     if (timeout==2) {\r
+               DIS_TIMER;\r
+               EN_OWINT;\r
+               mode=OWM_SLEEP;\r
+       }\r
+       timeout++;*/\r
+       //sleep_enable();           // Enable Sleep Mode\r
+\r
+}\r
+\r
+int testSW(void) {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB|=(1<<PORTB0); //Pullup\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       r=PINB&(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB&=~(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+       \r
+       \r
+}\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack1_t;\r
+volatile pack1_t pack1;\r
+\r
+\r
+\r
+typedef union {\r
+       #if  defined(__AVR_ATtiny25__)\r
+       volatile uint8_t bytes[16];\r
+       #else\r
+       volatile uint8_t bytes[64];\r
+       #endif\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               #if  defined(__AVR_ATtiny25__)\r
+               #else\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+               #endif\r
+       };\r
+} pack2_t;\r
+volatile pack2_t pack2;\r
+\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+\r
+uint8_t max_adr=0;\r
+\r
+int main(void){\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       pack1.temp=0x0550;\r
+       pack1.config=0x7F;\r
+       pack1.TH=75;\r
+       pack1.TL=70;\r
+       pack1.rrFF=0xFF;\r
+       pack1.rr00=0;\r
+       pack1.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+       if (testSW()) {\r
+               config_info2[5]=8;\r
+               }else{\r
+               config_info2[5]=7;\r
+       }\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;\r
+       SHT2x_SoftReset();\r
+       SHT2x_ReadUserRegister(userRegister);\r
+       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
+       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
+       // --- measure humidity with "Hold Master Mode (HM)" ---\r
+       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+       SHT2x_MeasurePoll(TEMP, &sT);\r
+       //-- calculate humidity and temperature --\r
+       //temperatureC = SHT2x_CalcTemperatureC(sT);\r
+       //humidityRH = SHT2x_CalcRH(sRH);\r
+       \r
+       gcontrol=1;\r
+       sei();\r
+       //DDRB|=(1<<PINB1);\r
+    while(1)   {\r
+               if ((gcontrol==2)||(gcontrol==3)) {\r
+                       wdcounter=3;\r
+                       gcontrol=0;\r
+                       \r
+               }\r
+               \r
+               if (wdcounter>2) {\r
+                       //PORTB|=(1<<PINB1); //Dauer 440ms\r
+                       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+                       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+                       SHT2x_MeasurePoll(TEMP, &sT);\r
+                       //-- calculate humidity and temperature --\r
+                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0-4;\r
+                       humidityRH = SHT2x_CalcRH(sRH)*10.0+5;\r
+                       if (humidityRH>1000) humidityRH=1000;\r
+                       if (testSW()) {\r
+                               am2302_hum= humidityRH*10.0;\r
+                               am2302_temp=temperatureC*25.6;\r
+                               //\r
+                               config_info2[5]=8;\r
+                               \r
+                       }else{\r
+                               \r
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                               //am2302_hum=0.318*hhum +76.0;\r
+                               am2302_hum=0.31*hhum +80;\r
+                               am2302_temp=temperatureC*25.6;\r
+                               //am2302_temp=am2302_temp-45;\r
+                               config_info2[5]=7;\r
+                       }\r
+                       wdcounter=0;\r
+               }\r
+       \r
+               if (gcontrol==1) {\r
+                       gcontrol=0;\r
+                       l=MAX44009getlux(max_adr);              \r
+                       if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045\r
+                       //double l=1000;\r
+                       l=log(l)*10*16;\r
+                       uint16_t w=l;\r
+                       uint8_t t8=w>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack1.TH) af=1;\r
+                       if (t8<=pack1.TL) af=1; \r
+                       cli();\r
+                       pack1.temp=w;\r
+                       //pack.temp++;\r
+                       alarmflag=af;\r
+                       sei();                  \r
+                       EXTERN_SLEEP();         \r
+               }\r
+               \r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 634f63e..7b401bf 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_MAX44009_DS2438_SHT", "DS18B20_MAX44009_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_MAX44009_DS2438_SHT", "DS18B20_MAX44009_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 913fe40..2bbe71c 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_DS2438</AssemblyName>
-    <Name>DS18B20_MAX44009_DS2438_SHT</Name>
-    <RootNamespace>DS18B20_DS2438</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\I2C\SHT2x.c">
-      <SubType>compile</SubType>
-      <Link>SHT2x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">
-      <SubType>compile</SubType>
-      <Link>MAX44009.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20_DS2438.S</Link>
-    </Compile>
-    <Compile Include="DS18B20_DS2438.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_DS2438</AssemblyName>\r
+    <Name>DS18B20_MAX44009_DS2438_SHT</Name>\r
+    <RootNamespace>DS18B20_DS2438</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\I2C\SHT2x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>SHT2x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">\r
+      <SubType>compile</SubType>\r
+      <Link>MAX44009.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20_DS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_DS2438.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 6bb479f..450474d 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_TC", "DS18B20_TC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_TC", "DS18B20_TC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 154b3e5..6ed9a03 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176};
-//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088};
-       double gettemp_rs(double V) {
-               uint8_t iv=(uint8_t)(V);
-               float t0=pgm_read_float(&(k_rs[iv]));
-               float t1=pgm_read_float(&(k_rs[iv+1]));
-               return t0+(t1-t0)/1*(V-iv);
-       }
-
-
-uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0xAC};/**/
-uint8_t config_info[16]={0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-volatile uint8_t wdcounter;
-
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       //sleep_disable();          // Disable Sleep on Wakeup
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-/*     if (timeout==2) {
-               DIS_TIMER;
-               EN_OWINT;
-               mode=OWM_SLEEP;
-       }
-       timeout++;*/
-       //sleep_enable();           // Enable Sleep Mode
-
-}
-
-
-#define OWM_PORT PORTA
-#define OWM_PIN PINA
-#define OWM_PINN PINA0
-#define OWM_DD DDRA
-
-#define OWM_SET_LOW OWM_PORT&=~(1<<OWM_PINN);OWM_DD|=(1<<OWM_PINN)
-#define OWM_SET_HIGH OWM_DD&=~(1<<OWM_PINN);OWM_PORT|=(1<<OWM_PINN)
-
-#define OWM_IS_LOW ((OWM_PIN & (1<<OWM_PINN))==0)
-
-
-void owm_init() {
-       OWM_PORT|=(1<<OWM_PINN); //PULL UP
-       OWM_DD&=~(1<<OWM_PINN);
-}
-
-#define owm_delay(us1)  _delay_us(us1)
-
-uint8_t owm_reset() {
-       OWM_SET_LOW;
-       owm_delay(480);
-       OWM_SET_HIGH;
-       owm_delay(60);
-       if (OWM_IS_LOW) {owm_delay(420); return 1;} else {owm_delay(420); return 0;}
-       
-       
-}
-
-void owm_rw(uint8_t *b) {
-       uint8_t i;
-       uint8_t pp=1;
-       for(i=0;i<8;i++) {
-               if (pp&b[0]) {
-                       OWM_SET_LOW;
-                       owm_delay(6);
-                       OWM_SET_HIGH;
-                       owm_delay(9);
-                       if (OWM_IS_LOW) {
-                               b[0]&=~pp;
-                       }
-                       owm_delay(80-6-9);
-                       
-                       } else {
-                       OWM_SET_LOW;
-                       owm_delay(60);
-                       OWM_SET_HIGH;
-                       owm_delay(20);
-               }
-               pp=(pp<<1);
-       }
-}
-
-void owm_block(uint8_t count, uint8_t *buf){
-       uint8_t i;
-       for(i=0;i<count;i++) {
-               owm_rw(buf+i);
-       }
-}
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176};\r
+//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088};\r
+       double gettemp_rs(double V) {\r
+               uint8_t iv=(uint8_t)(V);\r
+               float t0=pgm_read_float(&(k_rs[iv]));\r
+               float t1=pgm_read_float(&(k_rs[iv+1]));\r
+               return t0+(t1-t0)/1*(V-iv);\r
+       }\r
+\r
+\r
+uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0xAC};/**/\r
+uint8_t config_info[16]={0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       //sleep_disable();          // Disable Sleep on Wakeup\r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+/*     if (timeout==2) {\r
+               DIS_TIMER;\r
+               EN_OWINT;\r
+               mode=OWM_SLEEP;\r
+       }\r
+       timeout++;*/\r
+       //sleep_enable();           // Enable Sleep Mode\r
+\r
+}\r
+\r
+\r
+#define OWM_PORT PORTA\r
+#define OWM_PIN PINA\r
+#define OWM_PINN PINA0\r
+#define OWM_DD DDRA\r
+\r
+#define OWM_SET_LOW OWM_PORT&=~(1<<OWM_PINN);OWM_DD|=(1<<OWM_PINN)\r
+#define OWM_SET_HIGH OWM_DD&=~(1<<OWM_PINN);OWM_PORT|=(1<<OWM_PINN)\r
+\r
+#define OWM_IS_LOW ((OWM_PIN & (1<<OWM_PINN))==0)\r
+\r
+\r
+void owm_init() {\r
+       OWM_PORT|=(1<<OWM_PINN); //PULL UP\r
+       OWM_DD&=~(1<<OWM_PINN);\r
+}\r
+\r
+#define owm_delay(us1)  _delay_us(us1)\r
+\r
+uint8_t owm_reset() {\r
+       OWM_SET_LOW;\r
+       owm_delay(480);\r
+       OWM_SET_HIGH;\r
+       owm_delay(60);\r
+       if (OWM_IS_LOW) {owm_delay(420); return 1;} else {owm_delay(420); return 0;}\r
+       \r
+       \r
+}\r
+\r
+void owm_rw(uint8_t *b) {\r
+       uint8_t i;\r
+       uint8_t pp=1;\r
+       for(i=0;i<8;i++) {\r
+               if (pp&b[0]) {\r
+                       OWM_SET_LOW;\r
+                       owm_delay(6);\r
+                       OWM_SET_HIGH;\r
+                       owm_delay(9);\r
+                       if (OWM_IS_LOW) {\r
+                               b[0]&=~pp;\r
+                       }\r
+                       owm_delay(80-6-9);\r
+                       \r
+                       } else {\r
+                       OWM_SET_LOW;\r
+                       owm_delay(60);\r
+                       OWM_SET_HIGH;\r
+                       owm_delay(20);\r
+               }\r
+               pp=(pp<<1);\r
+       }\r
+}\r
+\r
+void owm_block(uint8_t count, uint8_t *buf){\r
+       uint8_t i;\r
+       for(i=0;i<count;i++) {\r
+               owm_rw(buf+i);\r
+       }\r
+}\r
+\r
 inline int16_t ow_fconvert(uint8_t b1, uint8_t b2) {
        int16_t tsht;
        tsht=b1  |((int)b2<<8);
        if (b2 & 0x080)
        tsht |= 0xFFFFF0000;
        return tsht;
-}
-volatile double V,ktemp;
-
-uint16_t ADmess() {
-        ADMUX=0b10001101;
-        ADCSRA|=(1<<ADSC);
-        while ((ADCSRA&(1<<ADSC)));
-       return ADC;
-}
-
-int main(void){
-    //PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
-       pack.temp=0x0550;
-       pack.config=0x7F;
-       pack.TH=75;
-       pack.TL=70;
-       pack.rrFF=0xFF;
-       pack.rr00=0;
-       pack.rr10=0x10;
-       PORTA=0xFF-(1<<PINA1)-(1<<PINA2);
-       PORTB=0xFF;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~1 seconds
-       MCUSR=0;
-       uint8_t block[13];
-       sei();
-       ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
-       owm_init();
-       owm_reset();
-       block[0]=0xCC;
-       block[1]=0x4E;
-       block[2]=0;
-       block[3]=0;
-       block[4]=0x1F;
-       owm_block(5,block);
-       owm_reset();
-       block[0]=0x33;
-       for(uint8_t i=1;i<9;i++) {
-               block[i]=0xFF;
-       }
-       owm_block(9,block);
-       
-       if (block[1]==0x28) {  //DS18B20 angeschlossen
-               for(uint8_t i=0;i<8;i++) {
-                       owid[i]=block[i+1];
-               }
-               while(EECR & (1<<EEPE));
-               EEAR=E2END-7;
-               EECR|=(1<EERE);
-               if (EEDR!=0x28) { //Wenn keine ID im Eeprom uebernimm es
-                       for(uint8_t a=0;a<8;a++) {
-                               while(EECR & (1<<EEPE));
-                               EECR = (0<<EEPM1)|(0<<EEPM0);
-                               EEAR = E2END-7+a;
-                               EEDR = block[a+1];
-                               EECR |= (1<<EEMPE);
-                               EECR |= (1<<EEPE);
-                       }
-               }
-       }
-       
-       uint16_t ares[16],sum;
-       uint8_t par=0;
-       ares[0]=0;//ADmess();
-       for (par=1;par<16;par++) {
-               ares[par]=ares[0];
-       }
-       par=0;
-       wdcounter=0;
-       gcontrol=1;
-
-    while(1)   {
-               if (wdcounter>0) {
-                       ares[par]=ADmess();
-                       par++;
-                       if (par>15) par=0;
-                       wdcounter=0;
-               }
-               if (gcontrol) {
-                       PORTB|=(1<<PORTB0);
-                       sum=0;
-                       for(uint8_t i=0;i<16;i++) {
-                               sum+=ares[i];
-                       }
-                       V=sum/20.0/1024.0*1.12*1000.0/16.0;
-                       //V=sum/20.0/1024.0*1.01*1000.0/16.0;
-                       ktemp=gettemp_rs(V);
-                       owm_reset();
-                       block[0]=0xCC;
-                       block[1]=0x44;
-                       owm_block(2,block);
-                       _delay_ms(100);
-                       owm_reset();
-                       block[0]=0xCC;
-                       block[1]=0xBE;
-                       for(uint8_t i=0;i<9;i++) block[i+2]=0xFF;
-                       owm_block(11,block);
-                       uint16_t htemp;
-                       if (PINB&(1<<PINB0)) {
-                               htemp=(ktemp*16+(block[2]|(block[3]<<8)))/10;
-                       } else {
-                               
-                               htemp=ktemp*16+(block[2]|(block[3]<<8));
-                       }
-                       uint8_t t8=pack.temp>>4;
-                       uint8_t af=0;
-                       if (t8>pack.TH) af=1;
-                       if (t8<=pack.TL) af=1;
-                       cli();
-                       pack.temp=htemp;
-                       alarmflag=af;
-                       sei();
-                       EXTERN_SLEEP();
-                       PORTB&=~(1<<PORTB0);
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-//                     CLKPR=(1<<CLKPCE);
-       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/
-//                     PORTB&=~(1<<PINB1);
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-   }
-
-
+}\r
+volatile double V,ktemp;\r
+\r
+uint16_t ADmess() {\r
+        ADMUX=0b10001101;\r
+        ADCSRA|=(1<<ADSC);\r
+        while ((ADCSRA&(1<<ADSC)));\r
+       return ADC;\r
+}\r
+\r
+int main(void){\r
+    //PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power\r
+       pack.temp=0x0550;\r
+       pack.config=0x7F;\r
+       pack.TH=75;\r
+       pack.TL=70;\r
+       pack.rrFF=0xFF;\r
+       pack.rr00=0;\r
+       pack.rr10=0x10;\r
+       PORTA=0xFF-(1<<PINA1)-(1<<PINA2);\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~1 seconds\r
+       MCUSR=0;\r
+       uint8_t block[13];\r
+       sei();\r
+       ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);\r
+       owm_init();\r
+       owm_reset();\r
+       block[0]=0xCC;\r
+       block[1]=0x4E;\r
+       block[2]=0;\r
+       block[3]=0;\r
+       block[4]=0x1F;\r
+       owm_block(5,block);\r
+       owm_reset();\r
+       block[0]=0x33;\r
+       for(uint8_t i=1;i<9;i++) {\r
+               block[i]=0xFF;\r
+       }\r
+       owm_block(9,block);\r
+       \r
+       if (block[1]==0x28) {  //DS18B20 angeschlossen\r
+               for(uint8_t i=0;i<8;i++) {\r
+                       owid[i]=block[i+1];\r
+               }\r
+               while(EECR & (1<<EEPE));\r
+               EEAR=E2END-7;\r
+               EECR|=(1<EERE);\r
+               if (EEDR!=0x28) { //Wenn keine ID im Eeprom uebernimm es\r
+                       for(uint8_t a=0;a<8;a++) {\r
+                               while(EECR & (1<<EEPE));\r
+                               EECR = (0<<EEPM1)|(0<<EEPM0);\r
+                               EEAR = E2END-7+a;\r
+                               EEDR = block[a+1];\r
+                               EECR |= (1<<EEMPE);\r
+                               EECR |= (1<<EEPE);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       uint16_t ares[16],sum;\r
+       uint8_t par=0;\r
+       ares[0]=0;//ADmess();\r
+       for (par=1;par<16;par++) {\r
+               ares[par]=ares[0];\r
+       }\r
+       par=0;\r
+       wdcounter=0;\r
+       gcontrol=1;\r
+\r
+    while(1)   {\r
+               if (wdcounter>0) {\r
+                       ares[par]=ADmess();\r
+                       par++;\r
+                       if (par>15) par=0;\r
+                       wdcounter=0;\r
+               }\r
+               if (gcontrol) {\r
+                       PORTB|=(1<<PORTB0);\r
+                       sum=0;\r
+                       for(uint8_t i=0;i<16;i++) {\r
+                               sum+=ares[i];\r
+                       }\r
+                       V=sum/20.0/1024.0*1.12*1000.0/16.0;\r
+                       //V=sum/20.0/1024.0*1.01*1000.0/16.0;\r
+                       ktemp=gettemp_rs(V);\r
+                       owm_reset();\r
+                       block[0]=0xCC;\r
+                       block[1]=0x44;\r
+                       owm_block(2,block);\r
+                       _delay_ms(100);\r
+                       owm_reset();\r
+                       block[0]=0xCC;\r
+                       block[1]=0xBE;\r
+                       for(uint8_t i=0;i<9;i++) block[i+2]=0xFF;\r
+                       owm_block(11,block);\r
+                       uint16_t htemp;\r
+                       if (PINB&(1<<PINB0)) {\r
+                               htemp=(ktemp*16+(block[2]|(block[3]<<8)))/10;\r
+                       } else {\r
+                               \r
+                               htemp=ktemp*16+(block[2]|(block[3]<<8));\r
+                       }\r
+                       uint8_t t8=pack.temp>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack.TH) af=1;\r
+                       if (t8<=pack.TL) af=1;\r
+                       cli();\r
+                       pack.temp=htemp;\r
+                       alarmflag=af;\r
+                       sei();\r
+                       EXTERN_SLEEP();\r
+                       PORTB&=~(1<<PORTB0);\r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+//                     CLKPR=(1<<CLKPCE);\r
+       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/\r
+//                     PORTB&=~(1<<PINB1);\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 21a38f9..32390b0 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_TC</AssemblyName>
-    <Name>DS18B20_TC</Name>
-    <RootNamespace>DS18B20_TC</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\OWDS18B20.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20.S</Link>
-    </Compile>
-    <Compile Include="DS18B20_TC.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_TC</AssemblyName>\r
+    <Name>DS18B20_TC</Name>\r
+    <RootNamespace>DS18B20_TC</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\OWDS18B20.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_TC.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index ca48831..4b3629e 100644 (file)
--210;-8.095;-8.076;-8.057;-8.037;-8.017;-7.996;-7.976;-7.955;-7.934;-7.912;-7.890
--200;-7.890;-7.868;-7.846;-7.824;-7.801;-7.778;-7.755;-7.731;-7.707;-7.683;-7.659
--190;-7.659;-7.634;-7.610;-7.585;-7.559;-7.534;-7.508;-7.482;-7.456;-7.429;-7.403
--180;-7.403;-7.376;-7.348;-7.321;-7.293;-7.265;-7.237;-7.209;-7.181;-7.152;-7.123
--170;-7.123;-7.094;-7.064;-7.035;-7.005;-6.975;-6.944;-6.914;-6.883;-6.853;-6.821
--160;-6.821;-6.790;-6.759;-6.727;-6.695;-6.663;-6.631;-6.598;-6.566;-6.533;-6.500
--150;-6.500;-6.467;-6.433;-6.400;-6.366;-6.332;-6.298;-6.263;-6.229;-6.194;-6.159
--140;-6.159;-6.124;-6.089;-6.054;-6.018;-5.982;-5.946;-5.910;-5.874;-5.838;-5.801
--130;-5.801;-5.764;-5.727;-5.690;-5.653;-5.616;-5.578;-5.541;-5.503;-5.465;-5.426
--120;-5.426;-5.388;-5.350;-5.311;-5.272;-5.233;-5.194;-5.155;-5.116;-5.076;-5.037
--110;-5.037;-4.997;-4.957;-4.917;-4.877;-4.836;-4.796;-4.755;-4.714;-4.674;-4.633
--100;-4.633;-4.591;-4.550;-4.509;-4.467;-4.425;-4.384;-4.342;-4.300;-4.257;-4.215
--90;-4.215;-4.173;-4.130;-4.088;-4.045;-4.002;-3.959;-3.916;-3.872;-3.829;-3.786
--80;-3.786;-3.742;-3.698;-3.654;-3.610;-3.566;-3.522;-3.478;-3.434;-3.389;-3.344
--70;-3.344;-3.300;-3.255;-3.210;-3.165;-3.120;-3.075;-3.029;-2.984;-2.938;-2.893
--60;-2.893;-2.847;-2.801;-2.755;-2.709;-2.663;-2.617;-2.571;-2.524;-2.478;-2.431
--50;-2.431;-2.385;-2.338;-2.291;-2.244;-2.197;-2.150;-2.103;-2.055;-2.008;-1.961
--40;-1.961;-1.913;-1.865;-1.818;-1.770;-1.722;-1.674;-1.626;-1.578;-1.530;-1.482
--30;-1.482;-1.433;-1.385;-1.336;-1.288;-1.239;-1.190;-1.142;-1.093;-1.044;-0.995
--20;-0.995;-0.946;-0.896;-0.847;-0.798;-0.749;-0.699;-0.650;-0.600;-0.550;-0.501
--10;-0.501;-0.451;-0.401;-0.351;-0.301;-0.251;-0.201;-0.151;-0.101;-0.050;0.000
-0;0.000;0.050;0.101;0.151;0.202;0.253;0.303;0.354;0.405;0.456;0.507
-10;0.507;0.558;0.609;0.660;0.711;0.762;0.814;0.865;0.916;0.968;1.019
-20;1.019;1.071;1.122;1.174;1.226;1.277;1.329;1.381;1.433;1.485;1.537
-30;1.537;1.589;1.641;1.693;1.745;1.797;1.849;1.902;1.954;2.006;2.059
-40;2.059;2.111;2.164;2.216;2.269;2.322;2.374;2.427;2.480;2.532;2.585
-50;2.585;2.638;2.691;2.744;2.797;2.850;2.903;2.956;3.009;3.062;3.116
-60;3.116;3.169;3.222;3.275;3.329;3.382;3.436;3.489;3.543;3.596;3.650
-70;3.650;3.703;3.757;3.810;3.864;3.918;3.971;4.025;4.079;4.133;4.187
-80;4.187;4.240;4.294;4.348;4.402;4.456;4.510;4.564;4.618;4.672;4.726
-90;4.726;4.781;4.835;4.889;4.943;4.997;5.052;5.106;5.160;5.215;5.269
-100;5.269;5.323;5.378;5.432;5.487;5.541;5.595;5.650;5.705;5.759;5.814
-110;5.814;5.868;5.923;5.977;6.032;6.087;6.141;6.196;6.251;6.306;6.360
-120;6.360;6.415;6.470;6.525;6.579;6.634;6.689;6.744;6.799;6.854;6.909
-130;6.909;6.964;7.019;7.074;7.129;7.184;7.239;7.294;7.349;7.404;7.459
-140;7.459;7.514;7.569;7.624;7.679;7.734;7.789;7.844;7.900;7.955;8.010
-150;8.010;8.065;8.120;8.175;8.231;8.286;8.341;8.396;8.452;8.507;8.562
-160;8.562;8.618;8.673;8.728;8.783;8.839;8.894;8.949;9.005;9.060;9.115
-170;9.115;9.171;9.226;9.282;9.337;9.392;9.448;9.503;9.559;9.614;9.669
-180;9.669;9.725;9.780;9.836;9.891;9.947;10.002;10.057;10.113;10.168;10.224
-190;10.224;10.279;10.335;10.390;10.446;10.501;10.557;10.612;10.668;10.723;10.779
-200;10.779;10.834;10.890;10.945;11.001;11.056;11.112;11.167;11.223;11.278;11.334
-210;11.334;11.389;11.445;11.501;11.556;11.612;11.667;11.723;11.778;11.834;11.889
-220;11.889;11.945;12.000;12.056;12.111;12.167;12.222;12.278;12.334;12.389;12.445
-230;12.445;12.500;12.556;12.611;12.667;12.722;12.778;12.833;12.889;12.944;13.000
-240;13.000;13.056;13.111;13.167;13.222;13.278;13.333;13.389;13.444;13.500;13.555
-250;13.555;13.611;13.666;13.722;13.777;13.833;13.888;13.944;13.999;14.055;14.110
-260;14.110;14.166;14.221;14.277;14.332;14.388;14.443;14.499;14.554;14.609;14.665
-270;14.665;14.720;14.776;14.831;14.887;14.942;14.998;15.053;15.109;15.164;15.219
-280;15.219;15.275;15.330;15.386;15.441;15.496;15.552;15.607;15.663;15.718;15.773
-290;15.773;15.829;15.884;15.940;15.995;16.050;16.106;16.161;16.216;16.272;16.327
-300;16.327;16.383;16.438;16.493;16.549;16.604;16.659;16.715;16.770;16.825;16.881
-310;16.881;16.936;16.991;17.046;17.102;17.157;17.212;17.268;17.323;17.378;17.434
-320;17.434;17.489;17.544;17.599;17.655;17.710;17.765;17.820;17.876;17.931;17.986
-330;17.986;18.041;18.097;18.152;18.207;18.262;18.318;18.373;18.428;18.483;18.538
-340;18.538;18.594;18.649;18.704;18.759;18.814;18.870;18.925;18.980;19.035;19.090
-350;19.090;19.146;19.201;19.256;19.311;19.366;19.422;19.477;19.532;19.587;19.642
-360;19.642;19.697;19.753;19.808;19.863;19.918;19.973;20.028;20.083;20.139;20.194
-370;20.194;20.249;20.304;20.359;20.414;20.469;20.525;20.580;20.635;20.690;20.745
-380;20.745;20.800;20.855;20.911;20.966;21.021;21.076;21.131;21.186;21.241;21.297
-390;21.297;21.352;21.407;21.462;21.517;21.572;21.627;21.683;21.738;21.793;21.848
-400;21.848;21.903;21.958;22.014;22.069;22.124;22.179;22.234;22.289;22.345;22.400
-410;22.400;22.455;22.510;22.565;22.620;22.676;22.731;22.786;22.841;22.896;22.952
-420;22.952;23.007;23.062;23.117;23.172;23.228;23.283;23.338;23.393;23.449;23.504
-430;23.504;23.559;23.614;23.670;23.725;23.780;23.835;23.891;23.946;24.001;24.057
-440;24.057;24.112;24.167;24.223;24.278;24.333;24.389;24.444;24.499;24.555;24.610
-450;24.610;24.665;24.721;24.776;24.832;24.887;24.943;24.998;25.053;25.109;25.164
-460;25.164;25.220;25.275;25.331;25.386;25.442;25.497;25.553;25.608;25.664;25.720
-470;25.720;25.775;25.831;25.886;25.942;25.998;26.053;26.109;26.165;26.220;26.276
-480;26.276;26.332;26.387;26.443;26.499;26.555;26.610;26.666;26.722;26.778;26.834
-490;26.834;26.889;26.945;27.001;27.057;27.113;27.169;27.225;27.281;27.337;27.393
-500;27.393;27.449;27.505;27.561;27.617;27.673;27.729;27.785;27.841;27.897;27.953
-510;27.953;28.010;28.066;28.122;28.178;28.234;28.291;28.347;28.403;28.460;28.516
-520;28.516;28.572;28.629;28.685;28.741;28.798;28.854;28.911;28.967;29.024;29.080
-530;29.080;29.137;29.194;29.250;29.307;29.363;29.420;29.477;29.534;29.590;29.647
-540;29.647;29.704;29.761;29.818;29.874;29.931;29.988;30.045;30.102;30.159;30.216
-550;30.216;30.273;30.330;30.387;30.444;30.502;30.559;30.616;30.673;30.730;30.788
-560;30.788;30.845;30.902;30.960;31.017;31.074;31.132;31.189;31.247;31.304;31.362
-570;31.362;31.419;31.477;31.535;31.592;31.650;31.708;31.766;31.823;31.881;31.939
-580;31.939;31.997;32.055;32.113;32.171;32.229;32.287;32.345;32.403;32.461;32.519
-590;32.519;32.577;32.636;32.694;32.752;32.810;32.869;32.927;32.985;33.044;33.102
-600;33.102;33.161;33.219;33.278;33.337;33.395;33.454;33.513;33.571;33.630;33.689
-610;33.689;33.748;33.807;33.866;33.925;33.984;34.043;34.102;34.161;34.220;34.279
-620;34.279;34.338;34.397;34.457;34.516;34.575;34.635;34.694;34.754;34.813;34.873
-630;34.873;34.932;34.992;35.051;35.111;35.171;35.230;35.290;35.350;35.410;35.470
-640;35.470;35.530;35.590;35.650;35.710;35.770;35.830;35.890;35.950;36.010;36.071
-650;36.071;36.131;36.191;36.252;36.312;36.373;36.433;36.494;36.554;36.615;36.675
-660;36.675;36.736;36.797;36.858;36.918;36.979;37.040;37.101;37.162;37.223;37.284
-670;37.284;37.345;37.406;37.467;37.528;37.590;37.651;37.712;37.773;37.835;37.896
-680;37.896;37.958;38.019;38.081;38.142;38.204;38.265;38.327;38.389;38.450;38.512
-690;38.512;38.574;38.636;38.698;38.760;38.822;38.884;38.946;39.008;39.070;39.132
-700;39.132;39.194;39.256;39.318;39.381;39.443;39.505;39.568;39.630;39.693;39.755
-710;39.755;39.818;39.880;39.943;40.005;40.068;40.131;40.193;40.256;40.319;40.382
-720;40.382;40.445;40.508;40.570;40.633;40.696;40.759;40.822;40.886;40.949;41.012
-730;41.012;41.075;41.138;41.201;41.265;41.328;41.391;41.455;41.518;41.581;41.645
-740;41.645;41.708;41.772;41.835;41.899;41.962;42.026;42.090;42.153;42.217;42.281
-750;42.281;42.344;42.408;42.472;42.536;42.599;42.663;42.727;42.791;42.855;42.919
-760;42.919;42.983;43.047;43.111;43.175;43.239;43.303;43.367;43.431;43.495;43.559
-770;43.559;43.624;43.688;43.752;43.817;43.881;43.945;44.010;44.074;44.139;44.203
-780;44.203;44.267;44.332;44.396;44.461;44.525;44.590;44.655;44.719;44.784;44.848
-790;44.848;44.913;44.977;45.042;45.107;45.171;45.236;45.301;45.365;45.430;45.494
-800;45.494;45.559;45.624;45.688;45.753;45.818;45.882;45.947;46.011;46.076;46.141
-810;46.141;46.205;46.270;46.334;46.399;46.464;46.528;46.593;46.657;46.722;46.786
-820;46.786;46.851;46.915;46.980;47.044;47.109;47.173;47.238;47.302;47.367;47.431
-830;47.431;47.495;47.560;47.624;47.688;47.753;47.817;47.881;47.946;48.010;48.074
-840;48.074;48.138;48.202;48.267;48.331;48.395;48.459;48.523;48.587;48.651;48.715
-850;48.715;48.779;48.843;48.907;48.971;49.034;49.098;49.162;49.226;49.290;49.353
-860;49.353;49.417;49.481;49.544;49.608;49.672;49.735;49.799;49.862;49.926;49.989
-870;49.989;50.052;50.116;50.179;50.243;50.306;50.369;50.432;50.495;50.559;50.622
-880;50.622;50.685;50.748;50.811;50.874;50.937;51.000;51.063;51.126;51.188;51.251
-890;51.251;51.314;51.377;51.439;51.502;51.565;51.627;51.690;51.752;51.815;51.877
-900;51.877;51.940;52.002;52.064;52.127;52.189;52.251;52.314;52.376;52.438;52.500
-910;52.500;52.562;52.624;52.686;52.748;52.810;52.872;52.934;52.996;53.057;53.119
-920;53.119;53.181;53.243;53.304;53.366;53.427;53.489;53.550;53.612;53.673;53.735
-930;53.735;53.796;53.857;53.919;53.980;54.041;54.102;54.164;54.225;54.286;54.347
-940;54.347;54.408;54.469;54.530;54.591;54.652;54.713;54.773;54.834;54.895;54.956
-950;54.956;55.016;55.077;55.138;55.198;55.259;55.319;55.380;55.440;55.501;55.561
-960;55.561;55.622;55.682;55.742;55.803;55.863;55.923;55.983;56.043;56.104;56.164
-970;56.164;56.224;56.284;56.344;56.404;56.464;56.524;56.584;56.643;56.703;56.763
-980;56.763;56.823;56.883;56.942;57.002;57.062;57.121;57.181;57.240;57.300;57.360
-990;57.360;57.419;57.479;57.538;57.597;57.657;57.716;57.776;57.835;57.894;57.953
-1000;57.953;58.013;58.072;58.131;58.190;58.249;58.309;58.368;58.427;58.486;58.545
-1010;58.545;58.604;58.663;58.722;58.781;58.840;58.899;58.957;59.016;59.075;59.134
-1020;59.134;59.193;59.252;59.310;59.369;59.428;59.487;59.545;59.604;59.663;59.721
-1030;59.721;59.780;59.838;59.897;59.956;60.014;60.073;60.131;60.190;60.248;60.307
-1040;60.307;60.365;60.423;60.482;60.540;60.599;60.657;60.715;60.774;60.832;60.890
-1050;60.890;60.949;61.007;61.065;61.123;61.182;61.240;61.298;61.356;61.415;61.473
-1060;61.473;61.531;61.589;61.647;61.705;61.763;61.822;61.880;61.938;61.996;62.054
-1070;62.054;62.112;62.170;62.228;62.286;62.344;62.402;62.460;62.518;62.576;62.634
-1080;62.634;62.692;62.750;62.808;62.866;62.924;62.982;63.040;63.098;63.156;63.214
-1090;63.214;63.271;63.329;63.387;63.445;63.503;63.561;63.619;63.677;63.734;63.792
-1100;63.792;63.850;63.908;63.966;64.024;64.081;64.139;64.197;64.255;64.313;64.370
-1110;64.370;64.428;64.486;64.544;64.602;64.659;64.717;64.775;64.833;64.890;64.948
-1120;64.948;65.006;65.064;65.121;65.179;65.237;65.295;65.352;65.410;65.468;65.525
-1130;65.525;65.583;65.641;65.699;65.756;65.814;65.872;65.929;65.987;66.045;66.102
-1140;66.102;66.160;66.218;66.275;66.333;66.391;66.448;66.506;66.564;66.621;66.679
-1150;66.679;66.737;66.794;66.852;66.910;66.967;67.025;67.082;67.140;67.198;67.255
-1160;67.255;67.313;67.370;67.428;67.486;67.543;67.601;67.658;67.716;67.773;67.831
-1170;67.831;67.888;67.946;68.003;68.061;68.119;68.176;68.234;68.291;68.348;68.406
-1180;68.406;68.463;68.521;68.578;68.636;68.693;68.751;68.808;68.865;68.923;68.980
-1190;68.980;69.037;69.095;69.152;69.209;69.267;69.324;69.381;69.439;69.496;69.553
+-210;-8.095;-8.076;-8.057;-8.037;-8.017;-7.996;-7.976;-7.955;-7.934;-7.912;-7.890\r
+-200;-7.890;-7.868;-7.846;-7.824;-7.801;-7.778;-7.755;-7.731;-7.707;-7.683;-7.659\r
+-190;-7.659;-7.634;-7.610;-7.585;-7.559;-7.534;-7.508;-7.482;-7.456;-7.429;-7.403\r
+-180;-7.403;-7.376;-7.348;-7.321;-7.293;-7.265;-7.237;-7.209;-7.181;-7.152;-7.123\r
+-170;-7.123;-7.094;-7.064;-7.035;-7.005;-6.975;-6.944;-6.914;-6.883;-6.853;-6.821\r
+-160;-6.821;-6.790;-6.759;-6.727;-6.695;-6.663;-6.631;-6.598;-6.566;-6.533;-6.500\r
+-150;-6.500;-6.467;-6.433;-6.400;-6.366;-6.332;-6.298;-6.263;-6.229;-6.194;-6.159\r
+-140;-6.159;-6.124;-6.089;-6.054;-6.018;-5.982;-5.946;-5.910;-5.874;-5.838;-5.801\r
+-130;-5.801;-5.764;-5.727;-5.690;-5.653;-5.616;-5.578;-5.541;-5.503;-5.465;-5.426\r
+-120;-5.426;-5.388;-5.350;-5.311;-5.272;-5.233;-5.194;-5.155;-5.116;-5.076;-5.037\r
+-110;-5.037;-4.997;-4.957;-4.917;-4.877;-4.836;-4.796;-4.755;-4.714;-4.674;-4.633\r
+-100;-4.633;-4.591;-4.550;-4.509;-4.467;-4.425;-4.384;-4.342;-4.300;-4.257;-4.215\r
+-90;-4.215;-4.173;-4.130;-4.088;-4.045;-4.002;-3.959;-3.916;-3.872;-3.829;-3.786\r
+-80;-3.786;-3.742;-3.698;-3.654;-3.610;-3.566;-3.522;-3.478;-3.434;-3.389;-3.344\r
+-70;-3.344;-3.300;-3.255;-3.210;-3.165;-3.120;-3.075;-3.029;-2.984;-2.938;-2.893\r
+-60;-2.893;-2.847;-2.801;-2.755;-2.709;-2.663;-2.617;-2.571;-2.524;-2.478;-2.431\r
+-50;-2.431;-2.385;-2.338;-2.291;-2.244;-2.197;-2.150;-2.103;-2.055;-2.008;-1.961\r
+-40;-1.961;-1.913;-1.865;-1.818;-1.770;-1.722;-1.674;-1.626;-1.578;-1.530;-1.482\r
+-30;-1.482;-1.433;-1.385;-1.336;-1.288;-1.239;-1.190;-1.142;-1.093;-1.044;-0.995\r
+-20;-0.995;-0.946;-0.896;-0.847;-0.798;-0.749;-0.699;-0.650;-0.600;-0.550;-0.501\r
+-10;-0.501;-0.451;-0.401;-0.351;-0.301;-0.251;-0.201;-0.151;-0.101;-0.050;0.000\r
+0;0.000;0.050;0.101;0.151;0.202;0.253;0.303;0.354;0.405;0.456;0.507\r
+10;0.507;0.558;0.609;0.660;0.711;0.762;0.814;0.865;0.916;0.968;1.019\r
+20;1.019;1.071;1.122;1.174;1.226;1.277;1.329;1.381;1.433;1.485;1.537\r
+30;1.537;1.589;1.641;1.693;1.745;1.797;1.849;1.902;1.954;2.006;2.059\r
+40;2.059;2.111;2.164;2.216;2.269;2.322;2.374;2.427;2.480;2.532;2.585\r
+50;2.585;2.638;2.691;2.744;2.797;2.850;2.903;2.956;3.009;3.062;3.116\r
+60;3.116;3.169;3.222;3.275;3.329;3.382;3.436;3.489;3.543;3.596;3.650\r
+70;3.650;3.703;3.757;3.810;3.864;3.918;3.971;4.025;4.079;4.133;4.187\r
+80;4.187;4.240;4.294;4.348;4.402;4.456;4.510;4.564;4.618;4.672;4.726\r
+90;4.726;4.781;4.835;4.889;4.943;4.997;5.052;5.106;5.160;5.215;5.269\r
+100;5.269;5.323;5.378;5.432;5.487;5.541;5.595;5.650;5.705;5.759;5.814\r
+110;5.814;5.868;5.923;5.977;6.032;6.087;6.141;6.196;6.251;6.306;6.360\r
+120;6.360;6.415;6.470;6.525;6.579;6.634;6.689;6.744;6.799;6.854;6.909\r
+130;6.909;6.964;7.019;7.074;7.129;7.184;7.239;7.294;7.349;7.404;7.459\r
+140;7.459;7.514;7.569;7.624;7.679;7.734;7.789;7.844;7.900;7.955;8.010\r
+150;8.010;8.065;8.120;8.175;8.231;8.286;8.341;8.396;8.452;8.507;8.562\r
+160;8.562;8.618;8.673;8.728;8.783;8.839;8.894;8.949;9.005;9.060;9.115\r
+170;9.115;9.171;9.226;9.282;9.337;9.392;9.448;9.503;9.559;9.614;9.669\r
+180;9.669;9.725;9.780;9.836;9.891;9.947;10.002;10.057;10.113;10.168;10.224\r
+190;10.224;10.279;10.335;10.390;10.446;10.501;10.557;10.612;10.668;10.723;10.779\r
+200;10.779;10.834;10.890;10.945;11.001;11.056;11.112;11.167;11.223;11.278;11.334\r
+210;11.334;11.389;11.445;11.501;11.556;11.612;11.667;11.723;11.778;11.834;11.889\r
+220;11.889;11.945;12.000;12.056;12.111;12.167;12.222;12.278;12.334;12.389;12.445\r
+230;12.445;12.500;12.556;12.611;12.667;12.722;12.778;12.833;12.889;12.944;13.000\r
+240;13.000;13.056;13.111;13.167;13.222;13.278;13.333;13.389;13.444;13.500;13.555\r
+250;13.555;13.611;13.666;13.722;13.777;13.833;13.888;13.944;13.999;14.055;14.110\r
+260;14.110;14.166;14.221;14.277;14.332;14.388;14.443;14.499;14.554;14.609;14.665\r
+270;14.665;14.720;14.776;14.831;14.887;14.942;14.998;15.053;15.109;15.164;15.219\r
+280;15.219;15.275;15.330;15.386;15.441;15.496;15.552;15.607;15.663;15.718;15.773\r
+290;15.773;15.829;15.884;15.940;15.995;16.050;16.106;16.161;16.216;16.272;16.327\r
+300;16.327;16.383;16.438;16.493;16.549;16.604;16.659;16.715;16.770;16.825;16.881\r
+310;16.881;16.936;16.991;17.046;17.102;17.157;17.212;17.268;17.323;17.378;17.434\r
+320;17.434;17.489;17.544;17.599;17.655;17.710;17.765;17.820;17.876;17.931;17.986\r
+330;17.986;18.041;18.097;18.152;18.207;18.262;18.318;18.373;18.428;18.483;18.538\r
+340;18.538;18.594;18.649;18.704;18.759;18.814;18.870;18.925;18.980;19.035;19.090\r
+350;19.090;19.146;19.201;19.256;19.311;19.366;19.422;19.477;19.532;19.587;19.642\r
+360;19.642;19.697;19.753;19.808;19.863;19.918;19.973;20.028;20.083;20.139;20.194\r
+370;20.194;20.249;20.304;20.359;20.414;20.469;20.525;20.580;20.635;20.690;20.745\r
+380;20.745;20.800;20.855;20.911;20.966;21.021;21.076;21.131;21.186;21.241;21.297\r
+390;21.297;21.352;21.407;21.462;21.517;21.572;21.627;21.683;21.738;21.793;21.848\r
+400;21.848;21.903;21.958;22.014;22.069;22.124;22.179;22.234;22.289;22.345;22.400\r
+410;22.400;22.455;22.510;22.565;22.620;22.676;22.731;22.786;22.841;22.896;22.952\r
+420;22.952;23.007;23.062;23.117;23.172;23.228;23.283;23.338;23.393;23.449;23.504\r
+430;23.504;23.559;23.614;23.670;23.725;23.780;23.835;23.891;23.946;24.001;24.057\r
+440;24.057;24.112;24.167;24.223;24.278;24.333;24.389;24.444;24.499;24.555;24.610\r
+450;24.610;24.665;24.721;24.776;24.832;24.887;24.943;24.998;25.053;25.109;25.164\r
+460;25.164;25.220;25.275;25.331;25.386;25.442;25.497;25.553;25.608;25.664;25.720\r
+470;25.720;25.775;25.831;25.886;25.942;25.998;26.053;26.109;26.165;26.220;26.276\r
+480;26.276;26.332;26.387;26.443;26.499;26.555;26.610;26.666;26.722;26.778;26.834\r
+490;26.834;26.889;26.945;27.001;27.057;27.113;27.169;27.225;27.281;27.337;27.393\r
+500;27.393;27.449;27.505;27.561;27.617;27.673;27.729;27.785;27.841;27.897;27.953\r
+510;27.953;28.010;28.066;28.122;28.178;28.234;28.291;28.347;28.403;28.460;28.516\r
+520;28.516;28.572;28.629;28.685;28.741;28.798;28.854;28.911;28.967;29.024;29.080\r
+530;29.080;29.137;29.194;29.250;29.307;29.363;29.420;29.477;29.534;29.590;29.647\r
+540;29.647;29.704;29.761;29.818;29.874;29.931;29.988;30.045;30.102;30.159;30.216\r
+550;30.216;30.273;30.330;30.387;30.444;30.502;30.559;30.616;30.673;30.730;30.788\r
+560;30.788;30.845;30.902;30.960;31.017;31.074;31.132;31.189;31.247;31.304;31.362\r
+570;31.362;31.419;31.477;31.535;31.592;31.650;31.708;31.766;31.823;31.881;31.939\r
+580;31.939;31.997;32.055;32.113;32.171;32.229;32.287;32.345;32.403;32.461;32.519\r
+590;32.519;32.577;32.636;32.694;32.752;32.810;32.869;32.927;32.985;33.044;33.102\r
+600;33.102;33.161;33.219;33.278;33.337;33.395;33.454;33.513;33.571;33.630;33.689\r
+610;33.689;33.748;33.807;33.866;33.925;33.984;34.043;34.102;34.161;34.220;34.279\r
+620;34.279;34.338;34.397;34.457;34.516;34.575;34.635;34.694;34.754;34.813;34.873\r
+630;34.873;34.932;34.992;35.051;35.111;35.171;35.230;35.290;35.350;35.410;35.470\r
+640;35.470;35.530;35.590;35.650;35.710;35.770;35.830;35.890;35.950;36.010;36.071\r
+650;36.071;36.131;36.191;36.252;36.312;36.373;36.433;36.494;36.554;36.615;36.675\r
+660;36.675;36.736;36.797;36.858;36.918;36.979;37.040;37.101;37.162;37.223;37.284\r
+670;37.284;37.345;37.406;37.467;37.528;37.590;37.651;37.712;37.773;37.835;37.896\r
+680;37.896;37.958;38.019;38.081;38.142;38.204;38.265;38.327;38.389;38.450;38.512\r
+690;38.512;38.574;38.636;38.698;38.760;38.822;38.884;38.946;39.008;39.070;39.132\r
+700;39.132;39.194;39.256;39.318;39.381;39.443;39.505;39.568;39.630;39.693;39.755\r
+710;39.755;39.818;39.880;39.943;40.005;40.068;40.131;40.193;40.256;40.319;40.382\r
+720;40.382;40.445;40.508;40.570;40.633;40.696;40.759;40.822;40.886;40.949;41.012\r
+730;41.012;41.075;41.138;41.201;41.265;41.328;41.391;41.455;41.518;41.581;41.645\r
+740;41.645;41.708;41.772;41.835;41.899;41.962;42.026;42.090;42.153;42.217;42.281\r
+750;42.281;42.344;42.408;42.472;42.536;42.599;42.663;42.727;42.791;42.855;42.919\r
+760;42.919;42.983;43.047;43.111;43.175;43.239;43.303;43.367;43.431;43.495;43.559\r
+770;43.559;43.624;43.688;43.752;43.817;43.881;43.945;44.010;44.074;44.139;44.203\r
+780;44.203;44.267;44.332;44.396;44.461;44.525;44.590;44.655;44.719;44.784;44.848\r
+790;44.848;44.913;44.977;45.042;45.107;45.171;45.236;45.301;45.365;45.430;45.494\r
+800;45.494;45.559;45.624;45.688;45.753;45.818;45.882;45.947;46.011;46.076;46.141\r
+810;46.141;46.205;46.270;46.334;46.399;46.464;46.528;46.593;46.657;46.722;46.786\r
+820;46.786;46.851;46.915;46.980;47.044;47.109;47.173;47.238;47.302;47.367;47.431\r
+830;47.431;47.495;47.560;47.624;47.688;47.753;47.817;47.881;47.946;48.010;48.074\r
+840;48.074;48.138;48.202;48.267;48.331;48.395;48.459;48.523;48.587;48.651;48.715\r
+850;48.715;48.779;48.843;48.907;48.971;49.034;49.098;49.162;49.226;49.290;49.353\r
+860;49.353;49.417;49.481;49.544;49.608;49.672;49.735;49.799;49.862;49.926;49.989\r
+870;49.989;50.052;50.116;50.179;50.243;50.306;50.369;50.432;50.495;50.559;50.622\r
+880;50.622;50.685;50.748;50.811;50.874;50.937;51.000;51.063;51.126;51.188;51.251\r
+890;51.251;51.314;51.377;51.439;51.502;51.565;51.627;51.690;51.752;51.815;51.877\r
+900;51.877;51.940;52.002;52.064;52.127;52.189;52.251;52.314;52.376;52.438;52.500\r
+910;52.500;52.562;52.624;52.686;52.748;52.810;52.872;52.934;52.996;53.057;53.119\r
+920;53.119;53.181;53.243;53.304;53.366;53.427;53.489;53.550;53.612;53.673;53.735\r
+930;53.735;53.796;53.857;53.919;53.980;54.041;54.102;54.164;54.225;54.286;54.347\r
+940;54.347;54.408;54.469;54.530;54.591;54.652;54.713;54.773;54.834;54.895;54.956\r
+950;54.956;55.016;55.077;55.138;55.198;55.259;55.319;55.380;55.440;55.501;55.561\r
+960;55.561;55.622;55.682;55.742;55.803;55.863;55.923;55.983;56.043;56.104;56.164\r
+970;56.164;56.224;56.284;56.344;56.404;56.464;56.524;56.584;56.643;56.703;56.763\r
+980;56.763;56.823;56.883;56.942;57.002;57.062;57.121;57.181;57.240;57.300;57.360\r
+990;57.360;57.419;57.479;57.538;57.597;57.657;57.716;57.776;57.835;57.894;57.953\r
+1000;57.953;58.013;58.072;58.131;58.190;58.249;58.309;58.368;58.427;58.486;58.545\r
+1010;58.545;58.604;58.663;58.722;58.781;58.840;58.899;58.957;59.016;59.075;59.134\r
+1020;59.134;59.193;59.252;59.310;59.369;59.428;59.487;59.545;59.604;59.663;59.721\r
+1030;59.721;59.780;59.838;59.897;59.956;60.014;60.073;60.131;60.190;60.248;60.307\r
+1040;60.307;60.365;60.423;60.482;60.540;60.599;60.657;60.715;60.774;60.832;60.890\r
+1050;60.890;60.949;61.007;61.065;61.123;61.182;61.240;61.298;61.356;61.415;61.473\r
+1060;61.473;61.531;61.589;61.647;61.705;61.763;61.822;61.880;61.938;61.996;62.054\r
+1070;62.054;62.112;62.170;62.228;62.286;62.344;62.402;62.460;62.518;62.576;62.634\r
+1080;62.634;62.692;62.750;62.808;62.866;62.924;62.982;63.040;63.098;63.156;63.214\r
+1090;63.214;63.271;63.329;63.387;63.445;63.503;63.561;63.619;63.677;63.734;63.792\r
+1100;63.792;63.850;63.908;63.966;64.024;64.081;64.139;64.197;64.255;64.313;64.370\r
+1110;64.370;64.428;64.486;64.544;64.602;64.659;64.717;64.775;64.833;64.890;64.948\r
+1120;64.948;65.006;65.064;65.121;65.179;65.237;65.295;65.352;65.410;65.468;65.525\r
+1130;65.525;65.583;65.641;65.699;65.756;65.814;65.872;65.929;65.987;66.045;66.102\r
+1140;66.102;66.160;66.218;66.275;66.333;66.391;66.448;66.506;66.564;66.621;66.679\r
+1150;66.679;66.737;66.794;66.852;66.910;66.967;67.025;67.082;67.140;67.198;67.255\r
+1160;67.255;67.313;67.370;67.428;67.486;67.543;67.601;67.658;67.716;67.773;67.831\r
+1170;67.831;67.888;67.946;68.003;68.061;68.119;68.176;68.234;68.291;68.348;68.406\r
+1180;68.406;68.463;68.521;68.578;68.636;68.693;68.751;68.808;68.865;68.923;68.980\r
+1190;68.980;69.037;69.095;69.152;69.209;69.267;69.324;69.381;69.439;69.496;69.553\r
index 79f65ef..c11c3dd 100644 (file)
@@ -1,31 +1,31 @@
-fi=open("Typ-J.csv","r")
-lastv=0
-v=0
-lastt=0
-t=0
-rs=""
-wc=0
-for l in fi.readlines():
-       #print(l)
-       ll=l.split(";")
-       i=0
-       for n in ll[1:10]:
-               s=ll[0]+"."+str(i)
-               lastv=v
-               lastt=t
-               v=float(n)
-               t=float(s)
-               if (int(v)!=int(lastv)):
-                       interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv)
-                       print int(v),interp
-                       rs=rs+", %f" %(interp)
-                       wc=wc+1
-               if (v==0):
-                       interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv)
-                       print int(v),interp
-                       rs="{0"
-                       wc=1
-                       
-               i=i+1
-print rs+"};"
+fi=open("Typ-J.csv","r")\r
+lastv=0\r
+v=0\r
+lastt=0\r
+t=0\r
+rs=""\r
+wc=0\r
+for l in fi.readlines():\r
+       #print(l)\r
+       ll=l.split(";")\r
+       i=0\r
+       for n in ll[1:10]:\r
+               s=ll[0]+"."+str(i)\r
+               lastv=v\r
+               lastt=t\r
+               v=float(n)\r
+               t=float(s)\r
+               if (int(v)!=int(lastv)):\r
+                       interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv)\r
+                       print int(v),interp\r
+                       rs=rs+", %f" %(interp)\r
+                       wc=wc+1\r
+               if (v==0):\r
+                       interp=lastt+(t-lastt)/(v-lastv)*(int(v)-lastv)\r
+                       print int(v),interp\r
+                       rs="{0"\r
+                       wc=1\r
+                       \r
+               i=i+1\r
+print rs+"};"\r
 print wc
\ No newline at end of file
index 05272b9..710468e 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC", "DS18B20_VOC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC", "DS18B20_VOC.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 3b14431..043f104 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common//I2C/MAX1164x.h"
-
-
-extern void OWINIT();
-
-extern void EXTERN_SLEEP();
-
-
-uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/
-uint8_t config_info[16]={0x01,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-uint8_t max_adr=0;
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack_t;
-volatile pack_t pack;
-
-volatile uint8_t wdcounter;
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-}
-
-
-
-
-#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL
-#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0
-#define CH0_CH1 MAX1164x_C_SCAN0
-
-
-
-int main(void){
-    PRR|=(1<<PRADC);  // adc for save Power
-       pack.temp=0x0550;
-       pack.config=0x7F;
-       pack.TH=75;
-       pack.TL=70;
-       pack.rrFF=0xFF;
-       pack.rr00=0;
-       pack.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-       PORTB|=(1<<PINB1);
-       DDRB|=(1<<PINB1);
-       PORTA|=(1<<PINA0);
-       DDRA|=(1<<PINA0);
-       
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1)| (1<<WDP0);   // Set Timeout to ~2 seconds
-       
-
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);//#define MAX1164x_C_CS0
-       _delay_ms(30); //Internal Referenz start
-       //2970 -> 1,5V
-       
-       gcontrol=1;
-       //DDRB|=(1<<PINB1);
-       volatile double l;
-       sei();
-    while(1)   {
-               if (wdcounter>0) {
-                       PORTB&=~(1<<PINB1);
-                       _delay_us(500);
-                       l=MAX1164x_read();
-                       PORTB|=(1<<PINB1);
-                       wdcounter=0;
-               }
-       
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1); //Dauer 2.3ms
-                       //=MAX44009getlux(max_adr);             
-                       //if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
-                       //double l=1000;
-                       
-                       uint16_t w=l;
-                       uint8_t t8=w>>4;
-                       uint8_t af=0;
-                       if (t8>pack.TH) af=1;
-                       if (t8<=pack.TL) af=1; 
-                       cli();
-                       pack.temp=w;
-                       //pack.temp++;
-                       alarmflag=af;
-                       sei();  
-                       EXTERN_SLEEP();         
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               //MCUCR&=~(1<<ISC01);
-               asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common//I2C/MAX1164x.h"\r
+\r
+\r
+extern void OWINIT();\r
+\r
+extern void EXTERN_SLEEP();\r
+\r
+\r
+uint8_t owid[8]={0x28, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x77, 0x6B};/**/\r
+uint8_t config_info[16]={0x01,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+\r
+uint8_t max_adr=0;\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+}\r
+\r
+\r
+\r
+\r
+#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL\r
+#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0\r
+#define CH0_CH1 MAX1164x_C_SCAN0\r
+\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       pack.temp=0x0550;\r
+       pack.config=0x7F;\r
+       pack.TH=75;\r
+       pack.TL=70;\r
+       pack.rrFF=0xFF;\r
+       pack.rr00=0;\r
+       pack.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+       PORTB|=(1<<PINB1);\r
+       DDRB|=(1<<PINB1);\r
+       PORTA|=(1<<PINA0);\r
+       DDRA|=(1<<PINA0);\r
+       \r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       \r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP2) | (1<<WDP1)| (1<<WDP0);   // Set Timeout to ~2 seconds\r
+       \r
+\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);//#define MAX1164x_C_CS0\r
+       _delay_ms(30); //Internal Referenz start\r
+       //2970 -> 1,5V\r
+       \r
+       gcontrol=1;\r
+       //DDRB|=(1<<PINB1);\r
+       volatile double l;\r
+       sei();\r
+    while(1)   {\r
+               if (wdcounter>0) {\r
+                       PORTB&=~(1<<PINB1);\r
+                       _delay_us(500);\r
+                       l=MAX1164x_read();\r
+                       PORTB|=(1<<PINB1);\r
+                       wdcounter=0;\r
+               }\r
+       \r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1); //Dauer 2.3ms\r
+                       //=MAX44009getlux(max_adr);             \r
+                       //if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045\r
+                       //double l=1000;\r
+                       \r
+                       uint16_t w=l;\r
+                       uint8_t t8=w>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack.TH) af=1;\r
+                       if (t8<=pack.TL) af=1; \r
+                       cli();\r
+                       pack.temp=w;\r
+                       //pack.temp++;\r
+                       alarmflag=af;\r
+                       sei();  \r
+                       EXTERN_SLEEP();         \r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               //MCUCR&=~(1<<ISC01);\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 290b54e..fca0860 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_MAX44009</AssemblyName>
-    <Name>DS18B20_VOC</Name>
-    <RootNamespace>DS18B20_MAX44009</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000789</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\OWDS18B20.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20.S</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX1164x.c">
-      <SubType>compile</SubType>
-      <Link>MAX1164x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="DS18B20_VOC.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_MAX44009</AssemblyName>\r
+    <Name>DS18B20_VOC</Name>\r
+    <RootNamespace>DS18B20_MAX44009</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000789</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\OWDS18B20.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20.S</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX1164x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>MAX1164x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_VOC.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 0e9ae0a..3e1aafc 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX1164x.h"
-#include "../common/I2C/SHT2x.h"
-#include "../common/calibr.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-
-
-volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
-volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
-volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       
-volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       
-       
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-volatile uint8_t wdcounter=1;
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-
-
-}
-
-
-typedef union {
-       volatile uint8_t bytes[8];
-       struct {
-               uint16_t temp;  //0
-               uint8_t TH;  //2
-               uint8_t TL;  //3
-               uint8_t config;  //4
-               uint8_t rrFF; //5
-               uint8_t rr00; //6
-               uint8_t rr10; //7
-       };
-} pack1_t;
-volatile pack1_t pack1;
-
-
-
-typedef union {
-       #if  defined(__AVR_ATtiny25__)
-       volatile uint8_t bytes[16];
-       #else
-       volatile uint8_t bytes[64];
-       #endif
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               int16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               #if  defined(__AVR_ATtiny25__)
-               #else
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-               #endif
-       };
-} pack2_t;
-volatile pack2_t pack2;
-
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-double temperatureC,humidityRH,hhum;
-double l;
-
-uint8_t max_adr=0;
-#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL
-#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0
-#define CH0_CH1 MAX1164x_C_SCAN0
-//|MAX1164x_C_CS0
-
-
-inline double interp(double t, double h) {
-       double h2;
-        double t2;
-       h2=h*h;
-       t2=t*t;
-       return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591;
-}
-
-uint8_t cmode=0;
-double R0=0;
-int16_t hr;
-uint8_t startup=5;
-uint8_t reset_R0=0;
-int16_t mr;
-double ip;
-
-int main(void){
-       //volatile double test=calibr_hum(20,1,20);
-    PRR|=(1<<PRADC);  // adc for save Power
-       pack1.temp=0x0550;
-       pack1.config=0x7F;
-       pack1.TH=75;
-       pack1.TL=70;
-       pack1.rrFF=0xFF;
-       pack1.rr00=0;
-       pack1.rr10=0x10;
-       PORTA=0xFF;
-       PORTB=0xFF;
-       OWINIT();
-       PORTB|=(1<<PINB1);
-       DDRB|=(1<<PINB1);
-       PORTA|=(1<<PINA0);
-       DDRA|=(1<<PINA0);
-       
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       
-       while(EECR & (1<<EEPE));
-       EEARL=1;
-       EECR |= (1<<EERE);
-       hr=EEDR;
-       if (hr!=0xFF) {
-               hr=hr<<8;
-               while(EECR & (1<<EEPE));
-               EEARL=0;
-               EECR |= (1<<EERE);
-               hr|=EEDR;
-               R0=hr/100.0;
-               pack2.page3[0]=hr&0xFF;
-               pack2.page3[1]=(hr>>8)&0xFF;
-       }
-
-       
-
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP0) |(1<<WDP2) | (1<<WDP1);    // Set Timeout to ~2 seconds
-       //(1<<WDP3) | (1<<WDP0);    // Set Timeout to ~8 seconds
-
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       
-       SHT2x_SoftReset();
-       SHT2x_ReadUserRegister(userRegister);
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg
-       // --- measure humidity with "Hold Master Mode (HM)" ---
-       //SHT2x_MeasurePoll(HUMIDITY, &sRH);
-       // --- measure temperature with "Polling Mode" (no hold master) ---
-       //SHT2x_MeasurePoll(TEMP, &sT);
-       //-- calculate humidity and temperature --
-       //temperatureC = SHT2x_CalcTemperatureC(sT);
-       //humidityRH = SHT2x_CalcRH(sRH);
-       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);//#define MAX1164x_C_CS0
-       _delay_ms(30); //Internal Referenz start
-       //2970 -> 1,5V  
-       gcontrol=1;
-       sei();
-       //DDRB|=(1<<PINB1);
-    while(1)   {
-               if (pack1.config==0x1F) {
-                       if (reset_R0==0) {
-                               reset_R0=1;
-                               pack1.config=0x7F;
-                               R0=0;
-                               hr=R0*100;
-                               pack2.page3[0]=hr&0xFF;
-                               pack2.page3[1]=(hr>>8)&0xFF;
-                               
-                               while(EECR & (1<<EEPE));
-                               EECR = (0<<EEPM1)|(0<<EEPM0);
-                               EEARL = 0;
-                               EEDR = hr&0xFF;
-                               EECR |= (1<<EEMPE);
-                               EECR |= (1<<EEPE);
-                               while(EECR & (1<<EEPE));
-                               EECR = (0<<EEPM1)|(0<<EEPM0);
-                               EEARL = 1;
-                               EEDR = hr>>8;
-                               EECR |= (1<<EEMPE);
-                               EECR |= (1<<EEPE);
-
-                       }
-               } else reset_R0=0;                      //PORTB|=(1<<PINB1); //Dauer 440ms
-               if (wdcounter>0) {
-                       if (startup!=0) startup--;
-                       SHT2x_MeasurePoll(HUMIDITY, &sRH);
-                       // --- measure temperature with "Polling Mode" (no hold master) ---
-                       SHT2x_MeasurePoll(TEMP, &sT);
-                       //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT);
-                       humidityRH = SHT2x_CalcRH(sRH);
-                       ip=interp(temperatureC,humidityRH);
-                       humidityRH=calibr_hum(temperatureC,-1,humidityRH)*10.0;
-                       //humidityRH=humidityRH*10.0;
-                       temperatureC =temperatureC *10.0-10;
-                       hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                       am2302_hum=0.318*hhum +76.0;
-                       am2302_temp=temperatureC*25.6;
-                       //PORTB&=~(1<<PINB1);
-                       mr=0;
-//Kritische Sektion !______________________________
-                       PORTB&=~(1<<PINB1);
-                       _delay_us(150);
-                       mr+=MAX1164x_read();
-                       _delay_us(150);
-                       mr+=MAX1164x_read();
-                       
-                       PORTB|=(1<<PINB1);
-//ENDE Kritische Sektion !______________________________
-                       //l=mr/2.0*2.048/4096; 
-                       // l maximal 2  mr max 4096  //mr 2V=8000 
-                       
-                       if (cmode) {
-                               //l+=1.5; //Spannung real
-                               mr+=6000;
-                       } 
-                       //if (l>1.8) {
-                       if (mr>7200) {                          
-                               if (cmode==0) {
-                                       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1);
-                                       cmode=1;
-                                       pack2.page3[4]=cmode;
-                               }
-                       }
-                       //if (l<1.6) {
-                       if (mr<6400) {  
-                               if (cmode==1) {
-                                       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);
-                                       cmode=0;
-                                       pack2.page3[4]=cmode;
-                               }
-                               
-                               
-                       }
-                       //hr=l*10000.0;
-                       hr=mr*5/2;
-                       pack2.page3[2]=hr&0xFF;
-                       pack2.page3[3]=(hr>>8)&0xFF;
-                       l=mr/4000.0;
-                       l=( 3/l- 1) *30;
-                       pack2.current=l*100;
-                       //ip=interp(temperatureC,humidityRH);
-                       hr=ip*1000;
-                       pack2.page3[5]=hr&0xFF;
-                       pack2.page3[6]=(hr>>8)&0xFF;
-                       
-                       l=l/ip;
-                       
-                       if (startup==0){
-                       if (l>R0) {
-                               R0=l;
-                               hr=R0*100;
-                               pack2.page3[0]=hr&0xFF;
-                               pack2.page3[1]=(hr>>8)&0xFF;
-                               
-                               while(EECR & (1<<EEPE));
-                               EECR = (0<<EEPM1)|(0<<EEPM0);
-                               EEARL = 0;
-                               EEDR = hr&0xFF;
-                               EECR |= (1<<EEMPE);
-                               EECR |= (1<<EEPE);
-                               while(EECR & (1<<EEPE));
-                               EECR = (0<<EEPM1)|(0<<EEPM0);
-                               EEARL = 1;
-                               EEDR = hr>>8;
-                               EECR |= (1<<EEMPE);
-                               EECR |= (1<<EEPE);
-
-                       }
-                       }
-                        l=l/R0;
-                       l=log(1/l);
-                       l=l*160*4; //fuer DS18B20
-                       if (l>500) {
-                               l=100;
-                       }
-                       wdcounter=0;
-                       
-               }
-       
-               if (gcontrol==1) {
-                       uint16_t w=l;
-                       uint8_t t8=w>>4;
-                       uint8_t af=0;
-                       if (t8>pack1.TH) af=1;
-                       if (t8<=pack1.TL) af=1; 
-                       cli();
-                       pack1.temp=w;
-                       //pack.temp++;
-                       alarmflag=af;
-                       sei();                  
-                       EXTERN_SLEEP();         
-               }
-               if ((gcontrol==2)||(gcontrol==3)) {
-                       gcontrol=0;
-                       
-               }
-
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-   }
-
-
-}
\ No newline at end of file
+       \r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>  \r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX1164x.h"\r
+#include "../common/I2C/SHT2x.h"\r
+#include "../common/calibr.h"\r
+\r
+extern void OWINIT(void);\r
+extern void EXTERN_SLEEP(void);\r
+\r
+\r
+\r
+volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/\r
+volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/\r
+volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       \r
+volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       \r
+       \r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+volatile uint8_t wdcounter=1;\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+\r
+\r
+}\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[8];\r
+       struct {\r
+               uint16_t temp;  //0\r
+               uint8_t TH;  //2\r
+               uint8_t TL;  //3\r
+               uint8_t config;  //4\r
+               uint8_t rrFF; //5\r
+               uint8_t rr00; //6\r
+               uint8_t rr10; //7\r
+       };\r
+} pack1_t;\r
+volatile pack1_t pack1;\r
+\r
+\r
+\r
+typedef union {\r
+       #if  defined(__AVR_ATtiny25__)\r
+       volatile uint8_t bytes[16];\r
+       #else\r
+       volatile uint8_t bytes[64];\r
+       #endif\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               int16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               #if  defined(__AVR_ATtiny25__)\r
+               #else\r
+               uint8_t page2[8]; //17\r
+               union{ \r
+                       uint8_t page3[8]; //25\r
+                       struct {\r
+                               uint16_t R0;\r
+                               uint16_t VS;\r
+                               uint8_t cmode;\r
+                               int16_t ip;\r
+                               uint8_t free;\r
+                       };\r
+               };\r
+               union{ \r
+                       uint8_t page4[8];  //33\r
+                       struct {\r
+                               uint16_t tol_s8;\r
+                               uint16_t tol_d;\r
+                               uint16_t r_day_max;\r
+                               uint16_t r_week_max;\r
+                       };\r
+               };\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+               #endif\r
+       };\r
+} pack2_t;\r
+volatile pack2_t pack2;\r
+\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+double temperatureC,humidityRH,hhum;\r
+double l;\r
+\r
+uint8_t max_adr=0;\r
+#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL\r
+#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0\r
+#define CH0_CH1 MAX1164x_C_SCAN0\r
+//|MAX1164x_C_CS0\r
+\r
+uint16_t weekmaxarr[8];\r
+\r
+inline double interp(double t, double h) {\r
+       double h2;\r
+        double t2;\r
+       h2=h*h;\r
+       t2=t*t;\r
+       return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591;\r
+}\r
+\r
+double R0;\r
+uint16_t mr;\r
+uint8_t startup=10;\r
+double ip;\r
+\r
+#define EEPROM_R0 0\r
+#define EEPROM_R0d 2\r
+#define EEPROM_R0w 4\r
+#define EEPROM_dol 6\r
+\r
+\r
+uint16_t readEEPROM(uint8_t addr,uint16_t def) {\r
+       uint16_t hr;\r
+       while(EECR & (1<<EEPE));\r
+       EEARL=addr+1;\r
+       EECR |= (1<<EERE);\r
+       hr=EEDR;\r
+       if (hr!=0xFF) {\r
+               hr=hr<<8;\r
+               while(EECR & (1<<EEPE));\r
+               EEARL=addr;\r
+               EECR |= (1<<EERE);\r
+               hr|=EEDR;\r
+               return hr;\r
+       }\r
+       return def;\r
+}\r
+\r
+void writeEEPROM(uint8_t addr,uint16_t val) {\r
+       while(EECR & (1<<EEPE));\r
+       EECR = (0<<EEPM1)|(0<<EEPM0);\r
+       EEARL = addr;\r
+       EEDR = val&0xFF;\r
+       EECR |= (1<<EEMPE);\r
+       EECR |= (1<<EEPE);\r
+       while(EECR & (1<<EEPE));\r
+       EECR = (0<<EEPM1)|(0<<EEPM0);\r
+       EEARL = addr+1;\r
+       EEDR = val>>8;\r
+       EECR |= (1<<EEMPE);\r
+       EECR |= (1<<EEPE);\r
+}\r
+\r
+int main(void){\r
+       //volatile double test=calibr_hum(20,1,20);\r
+    PRR|=(1<<PRADC);  // adc for save Power\r
+       pack1.temp=0x0550;\r
+       pack1.config=0x7F;\r
+       pack1.TH=75;\r
+       pack1.TL=70;\r
+       pack1.rrFF=0xFF;\r
+       pack1.rr00=0;\r
+       pack1.rr10=0x10;\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+       OWINIT();\r
+       PORTB|=(1<<PINB1);\r
+       DDRB|=(1<<PINB1);\r
+       PORTA|=(1<<PINA0);\r
+       DDRA|=(1<<PINA0);\r
+       \r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       \r
+       pack2.cmode=0;\r
+       pack2.R0=readEEPROM(EEPROM_R0,1);\r
+       R0=pack2.R0/100.0;\r
+               \r
+       pack2.r_day_max=readEEPROM(EEPROM_R0d,1);\r
+       pack2.r_week_max=readEEPROM(EEPROM_R0w,1);\r
+       pack2.tol_d=readEEPROM(EEPROM_dol,0); \r
+       pack2.tol_s8=0;  //Tag faengt mit Einschalten an\r
+       for(uint8_t i=0;i<7;i++) {\r
+               weekmaxarr[i]=pack2.r_week_max;\r
+       }\r
+\r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       //(1<<WDP0) |(1<<WDP2) | (1<<WDP1);    // Set Timeout to ~2 seconds\r
+       (1<<WDP3) | (1<<WDP0);    // Set Timeout to ~8 seconds\r
+\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       \r
+       SHT2x_SoftReset();\r
+       SHT2x_ReadUserRegister(userRegister);\r
+       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
+       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);//#define MAX1164x_C_CS0\r
+       _delay_ms(30); //Internal Referenz start\r
+       //2970 -> 1,5V  \r
+       gcontrol=1;\r
+       sei();\r
+       //DDRB|=(1<<PINB1);\r
+    while(1)   {\r
+               if (pack1.config==0x1F) {\r
+                       pack1.config=0x7F;\r
+                       R0=1;\r
+                       pack2.R0=0;\r
+                       writeEEPROM(EEPROM_R0,0);\r
+               } \r
+               if (pack1.config==0x05) {\r
+                       pack1.config=0x7F;                              \r
+                       pack2.r_day_max=1;\r
+                       pack2.r_week_max=1;\r
+                       pack2.tol_d=0;\r
+                       pack2.tol_s8=0;  //Tag faengt mit Einschalten an        \r
+                       R0=1;   \r
+                       writeEEPROM(EEPROM_R0,0xFF);\r
+                       writeEEPROM(EEPROM_R0d,0xFF);  //Maximum des Tages\r
+                       writeEEPROM(EEPROM_R0w,0xFF); //Maximum der Letzten 7 Tage\r
+                       writeEEPROM(EEPROM_dol,0xFF); //Anzahl der Betriebstage         \r
+                       for(uint8_t i=0;i<7;i++) {\r
+                               weekmaxarr[i]=1;\r
+                       }                               \r
+               } \r
+               if (wdcounter>0) {\r
+                       pack2.tol_s8++;\r
+                       if (pack2.tol_s8>(10000))  {//10800 ist theortisch der Tag aber meistens zu lang\r
+                               pack2.tol_s8=0;\r
+                               pack2.tol_d++;  //rund 180 Jahre :-)\r
+                               pack2.r_week_max=0;\r
+                               weekmaxarr[7]=pack2.r_day_max;\r
+                               for(uint8_t i=0;i<7;i++) {\r
+                                       weekmaxarr[i]=weekmaxarr[i+1];\r
+                                       if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i];\r
+                               }\r
+                               if (pack2.tol_d>7) {\r
+                                       pack2.R0=pack2.r_week_max;\r
+                               } else {\r
+                                       pack2.R0=pack2.r_day_max;\r
+                               }\r
+                               R0=pack2.R0/100.0-0.5*(pack2.R0/100-R0);\r
+                               pack2.R0=R0*100;\r
+                               writeEEPROM(EEPROM_R0,pack2.R0);\r
+                               writeEEPROM(EEPROM_R0d,pack2.r_day_max);  //Maximum des Tages\r
+                               writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage\r
+                               writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage\r
+                               pack2.r_day_max=0;\r
+                       }\r
+                       if (startup!=0) startup--;\r
+                       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+                       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+                       SHT2x_MeasurePoll(TEMP, &sT);\r
+                       //-- calculate humidity and temperature --\r
+                       temperatureC = SHT2x_CalcTemperatureC(sT);\r
+                       humidityRH = SHT2x_CalcRH(sRH);\r
+                       ip=interp(temperatureC,humidityRH);\r
+                       pack2.ip=ip*1000;\r
+                       humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;\r
+                       //humidityRH=humidityRH*10.0;\r
+                       temperatureC =temperatureC *10.0-4.5;\r
+                       hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                       am2302_hum=0.318*hhum +76.0;\r
+                       am2302_temp=temperatureC*25.6;\r
+                       //PORTB&=~(1<<PINB1);\r
+                       mr=0;\r
+//Kritische Sektion !___Ein Breakpoint in dieser Section kann den TGS8100 zerstoeren!___________________________\r
+                       PORTB&=~(1<<PINB1);\r
+                       _delay_us(150);\r
+                       mr+=MAX1164x_read();\r
+                       _delay_us(150);\r
+                       mr+=MAX1164x_read();\r
+                       \r
+                       PORTB|=(1<<PINB1);\r
+//ENDE Kritische Sektion !______________________________\r
+                       //l=mr/2.0*2.048/4096; \r
+                       // l maximal 2  mr max 4096  //mr 2V=8000 \r
+                       \r
+                       if (pack2.cmode) { //cmode=0 V 0..2 V cmode=1 V 1.5..3.5V\r
+                               //l+=1.5; //Spannung real\r
+                               mr+=6000;\r
+                       } \r
+                       //if (l>1.8) {\r
+                       if (mr>7200) {                          \r
+                               if (pack2.cmode==0) {\r
+                                       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1);\r
+                                       pack2.cmode=1;\r
+                               }\r
+                       }\r
+                       //if (l<1.6) {\r
+                       if (mr<6400) {  \r
+                               if (pack2.cmode==1) {\r
+                                       MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);\r
+                                       pack2.cmode=0;\r
+                               }\r
+                               \r
+                               \r
+                       }\r
+                       //hr=l*10000.0;\r
+                       pack2.VS=mr*5/2;\r
+                       l=mr/4000.0;\r
+                       l=( 3/l- 1) *30;\r
+                       pack2.current=l*100;\r
+                       \r
+                       l=l/ip;\r
+                       \r
+                       if (startup==0){\r
+                               if (l>R0) {\r
+                                       R0=l;\r
+                                       pack2.R0=R0*100;\r
+                                       writeEEPROM(EEPROM_R0,pack2.R0);\r
+\r
+                               }\r
+                               if (l*100>pack2.r_day_max) {\r
+                                       pack2.r_day_max=l*100;\r
+                               }\r
+                       }\r
+                        l=l/R0;\r
+                       l=log(1/l);\r
+                       l=l*160*4; //fuer DS18B20\r
+               //      if (l>500) {\r
+               //              l=100;\r
+               //      }\r
+                       wdcounter=0;\r
+                       \r
+               }\r
+       \r
+               if (gcontrol==1) {\r
+                       uint16_t w=l;\r
+                       uint8_t t8=w>>4;\r
+                       uint8_t af=0;\r
+                       if (t8>pack1.TH) af=1;\r
+                       if (t8<=pack1.TL) af=1; \r
+                       cli();\r
+                       pack1.temp=w;\r
+                       //pack.temp++;\r
+                       alarmflag=af;\r
+                       sei();                  \r
+                       EXTERN_SLEEP();         \r
+               }\r
+               if ((gcontrol==2)||(gcontrol==3)) {\r
+                       gcontrol=0;\r
+                       \r
+               }\r
+\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
+}\r
index 7afb50c..7a42d6d 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC_DS2438_SHT", "DS18B20_VOC_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR
-               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS18B20_VOC_DS2438_SHT", "DS18B20_VOC_DS2438_SHT.cproj", "{7A5672FE-8226-4158-B931-E1F36B9A8858}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Debug|AVR.Build.0 = Debug|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.ActiveCfg = Release|AVR\r
+               {7A5672FE-8226-4158-B931-E1F36B9A8858}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index d6e98e5..14d075c 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS18B20_DS2438</AssemblyName>
-    <Name>DS18B20_VOC_DS2438_SHT</Name>
-    <RootNamespace>DS18B20_DS2438</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000789</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <com_atmel_avrdbg_tool_simulator>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>
-        </InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>
-      <ToolNumber>
-      </ToolNumber>
-      <ToolName>Simulator</ToolName>
-    </com_atmel_avrdbg_tool_simulator>
-    <ExternalProgrammingToolCommand />
-    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\calibr.c">
-      <SubType>compile</SubType>
-      <Link>calibr.c</Link>
-    </Compile>
-    <Compile Include="..\common\I2C\SHT2x.c">
-      <SubType>compile</SubType>
-      <Link>SHT2x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX1164x.c">
-      <SubType>compile</SubType>
-      <Link>MAX1164x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS18B20_DS2438.S</Link>
-    </Compile>
-    <Compile Include="DS18B20_DS2438.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{7a5672fe-8226-4158-b931-e1f36b9a8858}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS18B20_DS2438</AssemblyName>\r
+    <Name>DS18B20_VOC_DS2438_SHT</Name>\r
+    <RootNamespace>DS18B20_DS2438</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data>\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000789</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <com_atmel_avrdbg_tool_simulator>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>\r
+        </InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.simulator</ToolType>\r
+      <ToolNumber>\r
+      </ToolNumber>\r
+      <ToolName>Simulator</ToolName>\r
+    </com_atmel_avrdbg_tool_simulator>\r
+    <ExternalProgrammingToolCommand />\r
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcc.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.directories.IncludePaths>\r
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+  <avrgcc.linker.libraries.Libraries>\r
+    <ListValues>\r
+      <Value>libm</Value>\r
+    </ListValues>\r
+  </avrgcc.linker.libraries.Libraries>\r
+  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+</AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\calibr.c">\r
+      <SubType>compile</SubType>\r
+      <Link>calibr.c</Link>\r
+    </Compile>\r
+    <Compile Include="..\common\I2C\SHT2x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>SHT2x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX1164x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>MAX1164x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS18B20_DS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS18B20_DS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS18B20_DS2438.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
diff --git a/DS18B20_VOC_DS2438_SHT/MAX1164x.h b/DS18B20_VOC_DS2438_SHT/MAX1164x.h
deleted file mode 100644 (file)
index cf8977c..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef MAX1164x_H
-#define MAX1164x_H
-#define MAX1164x_S_SEL2 0x40
-#define MAX1164x_S_SEL1 0x20
-#define MAX1164x_S_SEL0 0x10
-#define MAX1164x_S_ECLK 0x08
-#define MAX1164x_S_BIP 0x04
-#define MAX1164_S_RESET 0x02
-
-#define MAX1164x_C_SCAN1 0x40
-#define MAX1164x_C_SCAN0 0x20
-#define MAX1164x_C_CS0  0x02
-#define MAX1164x_C_SGL 0x01
-
-
-
-void MAX1164x_init();
-void MAX1164x_config(uint8_t setup,uint8_t config);
-int16_t MAX1164x_read();
-
-
-#endif
\ No newline at end of file
index 2256c96..aec3ee8 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2406", "DS2406.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2406", "DS2406.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 5332d97..e6826c4 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-
-
-extern void OWINIT();
-
-uint8_t owid[8]={0x12, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x1E};/**/
-
-       
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-
-
-
-typedef union {
-       volatile uint8_t bytes[1];
-       struct {
-               uint8_t status;
-       };
-} pack_t;
-pack_t pack;
-
-
-
-
-int main(void){
-    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
-       OWINIT();
-       
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       
-               
-       
-
-
-
-#ifdef _EEPROM_SAVE_
-               EEARH=0;
-               
-               uint8_t addr;
-               for(uint8_t i=0;i<16;i++) {
-                       addr=i^0x0C;
-                       while(EECR & (1<<EEPE));   
-                       EEARL=i;
-                       EECR |= (1<<EERE);
-                       counters.c8[addr]=EEDR;
-               }
-               for (uint8_t i=0;i<4;i++) {
-                       if (counters.c32[i]==0xFFFFFFFF) counters.c32[i]=0;
-                       //counters.c32[i]=0;
-               }
-
-               /*for(uint8_t i=0;i<16;i++) {
-                       while(EECR & (1<<EEPE));
-                       EECR = (1<<EEPM0);
-                       EEARL = i;
-                       EECR |= (1<<EEMPE);
-                       EECR |= (1<<EEPE);
-               }*/
-       
-   
-#endif
-       sei();
-    while(1)   {
-               
-               //Test if timer active and no sleep then Idle else Power Down
-               if (TEST_TIMER&&(mode==0)) {
-                       MCUCR|=(1<<SE)|(1<<SM1); //Power Down, only low level on 1-Wire and pin change on PCINT wakes up
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1); 
-               }
-               asm("SLEEP");
-   }
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+\r
+\r
+extern void OWINIT();\r
+\r
+uint8_t owid[8]={0x12, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x1E};/**/\r
+\r
+       \r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[1];\r
+       struct {\r
+               uint8_t status;\r
+       };\r
+} pack_t;\r
+pack_t pack;\r
+\r
+\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power\r
+       OWINIT();\r
+       \r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       \r
+               \r
+       \r
+\r
+\r
+\r
+#ifdef _EEPROM_SAVE_\r
+               EEARH=0;\r
+               \r
+               uint8_t addr;\r
+               for(uint8_t i=0;i<16;i++) {\r
+                       addr=i^0x0C;\r
+                       while(EECR & (1<<EEPE));   \r
+                       EEARL=i;\r
+                       EECR |= (1<<EERE);\r
+                       counters.c8[addr]=EEDR;\r
+               }\r
+               for (uint8_t i=0;i<4;i++) {\r
+                       if (counters.c32[i]==0xFFFFFFFF) counters.c32[i]=0;\r
+                       //counters.c32[i]=0;\r
+               }\r
+\r
+               /*for(uint8_t i=0;i<16;i++) {\r
+                       while(EECR & (1<<EEPE));\r
+                       EECR = (1<<EEPM0);\r
+                       EEARL = i;\r
+                       EECR |= (1<<EEMPE);\r
+                       EECR |= (1<<EEPE);\r
+               }*/\r
+       \r
+   \r
+#endif\r
+       sei();\r
+    while(1)   {\r
+               \r
+               //Test if timer active and no sleep then Idle else Power Down\r
+               if (TEST_TIMER&&(mode==0)) {\r
+                       MCUCR|=(1<<SE)|(1<<SM1); //Power Down, only low level on 1-Wire and pin change on PCINT wakes up\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1); \r
+               }\r
+               asm("SLEEP");\r
+   }\r
 }
\ No newline at end of file
index f033ed3..fb51cbe 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>6.2</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2406</AssemblyName>
-    <Name>DS2406</Name>
-    <RootNamespace>DS2406</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800024445</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>NDEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="DS2406.c">
-      <SubType>compile</SubType>
-    </Compile>
-    <Compile Include="OWDS2406.S">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>6.2</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2406</AssemblyName>\r
+    <Name>DS2406</Name>\r
+    <RootNamespace>DS2406</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800024445</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>NDEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="DS2406.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+    <Compile Include="OWDS2406.S">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 76addbf..5e80148 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define  _CHANGEABLE_ID_
-#include "../common/OWConfig.s"
-#include "../common/OWCRC16.s"
-
-.extern pack,45
-.extern counters,8
-
-.macro CHIP_INIT       
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_channelaccess
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_CHANNEL_ACCESS OW_FIRST_COMMAND+0
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0x0F,OW_WRITE_SCRATCHPAD
-       cjmp 0xAA,hrc_set_readscratchpad
-       cset 0x5A,OW_COPY_SCRATCHPAD
-       cset 0xF0,OW_READ_MEMORY_ADDR
-       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-hrc_set_readscratchpad:
-       ldi r_mode,OW_READ_SCRATCHPAD
-       ldi r_sendflag,1
-       rjmp h_readscratchpad
-
-h_writescratchpad:
-       configZ pack,r_bytep
-       inc  r_bytep
-       st   Z,r_rwbyte
-       cpi  r_bytep,2
-       breq h_writescratchpad_block
-       brsh h_writescratchpad_set_eoffset ;;33
-       rjmp handle_end  ;handle_end zu weit entfernt fuer br...
-h_writescratchpad_set_eoffset:
-       cpi  r_bytep,35
-       breq h_writescratchpad_setcrc
-       mov r_temp,r_bytep
-       subi r_temp,4
-       sts pack+2,r_temp ;AA und PF cleared
-       rjmp handle_end
-;Start writeing to 32 Byte Block ; skip status byte    
-h_writescratchpad_block:
-       lds r_temp,pack ; Adresse low byte
-       andi r_temp,0x1F ;32 byte
-       add r_bytep,r_temp ;Zur angegebenen Startadresse springen
-       ;ori r_temp,0x20 ; Set PF flag
-       sts pack+2,r_temp  ;E4:E0 vorher setzen
-       ; Byte 3 ueberspringen
-       rjmp handle_end_inc
-
-h_writescratchpad_setcrc:
-       ;copy crc to pack
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp ; invertieren , komischer name.....
-       sts pack+44,r_temp
-       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC
-       ldi r_sendflag,1
-       ldi r_bytep,43
-h_writescratchpad_crc:
-       cpi r_bytep,45
-       breq h_writescratchpad_crc_end
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_writescratchpad_crc_end:
-       rjmp handle_end_sleep
-       
-       
-h_readscratchpad:
-       cpi r_bytep,35
-       breq h_readscratchpad_end
-       cpi r_bytep,3
-       brne h_readscratchpad_read_byte
-h_readscratchpad_set_offset:
-       lds r_temp,pack
-       andi r_temp,0x1F
-       ldi r_temp2,3
-       add r_temp,r_temp2
-       mov r_bytep,r_temp
-h_readscratchpad_read_byte:
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_end:
-       rjmp handle_end_sleep
-
-
-
-h_copyscratchpad:
-       cpi  r_bytep,3
-       brsh h_copyscratchpad_ok
-       configZ pack,r_bytep
-       inc  r_bytep
-       ld   r_temp,Z
-       cp r_temp,r_rwbyte
-       brne h_copyscratchpad_nok
-       cpi  r_bytep,3
-       breq h_copyscratchpad_ok
-       ldi  r_bcount,1 
-       rjmp handle_end
-h_copyscratchpad_ok:
-       ldi r_rwbyte,0xAA
-       ldi r_sendflag,1
-       rjmp handle_end
-h_copyscratchpad_nok:
-       lds r_temp,pack+3
-       andi r_temp,~0x80
-       sts pack+3,r_temp
-       rjmp handle_end_sleep
-
-
-h_readmemory_addr:
-       cpi r_bytep,0
-       brne h_readmrmory_addr_byte1
-       sts pack,r_rwbyte
-       rjmp handle_end_inc
-h_readmrmory_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORY
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemory2
-h_readmemory:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       inc r_bytep
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1
-       rjmp h_readmemory_end
-       sts pack+1,r_temp
-       sts pack,r_bytep
-h_readmemory2:
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemory_end:
-       rjmp handle_end_sleep
-
-
-
-
-
-
-
-
-h_readmemorycounter_addr:
-       cpi r_bytep,0
-       brne h_readmrmorycounter_addr_byte1
-       sts pack,r_rwbyte
-       inc r_bytep
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_readmrmorycounter_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORYCOUNTER
-       ;ldi r_bcount,1 
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       mov r_temp,r_bytep
-       andi r_temp,0x1F
-       breq h_readmemorycounter_next
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       ;ldi r_bcount,1
-       rjmp handle_end
-//h_readmemorycounter_end:
-//     ldi  r_mode,OW_SLEEP
-//     clr r_sendflag
-//     rjmp handle_end
-h_readmemorycounter_next:  ; rest lesen
-       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX
-       ldi r_bytep,34
-       lds r_temp2,pack
-       lds r_temp,pack+1
-       //lsr r_temp
-       //ror r_temp2
-
-       lsl r_temp2
-       rol r_temp
-       cpi r_temp,3
-       brne h_readmemorycounter_cFF
-       andi r_temp2,0xC0
-       swap r_temp2
-
-       ;cpi r_temp,0xE0
-
-       configZ counters,r_temp2
-       ld r_temp,Z+
-       sts pack+35,r_temp      
-       ld r_temp,Z+
-       sts pack+36,r_temp      
-       ld r_temp,Z+
-       sts pack+37,r_temp      
-       ld r_temp,Z+
-       sts pack+38,r_temp      
-       rjmp h_readmemorycounter_ex
-h_readmemorycounter_cFF:
-       ldi r_temp,0xFF
-       sts pack+35,r_temp      
-       sts pack+36,r_temp      
-       sts pack+37,r_temp      
-       sts pack+38,r_temp      
-
-h_readmemorycounter_ex:
-       inc r_bytep
-       cpi r_bytep,45
-       breq h_readmemorycounter_ex_end
-       cpi r_bytep,43
-       brne h_readmemorycounter_ex2
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp
-       sts pack+44,r_temp
-h_readmemorycounter_ex2:
-       ;ldi r_bcount,1
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemorycounter_ex_end:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1 ;am ene von allem 
-       rjmp h_readmemorycounter_ex_sleep
-       CRCInit1
-       ldi  r_mode,OW_READ_MEMORYCOUNTER
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter_ex_sleep:
-       ldi r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end
-
-
-
-       
-
-#include "../common/OWPinInterrupt.s"
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define  _CHANGEABLE_ID_\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC16.s"\r
+\r
+.extern pack,45\r
+.extern counters,8\r
+\r
+.macro CHIP_INIT       \r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_channelaccess\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_CHANNEL_ACCESS OW_FIRST_COMMAND+0\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0x0F,OW_WRITE_SCRATCHPAD\r
+       cjmp 0xAA,hrc_set_readscratchpad\r
+       cset 0x5A,OW_COPY_SCRATCHPAD\r
+       cset 0xF0,OW_READ_MEMORY_ADDR\r
+       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       ldi r_mode,OW_SLEEP\r
+       rjmp handle_end\r
+\r
+hrc_set_readscratchpad:\r
+       ldi r_mode,OW_READ_SCRATCHPAD\r
+       ldi r_sendflag,1\r
+       rjmp h_readscratchpad\r
+\r
+h_writescratchpad:\r
+       configZ pack,r_bytep\r
+       inc  r_bytep\r
+       st   Z,r_rwbyte\r
+       cpi  r_bytep,2\r
+       breq h_writescratchpad_block\r
+       brsh h_writescratchpad_set_eoffset ;;33\r
+       rjmp handle_end  ;handle_end zu weit entfernt fuer br...\r
+h_writescratchpad_set_eoffset:\r
+       cpi  r_bytep,35\r
+       breq h_writescratchpad_setcrc\r
+       mov r_temp,r_bytep\r
+       subi r_temp,4\r
+       sts pack+2,r_temp ;AA und PF cleared\r
+       rjmp handle_end\r
+;Start writeing to 32 Byte Block ; skip status byte    \r
+h_writescratchpad_block:\r
+       lds r_temp,pack ; Adresse low byte\r
+       andi r_temp,0x1F ;32 byte\r
+       add r_bytep,r_temp ;Zur angegebenen Startadresse springen\r
+       ;ori r_temp,0x20 ; Set PF flag\r
+       sts pack+2,r_temp  ;E4:E0 vorher setzen\r
+       ; Byte 3 ueberspringen\r
+       rjmp handle_end_inc\r
+\r
+h_writescratchpad_setcrc:\r
+       ;copy crc to pack\r
+       lds r_temp,crc\r
+       com r_temp\r
+       sts pack+43,r_temp\r
+       lds r_temp,crc+1\r
+       com r_temp ; invertieren , komischer name.....\r
+       sts pack+44,r_temp\r
+       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC\r
+       ldi r_sendflag,1\r
+       ldi r_bytep,43\r
+h_writescratchpad_crc:\r
+       cpi r_bytep,45\r
+       breq h_writescratchpad_crc_end\r
+       configZ pack,r_bytep\r
+       ld r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_writescratchpad_crc_end:\r
+       rjmp handle_end_sleep\r
+       \r
+       \r
+h_readscratchpad:\r
+       cpi r_bytep,35\r
+       breq h_readscratchpad_end\r
+       cpi r_bytep,3\r
+       brne h_readscratchpad_read_byte\r
+h_readscratchpad_set_offset:\r
+       lds r_temp,pack\r
+       andi r_temp,0x1F\r
+       ldi r_temp2,3\r
+       add r_temp,r_temp2\r
+       mov r_bytep,r_temp\r
+h_readscratchpad_read_byte:\r
+       configZ pack,r_bytep\r
+       ld r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readscratchpad_end:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+h_copyscratchpad:\r
+       cpi  r_bytep,3\r
+       brsh h_copyscratchpad_ok\r
+       configZ pack,r_bytep\r
+       inc  r_bytep\r
+       ld   r_temp,Z\r
+       cp r_temp,r_rwbyte\r
+       brne h_copyscratchpad_nok\r
+       cpi  r_bytep,3\r
+       breq h_copyscratchpad_ok\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end\r
+h_copyscratchpad_ok:\r
+       ldi r_rwbyte,0xAA\r
+       ldi r_sendflag,1\r
+       rjmp handle_end\r
+h_copyscratchpad_nok:\r
+       lds r_temp,pack+3\r
+       andi r_temp,~0x80\r
+       sts pack+3,r_temp\r
+       rjmp handle_end_sleep\r
+\r
+\r
+h_readmemory_addr:\r
+       cpi r_bytep,0\r
+       brne h_readmrmory_addr_byte1\r
+       sts pack,r_rwbyte\r
+       rjmp handle_end_inc\r
+h_readmrmory_addr_byte1:\r
+       sts pack+1,r_rwbyte\r
+       ldi r_mode,OW_READ_MEMORY\r
+       ldi r_sendflag,1\r
+       clr r_bytep\r
+       rjmp h_readmemory2\r
+h_readmemory:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       inc r_bytep\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       sbrc r_temp2,1\r
+       rjmp h_readmemory_end\r
+       sts pack+1,r_temp\r
+       sts pack,r_bytep\r
+h_readmemory2:\r
+       lds r_bytep,pack\r
+       andi r_bytep,0x1F\r
+       configZ pack+3,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end\r
+h_readmemory_end:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+h_readmemorycounter_addr:\r
+       cpi r_bytep,0\r
+       brne h_readmrmorycounter_addr_byte1\r
+       sts pack,r_rwbyte\r
+       inc r_bytep\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_readmrmorycounter_addr_byte1:\r
+       sts pack+1,r_rwbyte\r
+       ldi r_mode,OW_READ_MEMORYCOUNTER\r
+       ;ldi r_bcount,1 \r
+       ldi r_sendflag,1\r
+       clr r_bytep\r
+       rjmp h_readmemorycounter2\r
+h_readmemorycounter:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       ldi r_temp,1  ;inc leider kein c flag\r
+       add r_bytep,r_temp\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       mov r_temp,r_bytep\r
+       andi r_temp,0x1F\r
+       breq h_readmemorycounter_next\r
+       sts pack+1,r_temp2\r
+       sts pack,r_bytep\r
+h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen\r
+       lds r_bytep,pack\r
+       andi r_bytep,0x1F\r
+       configZ pack+3,r_bytep\r
+       ld   r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+//h_readmemorycounter_end:\r
+//     ldi  r_mode,OW_SLEEP\r
+//     clr r_sendflag\r
+//     rjmp handle_end\r
+h_readmemorycounter_next:  ; rest lesen\r
+       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX\r
+       ldi r_bytep,34\r
+       lds r_temp2,pack\r
+       lds r_temp,pack+1\r
+       //lsr r_temp\r
+       //ror r_temp2\r
+\r
+       lsl r_temp2\r
+       rol r_temp\r
+       cpi r_temp,3\r
+       brne h_readmemorycounter_cFF\r
+       andi r_temp2,0xC0\r
+       swap r_temp2\r
+\r
+       ;cpi r_temp,0xE0\r
+\r
+       configZ counters,r_temp2\r
+       ld r_temp,Z+\r
+       sts pack+35,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+36,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+37,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+38,r_temp      \r
+       rjmp h_readmemorycounter_ex\r
+h_readmemorycounter_cFF:\r
+       ldi r_temp,0xFF\r
+       sts pack+35,r_temp      \r
+       sts pack+36,r_temp      \r
+       sts pack+37,r_temp      \r
+       sts pack+38,r_temp      \r
+\r
+h_readmemorycounter_ex:\r
+       inc r_bytep\r
+       cpi r_bytep,45\r
+       breq h_readmemorycounter_ex_end\r
+       cpi r_bytep,43\r
+       brne h_readmemorycounter_ex2\r
+       lds r_temp,crc\r
+       com r_temp\r
+       sts pack+43,r_temp\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts pack+44,r_temp\r
+h_readmemorycounter_ex2:\r
+       ;ldi r_bcount,1\r
+       configZ pack,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end\r
+h_readmemorycounter_ex_end:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       ldi r_temp,1  ;inc leider kein c flag\r
+       add r_bytep,r_temp\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       sbrc r_temp2,1 ;am ene von allem \r
+       rjmp h_readmemorycounter_ex_sleep\r
+       CRCInit1\r
+       ldi  r_mode,OW_READ_MEMORYCOUNTER\r
+       sts pack+1,r_temp2\r
+       sts pack,r_bytep\r
+       rjmp h_readmemorycounter2\r
+h_readmemorycounter_ex_sleep:\r
+       ldi r_mode,OW_SLEEP\r
+       clr r_sendflag\r
+       rjmp handle_end\r
+\r
+\r
+\r
+       \r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 89b07db..c545126 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define _4_COUNTERS_
-//#define _EEPROM_SAVE_
-#define _CPULLUP_
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-
-
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-
-#if defined(_4_COUNTERS_)&&defined(_EEPROM_SAVE_)
-#error on ATtinyX5 you can not enable four counters and EEPROM save
-#endif
-#endif
-
-
-extern void OWINIT();
-
-uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/
-uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-       
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-
-
-volatile uint8_t wdcounter;
-
-
-
-
-typedef union {
-       volatile uint8_t bytes[45];
-       struct {
-               uint16_t addr;
-               uint8_t status;
-               uint8_t scratch[32];//3
-               uint32_t counter;  //35
-               uint32_t zero;   //39
-               uint16_t crc;  //43
-       };
-} counterpack_t;
-counterpack_t pack;
-
-volatile uint8_t lastcps;
-typedef union {
-       uint32_t c32[4];
-       uint8_t c8[16];
-} counters_t;
-
-volatile counters_t counters;
-
-volatile uint8_t istat;
-
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-#define PCINT_VECTOR PCINT0_vect
-#define PIN_REG PINB
-#define PIN_DDR DDRB
-#define PIN_CH2 (1<<PINB3)
-#define PIN_CH3 (1<<PINB4)
-#define PIN_CH0 (1<<PINB0)
-#define PIN_CH1 (1<<PINB1)
-#define PORT_EE PINB
-#define PIN_EE (1<<PINB0)
-#define TEST_TIMER  ((TIMSK & (1<<TOIE0))==0)
-#endif
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-#define PCINT_VECTOR PCINT0_vect
-#define PIN_REG PINA
-#define PIN_DDR DDRA
-#define PIN_CH2 (1<<PINA4)
-#define PIN_CH3 (1<<PINA5)
-#define PIN_CH0 (1<<PINA6)
-#define PIN_CH1 (1<<PINA7)
-#define PORT_EE PINA //WARNING have to be the same PORT like PINREG because of istat
-#define PIN_EE (1<<PINA0)
-#define TEST_TIMER  ((TIMSK0 & (1<<TOIE0))==0)
-
-#endif
-
-
-ISR(PCINT0_vect) {
-       if (((PIN_REG&PIN_CH2)==0)&&((istat&PIN_CH2)==PIN_CH2)) {       counters.c32[2]++;      }
-       if (((PIN_REG&PIN_CH3)==0)&&((istat&PIN_CH3)==PIN_CH3)) {       counters.c32[3]++;      }
-       #ifdef _4_COUNTERS_
-       if (((PIN_REG&PIN_CH0)==0)&&((istat&PIN_CH0)==PIN_CH0)) {       counters.c32[0]++;      }
-       if (((PIN_REG&PIN_CH1)==0)&&((istat&PIN_CH1)==PIN_CH1)) {       counters.c32[1]++;      }
-       #endif
-       istat=PIN_REG;
-       #ifdef _EEPROM_SAVE_
-       if (((PORT_EE&PIN_EE)==0)&&((istat&PIN_EE)==PIN_EE)) {
-               //PORTB&=~(1<<PINB1);
-               EEARH=0;
-#ifndef _4_COUNTERS_
-               counters.c32[0]++;//Count the save cycles 
-#endif
-               for(uint8_t i=0;i<16;i++) {
-                       uint8_t addr=i^0x0C;
-                       while(EECR & (1<<EEPE));
-                       EECR = (0<<EEPM1)|(0<<EEPM0);
-                       EEARL = i;
-                       EEDR = counters.c8[addr];
-                       EECR |= (1<<EEMPE);
-                       EECR |= (1<<EEPE);
-               }
-               //PORTB|=(1<<PINB1);
-       }
-       #endif
-}
-
-
-int main(void){
-    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
-       OWINIT();
-       
-       pack.zero=0;
-       counters.c32[0]=0;
-       counters.c32[2]=0;
-       counters.c32[1]=0;
-       counters.c32[3]=0;
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-       PORTB|=(1<<PINB5) //Reset
-#ifdef _CPULLUP_
-       |PIN_CH2|PIN_CH3
-#ifdef _4_COUNTERS_    
-       |PIN_CH0|PIN_CH1
-#endif 
-#endif 
-       ;
-       
-       GIMSK|=(1<<PCIE);
-       
-       PCMSK=(1<<PCINT3)|(1<<PCINT4)
-#ifdef _4_COUNTERS_
-       |(1<<PCINT0)|(1<<PCINT1)
-#endif
-       ;
-#ifdef _EEPROM_SAVE_
-       DDRB&=~PIN_EE;
-       PCMSK|=(1<<PCINT0);
-       PORTB&=~PIN_EE; //Spannungsueberpruefung
-#endif
-       DDRB &=~((1<<PINB3)|(1<<PINB4)
-#ifdef _4_COUNTERS_
-       |(1<<PINB0)|(1<<PINB1)
-#endif
-       );
-       istat=PIN_REG;
-#endif
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-
-       PORTB|=0xFF-(1<<PINB2); //Make PullUp an all Pins but not OW_PIN
-       PORTA|=0xFF; 
-       if (PINB&(1<<PINB0)) { 
-       } else {//SW set, PINB0 =0 no pullup, clear PORT of ios
-               PORTA&=~((1<<PINA4)|(1<<PINA5));
-#ifdef _4_COUNTERS_
-               PORTA&=~((1<<PINA6)|(1<<PINA7));
-#endif
-               PORTB&=~(1<<PINB0);  //Disable Pullup io switch to save Power
-                               
-       } 
-
-       GIMSK|=(1<<PCIE0);
-       PCMSK0=(1<<PCINT4)|(1<<PCINT5)
-#ifdef _4_COUNTERS_
-               |(1<<PCINT6)|(1<<PCINT7)
-#endif
-       ;
-       
-       
-#ifdef _EEPROM_SAVE_
-       DDRA&=~(1<<PINA0);
-       PCMSK0|=(1<<PCINT0);
-       PORTA&=~(1<<PINA0); //Spannungsueberpruefung
-#endif
-       istat=PINB;
-#endif
-
-#ifdef _EEPROM_SAVE_
-               EEARH=0;
-               
-               uint8_t addr;
-               for(uint8_t i=0;i<16;i++) {
-                       addr=i^0x0C;
-                       while(EECR & (1<<EEPE));   
-                       EEARL=i;
-                       EECR |= (1<<EERE);
-                       counters.c8[addr]=EEDR;
-               }
-               for (uint8_t i=0;i<4;i++) {
-                       if (counters.c32[i]==0xFFFFFFFF) counters.c32[i]=0;
-                       //counters.c32[i]=0;
-               }
-
-               /*for(uint8_t i=0;i<16;i++) {
-                       while(EECR & (1<<EEPE));
-                       EECR = (1<<EEPM0);
-                       EEARL = i;
-                       EECR |= (1<<EEMPE);
-                       EECR |= (1<<EEPE);
-               }*/
-       
-   
-#endif
-       sei();
-    while(1)   {
-               
-               //Test if timer active and no sleep then Idle else Power Down
-               if (TEST_TIMER&&(mode==0)) {
-                       MCUCR|=(1<<SE)|(1<<SM1); //Power Down, only low level on 1-Wire and pin change on PCINT wakes up
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1); 
-               }
-               asm("SLEEP");
-   }
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define _4_COUNTERS_\r
+//#define _EEPROM_SAVE_\r
+#define _CPULLUP_\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+\r
+\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+\r
+#if defined(_4_COUNTERS_)&&defined(_EEPROM_SAVE_)\r
+#error on ATtinyX5 you can not enable four counters and EEPROM save\r
+#endif\r
+#endif\r
+\r
+\r
+extern void OWINIT();\r
+\r
+uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/\r
+uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+       \r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[45];\r
+       struct {\r
+               uint16_t addr;\r
+               uint8_t status;\r
+               uint8_t scratch[32];//3\r
+               uint32_t counter;  //35\r
+               uint32_t zero;   //39\r
+               uint16_t crc;  //43\r
+       };\r
+} counterpack_t;\r
+counterpack_t pack;\r
+\r
+volatile uint8_t lastcps;\r
+typedef union {\r
+       uint32_t c32[4];\r
+       uint8_t c8[16];\r
+} counters_t;\r
+\r
+volatile counters_t counters;\r
+\r
+volatile uint8_t istat;\r
+\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+#define PCINT_VECTOR PCINT0_vect\r
+#define PIN_REG PINB\r
+#define PIN_DDR DDRB\r
+#define PIN_CH2 (1<<PINB3)\r
+#define PIN_CH3 (1<<PINB4)\r
+#define PIN_CH0 (1<<PINB0)\r
+#define PIN_CH1 (1<<PINB1)\r
+#define PORT_EE PINB\r
+#define PIN_EE (1<<PINB0)\r
+#define TEST_TIMER  ((TIMSK & (1<<TOIE0))==0)\r
+#endif\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+#define PCINT_VECTOR PCINT0_vect\r
+#define PIN_REG PINA\r
+#define PIN_DDR DDRA\r
+#define PIN_CH2 (1<<PINA4)\r
+#define PIN_CH3 (1<<PINA5)\r
+#define PIN_CH0 (1<<PINA6)\r
+#define PIN_CH1 (1<<PINA7)\r
+#define PORT_EE PINA //WARNING have to be the same PORT like PINREG because of istat\r
+#define PIN_EE (1<<PINA0)\r
+#define TEST_TIMER  ((TIMSK0 & (1<<TOIE0))==0)\r
+\r
+#endif\r
+\r
+\r
+ISR(PCINT0_vect) {\r
+       if (((PIN_REG&PIN_CH2)==0)&&((istat&PIN_CH2)==PIN_CH2)) {       counters.c32[2]++;      }\r
+       if (((PIN_REG&PIN_CH3)==0)&&((istat&PIN_CH3)==PIN_CH3)) {       counters.c32[3]++;      }\r
+       #ifdef _4_COUNTERS_\r
+       if (((PIN_REG&PIN_CH0)==0)&&((istat&PIN_CH0)==PIN_CH0)) {       counters.c32[0]++;      }\r
+       if (((PIN_REG&PIN_CH1)==0)&&((istat&PIN_CH1)==PIN_CH1)) {       counters.c32[1]++;      }\r
+       #endif\r
+       istat=PIN_REG;\r
+       #ifdef _EEPROM_SAVE_\r
+       if (((PORT_EE&PIN_EE)==0)&&((istat&PIN_EE)==PIN_EE)) {\r
+               //PORTB&=~(1<<PINB1);\r
+               EEARH=0;\r
+#ifndef _4_COUNTERS_\r
+               counters.c32[0]++;//Count the save cycles \r
+#endif\r
+               for(uint8_t i=0;i<16;i++) {\r
+                       uint8_t addr=i^0x0C;\r
+                       while(EECR & (1<<EEPE));\r
+                       EECR = (0<<EEPM1)|(0<<EEPM0);\r
+                       EEARL = i;\r
+                       EEDR = counters.c8[addr];\r
+                       EECR |= (1<<EEMPE);\r
+                       EECR |= (1<<EEPE);\r
+               }\r
+               //PORTB|=(1<<PINB1);\r
+       }\r
+       #endif\r
+}\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power\r
+       OWINIT();\r
+       \r
+       pack.zero=0;\r
+       counters.c32[0]=0;\r
+       counters.c32[2]=0;\r
+       counters.c32[1]=0;\r
+       counters.c32[3]=0;\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       \r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+       PORTB|=(1<<PINB5) //Reset\r
+#ifdef _CPULLUP_\r
+       |PIN_CH2|PIN_CH3\r
+#ifdef _4_COUNTERS_    \r
+       |PIN_CH0|PIN_CH1\r
+#endif \r
+#endif \r
+       ;\r
+       \r
+       GIMSK|=(1<<PCIE);\r
+       \r
+       PCMSK=(1<<PCINT3)|(1<<PCINT4)\r
+#ifdef _4_COUNTERS_\r
+       |(1<<PCINT0)|(1<<PCINT1)\r
+#endif\r
+       ;\r
+#ifdef _EEPROM_SAVE_\r
+       DDRB&=~PIN_EE;\r
+       PCMSK|=(1<<PCINT0);\r
+       PORTB&=~PIN_EE; //Spannungsueberpruefung\r
+#endif\r
+       DDRB &=~((1<<PINB3)|(1<<PINB4)\r
+#ifdef _4_COUNTERS_\r
+       |(1<<PINB0)|(1<<PINB1)\r
+#endif\r
+       );\r
+       istat=PIN_REG;\r
+#endif\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+\r
+       PORTB|=0xFF-(1<<PINB2); //Make PullUp an all Pins but not OW_PIN\r
+       PORTA|=0xFF; \r
+       if (PINB&(1<<PINB0)) { \r
+       } else {//SW set, PINB0 =0 no pullup, clear PORT of ios\r
+               PORTA&=~((1<<PINA4)|(1<<PINA5));\r
+#ifdef _4_COUNTERS_\r
+               PORTA&=~((1<<PINA6)|(1<<PINA7));\r
+#endif\r
+               PORTB&=~(1<<PINB0);  //Disable Pullup io switch to save Power\r
+                               \r
+       } \r
+\r
+       GIMSK|=(1<<PCIE0);\r
+       PCMSK0=(1<<PCINT4)|(1<<PCINT5)\r
+#ifdef _4_COUNTERS_\r
+               |(1<<PCINT6)|(1<<PCINT7)\r
+#endif\r
+       ;\r
+       \r
+       \r
+#ifdef _EEPROM_SAVE_\r
+       DDRA&=~(1<<PINA0);\r
+       PCMSK0|=(1<<PCINT0);\r
+       PORTA&=~(1<<PINA0); //Spannungsueberpruefung\r
+#endif\r
+       istat=PINB;\r
+#endif\r
+\r
+#ifdef _EEPROM_SAVE_\r
+               EEARH=0;\r
+               \r
+               uint8_t addr;\r
+               for(uint8_t i=0;i<16;i++) {\r
+                       addr=i^0x0C;\r
+                       while(EECR & (1<<EEPE));   \r
+                       EEARL=i;\r
+                       EECR |= (1<<EERE);\r
+                       counters.c8[addr]=EEDR;\r
+               }\r
+               for (uint8_t i=0;i<4;i++) {\r
+                       if (counters.c32[i]==0xFFFFFFFF) counters.c32[i]=0;\r
+                       //counters.c32[i]=0;\r
+               }\r
+\r
+               /*for(uint8_t i=0;i<16;i++) {\r
+                       while(EECR & (1<<EEPE));\r
+                       EECR = (1<<EEPM0);\r
+                       EEARL = i;\r
+                       EECR |= (1<<EEMPE);\r
+                       EECR |= (1<<EEPE);\r
+               }*/\r
+       \r
+   \r
+#endif\r
+       sei();\r
+    while(1)   {\r
+               \r
+               //Test if timer active and no sleep then Idle else Power Down\r
+               if (TEST_TIMER&&(mode==0)) {\r
+                       MCUCR|=(1<<SE)|(1<<SM1); //Power Down, only low level on 1-Wire and pin change on PCINT wakes up\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1); \r
+               }\r
+               asm("SLEEP");\r
+   }\r
 }
\ No newline at end of file
index fc6996c..68613a5 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2423</AssemblyName>
-    <Name>DS2423</Name>
-    <RootNamespace>DS2423</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800024445</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\OWDS2423.S">
-      <SubType>compile</SubType>
-      <Link>OWDS2423.S</Link>
-    </Compile>
-    <Compile Include="DS2423.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2423</AssemblyName>\r
+    <Name>DS2423</Name>\r
+    <RootNamespace>DS2423</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800024445</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\OWDS2423.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS2423.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS2423.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 3b8bc1f..9946f3c 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423_BMP280", "DS2423_BMP280.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR
-               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423_BMP280", "DS2423_BMP280.cproj", "{26106A5A-6618-4774-943F-65C46DDB610B}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Debug|AVR.Build.0 = Debug|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.ActiveCfg = Release|AVR\r
+               {26106A5A-6618-4774-943F-65C46DDB610B}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 8ec5432..8f0596e 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define _4_COUNTERS_
-#define _EEPROM_SAVE_
-//#define _CPULLUP_
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/BMP280.h"
-
-
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/
-uint8_t config_info[16]={0x09,0x0D,0x09,0x0D,0x01,0x08,0x02,0x08,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-       
-
-extern volatile uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-
-
-volatile uint8_t wdcounter;
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       //if (reset_indicator==1) reset_indicator++;
-       //else if (reset_indicator==2) mode=0;
-}
-
-
-typedef union {
-       volatile uint8_t bytes[45];
-       struct {
-               uint16_t addr;
-               uint8_t status;
-               uint8_t scratch[32];//3
-               uint32_t counter;  //35
-               uint32_t zero;   //39
-               uint16_t crc;  //43
-       };
-} counterpack_t;
-counterpack_t pack;
-
-volatile uint8_t lastcps;
-typedef union {
-       uint32_t c32[4];
-       uint8_t c8[16];
-} counters_t;
-
-volatile counters_t counters;
-
-volatile uint8_t istat;
-
-
-volatile uint8_t wdcounter;
-
-int main(void){
-     PRR|=(1<<PRADC);  // adc for save Power
-     PORTA=0xFF;
-     PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-     DDRB|=(1<<PORTB0); //Als Ausgang und 0
-     
-     
-     OWINIT();
-
-     ACSR|=(1<<ACD);  //Disable Comparator
-     ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-     MCUCR &=~(1<<PUD); //All Pins Pullup...
-     MCUCR |=(1<<BODS);
-
-     
-     WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-     WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-     (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-        
-        
-       pack.zero=0;
-       counters.c32[0]=0;
-       counters.c32[2]=0;
-       counters.c32[1]=0;
-       counters.c32[3]=0;
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       
-       USI_TWI_Master_Initialise();
-       bmp280Init();   
-
-       uint32_t P;
-       int32_t t;
-       bmp280ConvertInt(&t,&P,1);
-       _delay_ms(200);
-       bmp280ConvertInt(&t,&P,1);
-       counters.c32[3]=P;
-       counters.c32[2]=t;
-       wdcounter=100;
-       sei();
-    while(1)   {
-               
-               if (wdcounter>2) {
-                       bmp280ConvertInt(&t,&P,1);
-                       while (mode!=0) ;
-                       cli();
-                       counters.c32[3]=P;
-                       counters.c32[2]=t;
-                       sei();
-                       
-                       wdcounter=0;
-               }
-
-               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-   }
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define _4_COUNTERS_\r
+#define _EEPROM_SAVE_\r
+//#define _CPULLUP_\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/BMP280.h"\r
+\r
+\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/\r
+uint8_t config_info[16]={0x09,0x0D,0x09,0x0D,0x01,0x08,0x02,0x08,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+       \r
+\r
+extern volatile uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       //if (reset_indicator==1) reset_indicator++;\r
+       //else if (reset_indicator==2) mode=0;\r
+}\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[45];\r
+       struct {\r
+               uint16_t addr;\r
+               uint8_t status;\r
+               uint8_t scratch[32];//3\r
+               uint32_t counter;  //35\r
+               uint32_t zero;   //39\r
+               uint16_t crc;  //43\r
+       };\r
+} counterpack_t;\r
+counterpack_t pack;\r
+\r
+volatile uint8_t lastcps;\r
+typedef union {\r
+       uint32_t c32[4];\r
+       uint8_t c8[16];\r
+} counters_t;\r
+\r
+volatile counters_t counters;\r
+\r
+volatile uint8_t istat;\r
+\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+int main(void){\r
+     PRR|=(1<<PRADC);  // adc for save Power\r
+     PORTA=0xFF;\r
+     PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+     DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+     \r
+     \r
+     OWINIT();\r
+\r
+     ACSR|=(1<<ACD);  //Disable Comparator\r
+     ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+     MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+     MCUCR |=(1<<BODS);\r
+\r
+     \r
+     WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+     WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+     (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+        \r
+        \r
+       pack.zero=0;\r
+       counters.c32[0]=0;\r
+       counters.c32[2]=0;\r
+       counters.c32[1]=0;\r
+       counters.c32[3]=0;\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       \r
+       USI_TWI_Master_Initialise();\r
+       bmp280Init();   \r
+\r
+       uint32_t P;\r
+       int32_t t;\r
+       bmp280ConvertInt(&t,&P,1);\r
+       _delay_ms(200);\r
+       bmp280ConvertInt(&t,&P,1);\r
+       counters.c32[3]=P;\r
+       counters.c32[2]=t;\r
+       wdcounter=100;\r
+       sei();\r
+    while(1)   {\r
+               \r
+               if (wdcounter>2) {\r
+                       bmp280ConvertInt(&t,&P,1);\r
+                       while (mode!=0) ;\r
+                       cli();\r
+                       counters.c32[3]=P;\r
+                       counters.c32[2]=t;\r
+                       sei();\r
+                       \r
+                       wdcounter=0;\r
+               }\r
+\r
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+   }\r
 }
\ No newline at end of file
index d6305a2..f38d95d 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2423_BMP280</AssemblyName>
-    <Name>DS2423_BMP280</Name>
-    <RootNamespace>DS2423_BMP280</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800024445</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
-      <SubType>compile</SubType>
-      <Link>BMP280.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2423.S">
-      <SubType>compile</SubType>
-      <Link>OWDS2423.S</Link>
-    </Compile>
-    <Compile Include="DS2423_BMP280.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{26106a5a-6618-4774-943f-65c46ddb610b}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2423_BMP280</AssemblyName>\r
+    <Name>DS2423_BMP280</Name>\r
+    <RootNamespace>DS2423_BMP280</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.22.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800024445</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">\r
+      <SubType>compile</SubType>\r
+      <Link>BMP280.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2423.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS2423.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS2423_BMP280.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 6142108..68af380 100644 (file)
@@ -1,3 +1,3 @@
-/Debug/
-/Release/
-*.atsuo
+/Debug/\r
+/Release/\r
+*.atsuo\r
index bbd175c..769482e 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#define F_CPU 8000000UL
-#define FP_CALC
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-
-extern void OWINIT();
-
-
-uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/
-uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-volatile uint8_t wdcounter;
-
-
-typedef union {
-#if  defined(__AVR_ATtiny25__)
-       volatile uint8_t bytes[16];
-#else
-       volatile uint8_t bytes[64];
-#endif
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-#if  defined(__AVR_ATtiny25__)
-#else
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-#endif
-       };
-} pack_t;
-volatile pack_t pack;
-
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-
-#define DDR_SENSOR   DDRB 
-#define PORT_SENSOR  PORTB
-#define PIN_SENSOR   PINB
-#define SENSOR       PB4
-#endif
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-#define DDR_SENSOR   DDRA
-#define PORT_SENSOR  PORTA
-#define PIN_SENSOR   PINA
-#define SENSOR       PINA2
-#endif
-
-
-
-#define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)
-#define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup
-#define SENSOR_sda_low    PORT_SENSOR &= ~(1 << SENSOR)
-#define SENSOR_is_hi                   PIN_SENSOR & (1 << SENSOR)
-#define SENSOR_is_low          !(PIN_SENSOR & (1 << SENSOR))
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-uint8_t am_wait(uint8_t _time,uint8_t _signal){
-       TCNT1=0;
-       while(TCNT1==0);
-       if (_signal) 
-               while((SENSOR_is_hi)&&(TCNT1<_time)) {}
-       else
-               while((SENSOR_is_low)&&(TCNT1<_time)) {}
-        
-               if (TCNT1>=_time) {return 1;}
-       return 0;
-}
-
-volatile uint8_t am2302_mode=0;        
-volatile uint8_t timeout=0;
-
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       sleep_disable();          // Disable Sleep on Wakeup
-       am2302_mode++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-/*     if (timeout==2) {
-               DIS_TIMER;
-               EN_OWINT;
-               mode=OWM_SLEEP;
-       }
-       timeout++;*/
-       sleep_enable();           // Enable Sleep Mode
-
-}
-
-int testSW() {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-       __asm__ __volatile__ ("nop");
-       PORTB|=(1<<PORTB0); //Pullup
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       r=PINB&(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       PORTB&=~(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-       
-       
-}      
-       
-uint8_t am2302_1() {
-       int16_t lam2302_temp;
-       uint16_t lam2302_hum;
-       uint8_t rSREG;
-       uint8_t sensor_data[5];
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-       TCCR1=(1<<CS12); //Clock/8 1µs
-#endif
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-       TCCR1B=(1<<CS11); //Clock/8 1µs
-#endif
-       SENSOR_sda_out;
-       SENSOR_sda_low; // MCU start signal
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       SENSOR_sda_in;
-       if (am_wait(200,1)) return 2;
-
-       // AM2302 response signal min: 75us typ:80us max:85us
-       if (am_wait(100,0)) return 3;
-       if (am_wait(100,1)) return 4;
-       
-       for(uint8_t i = 0; i < 5; i++)  {
-               uint8_t sensor_byte = 0;
-               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
-                       if (am_wait(88,0)) return 5;
-                       
-                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
-                       sensor_byte <<= 1; // add new lower byte
-                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
-                               sensor_byte |= 1;
-                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
-                       }
-               }
-               sensor_data[i] = sensor_byte;
-       }
-
-       // checksum
-       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
-       {
-               // debug output
-               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
-               PORTB&=~(1<<PINB0);
-               return 7;
-       }
-       if (!testSW()) {
-#ifdef FP_CALC
-       double htemp;
-       if (sensor_data[2]&0x80) { //min
-               sensor_data[2]&=~(0x80);
-               htemp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-               htemp=((sensor_data[2]<<8) + sensor_data[3]);
-       double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);
-       
-       lam2302_hum=0.318*hhum +76;
-       lam2302_temp=htemp*25.6;
-#else
-
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
-       
-       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
-       lam2302_hum=lam2302_hum*16/49-h1+80;
-       //lam2302_temp=lam2302_temp*128/5;
-
-       int16_t h2=lam2302_temp%5;
-       lam2302_temp=lam2302_temp/5;
-       lam2302_temp*=128;
-       lam2302_temp+=h2*128/5;
-#endif    
-       config_info[5]=7;
-       }
-       else {
-               if (sensor_data[2]&0x80) { //minus
-                       sensor_data[2]&=~(0x80);
-                       lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
-               } else
-               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;;
-               
-               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-               config_info[5]=12;
-       }
-       rSREG=SREG;
-       cli();
-       am2302_hum=lam2302_hum;
-       am2302_temp=lam2302_temp;
-       SREG=rSREG;
-       return 0;
-}
-
-
-uint8_t am2302_2() { //4mhz
-       int16_t lam2302_temp;
-       uint16_t lam2302_hum;
-       uint8_t rSREG;
-       uint8_t sensor_data[5];
-       #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-       TCCR1=(1<<CS11)|(1<<CS10); //Clock/8 1µs
-       #endif
-
-       #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-       TCCR1B=(1<<CS11); //Clock/8 1µs
-       #endif
-       SENSOR_sda_out;
-       SENSOR_sda_low; // MCU start signal
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       SENSOR_sda_in;
-       if (am_wait(200,1)) return 2;
-
-       // AM2302 response signal min: 75us typ:80us max:85us
-       if (am_wait(100,0)) return 3;
-       if (am_wait(100,1)) return 4;
-       
-       for(uint8_t i = 0; i < 5; i++)  {
-               uint8_t sensor_byte = 0;
-               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
-                       if (am_wait(88,0)) return 5;
-                       
-                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
-                       sensor_byte <<= 1; // add new lower byte
-                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
-                               sensor_byte |= 1;
-                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
-                       }
-               }
-               sensor_data[i] = sensor_byte;
-       }
-
-       // checksum
-       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
-       {
-               // debug output
-               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
-               PORTB&=~(1<<PINB0);
-               return 7;
-       }
-#ifdef FP_CALC
-       lam2302_hum=0.318* ((sensor_data[0]<<8) + sensor_data[1])+76;
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3])*25.6;
-       } else
-               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;
-#else
-
-
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-       lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
-       
-       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
-       lam2302_hum=lam2302_hum*16/49-h1+80;
-       //lam2302_temp=lam2302_temp*128/5;
-
-       int16_t h2=lam2302_temp%5;
-       lam2302_temp=lam2302_temp/5;
-       lam2302_temp*=128;
-       lam2302_temp+=h2*128/5;
-#endif 
-       
-       
-       rSREG=SREG;
-       cli();
-       am2302_hum=lam2302_hum;
-       am2302_temp=lam2302_temp;
-       SREG=rSREG;
-       return 0;
-}
-
-
-
-int main(void){
-    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-       PORTA=0xFF;
-       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-       DDRB|=(1<<PORTB0); //Als Ausgang und 0
-#endif
-       OWINIT();
-
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       MCUCR &=~(1<<PUD);
-       
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-
-       PORTB|=(1<<PINB0)|(1<<PINB1)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);
-       DDRB|=(1<<PINB1); //DBLINE
-#define SENSON PORTB|=(1<<PINB0);
-#define SENSOFF PORTB&=~(1<<PINB0);
-       DDRB|=(1<<PINB0); //stromversorgung
-       
-       // Set up Watch Dog Timer for Inactivity
-       WDTCR |= ((1<<WDCE) | (1<<WDE));   // Enable the WD Change Bit
-       WDTCR =   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
-#endif
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-
-
-       DDRA|=(1<<PINA1); //stromversorgung
-#define SENSON PORTA|=(1<<PINA1);
-#define SENSOFF PORTA&=~(1<<PINA1);
-
-       // Set up Watch Dog Timer for Inactivity
-       WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit
-       WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
-#endif
-
-       
-    uint8_t i;
-       uint8_t err;
-#if  defined(__AVR_ATtiny25__)
-    for(i=0;i<16;i++) pack.bytes[i]=0;
-#else
-       uint8_t pn=1;
-    for(i=0;i<64;i++) pack.bytes[i]=0;
-#endif
-       //pack.bytes[0]=1;
-       //pack.bytes[1]=2;
-       SENSON
-       _delay_ms(4000);
-       err =am2302_1();
-       sei();
-    while(1)   {
-               alarmflag=1;
-               if (am2302_mode==2) {
-                       err=am2302_1();
-                       if (err!=0) {
-#if  defined(__AVR_ATtiny25__)
-#else
-                               pack.page3[pn]=err;
-                               pn=pn+1;if (pn>31) pn=1;
-#endif
-                       }
-                       SENSOFF
-                       am2302_mode=3;
-               }
-               if (am2302_mode>=8) {
-                       am2302_mode=0;
-                       SENSON
-               }
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-//                     CLKPR=(1<<CLKPCE);
-       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/
-                       //PORTB&=~(1<<PINB1);
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-   }
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#define F_CPU 8000000UL\r
+#define FP_CALC\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+\r
+extern void OWINIT();\r
+\r
+\r
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/\r
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+\r
+typedef union {\r
+#if  defined(__AVR_ATtiny25__)\r
+       volatile uint8_t bytes[16];\r
+#else\r
+       volatile uint8_t bytes[64];\r
+#endif\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+#if  defined(__AVR_ATtiny25__)\r
+#else\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+#endif\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+\r
+#define DDR_SENSOR   DDRB \r
+#define PORT_SENSOR  PORTB\r
+#define PIN_SENSOR   PINB\r
+#define SENSOR       PB4\r
+#endif\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+#define DDR_SENSOR   DDRA\r
+#define PORT_SENSOR  PORTA\r
+#define PIN_SENSOR   PINA\r
+#define SENSOR       PINA2\r
+#endif\r
+\r
+\r
+\r
+#define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)\r
+#define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup\r
+#define SENSOR_sda_low    PORT_SENSOR &= ~(1 << SENSOR)\r
+#define SENSOR_is_hi                   PIN_SENSOR & (1 << SENSOR)\r
+#define SENSOR_is_low          !(PIN_SENSOR & (1 << SENSOR))\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+uint8_t am_wait(uint8_t _time,uint8_t _signal){\r
+       TCNT1=0;\r
+       while(TCNT1==0);\r
+       if (_signal) \r
+               while((SENSOR_is_hi)&&(TCNT1<_time)) {}\r
+       else\r
+               while((SENSOR_is_low)&&(TCNT1<_time)) {}\r
+        \r
+               if (TCNT1>=_time) {return 1;}\r
+       return 0;\r
+}\r
+\r
+volatile uint8_t am2302_mode=0;        \r
+volatile uint8_t timeout=0;\r
+\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       sleep_disable();          // Disable Sleep on Wakeup\r
+       am2302_mode++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+/*     if (timeout==2) {\r
+               DIS_TIMER;\r
+               EN_OWINT;\r
+               mode=OWM_SLEEP;\r
+       }\r
+       timeout++;*/\r
+       sleep_enable();           // Enable Sleep Mode\r
+\r
+}\r
+\r
+int testSW() {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB|=(1<<PORTB0); //Pullup\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       r=PINB&(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB&=~(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+       \r
+       \r
+}      \r
+       \r
+uint8_t am2302_1() {\r
+       int16_t lam2302_temp;\r
+       uint16_t lam2302_hum;\r
+       uint8_t rSREG;\r
+       uint8_t sensor_data[5];\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+       TCCR1=(1<<CS12); //Clock/8 1µs\r
+#endif\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+       TCCR1B=(1<<CS11); //Clock/8 1µs\r
+#endif\r
+       SENSOR_sda_out;\r
+       SENSOR_sda_low; // MCU start signal\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       SENSOR_sda_in;\r
+       if (am_wait(200,1)) return 2;\r
+\r
+       // AM2302 response signal min: 75us typ:80us max:85us\r
+       if (am_wait(100,0)) return 3;\r
+       if (am_wait(100,1)) return 4;\r
+       \r
+       for(uint8_t i = 0; i < 5; i++)  {\r
+               uint8_t sensor_byte = 0;\r
+               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor\r
+                       if (am_wait(88,0)) return 5;\r
+                       \r
+                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;\r
+                       sensor_byte <<= 1; // add new lower byte\r
+                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0\r
+                               sensor_byte |= 1;\r
+                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us\r
+                       }\r
+               }\r
+               sensor_data[i] = sensor_byte;\r
+       }\r
+\r
+       // checksum\r
+       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])\r
+       {\r
+               // debug output\r
+               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));\r
+               PORTB&=~(1<<PINB0);\r
+               return 7;\r
+       }\r
+       if (!testSW()) {\r
+#ifdef FP_CALC\r
+       double htemp;\r
+       if (sensor_data[2]&0x80) { //min\r
+               sensor_data[2]&=~(0x80);\r
+               htemp=-((sensor_data[2]<<8) + sensor_data[3]);\r
+       } else\r
+               htemp=((sensor_data[2]<<8) + sensor_data[3]);\r
+       double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);\r
+       \r
+       lam2302_hum=0.318*hhum +76;\r
+       lam2302_temp=htemp*25.6;\r
+#else\r
+\r
+       if (sensor_data[2]&0x80) { //minus\r
+               sensor_data[2]&=~(0x80);\r
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);\r
+       } else\r
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);\r
+       \r
+       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);\r
+       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;\r
+       lam2302_hum=lam2302_hum*16/49-h1+80;\r
+       //lam2302_temp=lam2302_temp*128/5;\r
+\r
+       int16_t h2=lam2302_temp%5;\r
+       lam2302_temp=lam2302_temp/5;\r
+       lam2302_temp*=128;\r
+       lam2302_temp+=h2*128/5;\r
+#endif    \r
+       config_info[5]=7;\r
+       }\r
+       else {\r
+               if (sensor_data[2]&0x80) { //minus\r
+                       sensor_data[2]&=~(0x80);\r
+                       lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);\r
+               } else\r
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;;\r
+               \r
+               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);\r
+               config_info[5]=12;\r
+       }\r
+       rSREG=SREG;\r
+       cli();\r
+       am2302_hum=lam2302_hum;\r
+       am2302_temp=lam2302_temp;\r
+       SREG=rSREG;\r
+       return 0;\r
+}\r
+\r
+\r
+uint8_t am2302_2() { //4mhz\r
+       int16_t lam2302_temp;\r
+       uint16_t lam2302_hum;\r
+       uint8_t rSREG;\r
+       uint8_t sensor_data[5];\r
+       #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+       TCCR1=(1<<CS11)|(1<<CS10); //Clock/8 1µs\r
+       #endif\r
+\r
+       #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+       TCCR1B=(1<<CS11); //Clock/8 1µs\r
+       #endif\r
+       SENSOR_sda_out;\r
+       SENSOR_sda_low; // MCU start signal\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       SENSOR_sda_in;\r
+       if (am_wait(200,1)) return 2;\r
+\r
+       // AM2302 response signal min: 75us typ:80us max:85us\r
+       if (am_wait(100,0)) return 3;\r
+       if (am_wait(100,1)) return 4;\r
+       \r
+       for(uint8_t i = 0; i < 5; i++)  {\r
+               uint8_t sensor_byte = 0;\r
+               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor\r
+                       if (am_wait(88,0)) return 5;\r
+                       \r
+                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;\r
+                       sensor_byte <<= 1; // add new lower byte\r
+                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0\r
+                               sensor_byte |= 1;\r
+                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us\r
+                       }\r
+               }\r
+               sensor_data[i] = sensor_byte;\r
+       }\r
+\r
+       // checksum\r
+       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])\r
+       {\r
+               // debug output\r
+               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));\r
+               PORTB&=~(1<<PINB0);\r
+               return 7;\r
+       }\r
+#ifdef FP_CALC\r
+       lam2302_hum=0.318* ((sensor_data[0]<<8) + sensor_data[1])+76;\r
+       if (sensor_data[2]&0x80) { //minus\r
+               sensor_data[2]&=~(0x80);\r
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3])*25.6;\r
+       } else\r
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;\r
+#else\r
+\r
+\r
+       if (sensor_data[2]&0x80) { //minus\r
+               sensor_data[2]&=~(0x80);\r
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);\r
+       } else\r
+       lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);\r
+       \r
+       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);\r
+       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;\r
+       lam2302_hum=lam2302_hum*16/49-h1+80;\r
+       //lam2302_temp=lam2302_temp*128/5;\r
+\r
+       int16_t h2=lam2302_temp%5;\r
+       lam2302_temp=lam2302_temp/5;\r
+       lam2302_temp*=128;\r
+       lam2302_temp+=h2*128/5;\r
+#endif \r
+       \r
+       \r
+       rSREG=SREG;\r
+       cli();\r
+       am2302_hum=lam2302_hum;\r
+       am2302_temp=lam2302_temp;\r
+       SREG=rSREG;\r
+       return 0;\r
+}\r
+\r
+\r
+\r
+int main(void){\r
+    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+       PORTA=0xFF;\r
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+#endif\r
+       OWINIT();\r
+\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       MCUCR &=~(1<<PUD);\r
+       \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+\r
+       PORTB|=(1<<PINB0)|(1<<PINB1)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);\r
+       DDRB|=(1<<PINB1); //DBLINE\r
+#define SENSON PORTB|=(1<<PINB0);\r
+#define SENSOFF PORTB&=~(1<<PINB0);\r
+       DDRB|=(1<<PINB0); //stromversorgung\r
+       \r
+       // Set up Watch Dog Timer for Inactivity\r
+       WDTCR |= ((1<<WDCE) | (1<<WDE));   // Enable the WD Change Bit\r
+       WDTCR =   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds\r
+#endif\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+\r
+\r
+       DDRA|=(1<<PINA1); //stromversorgung\r
+#define SENSON PORTA|=(1<<PINA1);\r
+#define SENSOFF PORTA&=~(1<<PINA1);\r
+\r
+       // Set up Watch Dog Timer for Inactivity\r
+       WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit\r
+       WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds\r
+#endif\r
+\r
+       \r
+    uint8_t i;\r
+       uint8_t err;\r
+#if  defined(__AVR_ATtiny25__)\r
+    for(i=0;i<16;i++) pack.bytes[i]=0;\r
+#else\r
+       uint8_t pn=1;\r
+    for(i=0;i<64;i++) pack.bytes[i]=0;\r
+#endif\r
+       //pack.bytes[0]=1;\r
+       //pack.bytes[1]=2;\r
+       SENSON\r
+       _delay_ms(4000);\r
+       err =am2302_1();\r
+       sei();\r
+    while(1)   {\r
+               alarmflag=1;\r
+               if (am2302_mode==2) {\r
+                       err=am2302_1();\r
+                       if (err!=0) {\r
+#if  defined(__AVR_ATtiny25__)\r
+#else\r
+                               pack.page3[pn]=err;\r
+                               pn=pn+1;if (pn>31) pn=1;\r
+#endif\r
+                       }\r
+                       SENSOFF\r
+                       am2302_mode=3;\r
+               }\r
+               if (am2302_mode>=8) {\r
+                       am2302_mode=0;\r
+                       SENSON\r
+               }\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+//                     CLKPR=(1<<CLKPCE);\r
+       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/\r
+                       //PORTB&=~(1<<PINB1);\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index a182bed..d2fbef2 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/
-uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-volatile uint8_t wdcounter;
-
-
-typedef union {
-
-       volatile uint8_t bytes[64];
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-#define DDR_SENSOR   DDRA
-#define PORT_SENSOR  PORTA
-#define PIN_SENSOR   PINA
-#define SENSOR       PINA2
-
-#define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)
-#define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup
-#define SENSOR_sda_low    PORT_SENSOR &= ~(1 << SENSOR)
-#define SENSOR_is_hi                   PIN_SENSOR & (1 << SENSOR)
-#define SENSOR_is_low          !(PIN_SENSOR & (1 << SENSOR))
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-uint8_t am_wait(uint8_t _time,uint8_t _signal){
-       TCNT1=0;
-       while(TCNT1==0);
-       if (_signal)
-       while((SENSOR_is_hi)&&(TCNT1<_time)) {}
-       else
-       while((SENSOR_is_low)&&(TCNT1<_time)) {}
-       
-       if (TCNT1>=_time) {return 1;}
-       return 0;
-}
-
-volatile uint8_t am2302_mode=0;
-volatile uint8_t timeout=0;
-
-
-
-
-
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-       #else
-ISR(WDT_vect) {
-       #endif
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-}
-       
-int testSW(void) {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-       __asm__ __volatile__ ("nop");
-       PORTB|=(1<<PORTB0); //Pullup
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       __asm__ __volatile__ ("nop");
-       r=PINB&(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       PORTB&=~(1<<PORTB0);
-       __asm__ __volatile__ ("nop");
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-}
-
-uint8_t am2302() {
-       int16_t lam2302_temp;
-       uint16_t lam2302_hum;
-       uint8_t rSREG;
-       uint8_t sensor_data[5];
-
-       TCCR1B=(1<<CS11); //Clock/8 1µs
-
-       SENSOR_sda_out;
-       SENSOR_sda_low; // MCU start signal
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
-       SENSOR_sda_in;
-       if (am_wait(200,1)) return 2;
-
-       // AM2302 response signal min: 75us typ:80us max:85us or 500us different types
-       if (am_wait(100,0)) return 3;
-       if (am_wait(100,1)) return 4;
-       
-       for(uint8_t i = 0; i < 5; i++)  {
-               uint8_t sensor_byte = 0;
-               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
-                       if (am_wait(88,0)) return 5;
-                       
-                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
-                       sensor_byte <<= 1; // add new lower byte
-                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
-                               sensor_byte |= 1;
-                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
-                       }
-               }
-               sensor_data[i] = sensor_byte;
-       }
-
-       // checksum
-       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
-       {
-               PORTB&=~(1<<PINB0);
-               return 7;
-       }
-       if (sensor_data[2]&0x80) { //minus
-               sensor_data[2]&=~(0x80);
-               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
-       } else
-               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
-       if (!testSW()) {
-               double htemp=lam2302_temp;
-        double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);
-               //htemp=Temperauter * 10 
-               //lam2302_hum=0.318*hhum +76;
-               lam2302_hum=0.31*hhum +80; //hhum = Hum*10 -> 5V also all *5
-               config_info[5]=7;
-       }
-       else {
-               
-               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
-               config_info[5]=12;
-       }
-       lam2302_temp=lam2302_temp*25.6;
-       rSREG=SREG;
-       cli();
-       am2302_hum=lam2302_hum;
-       am2302_temp=lam2302_temp;
-       SREG=rSREG;
-       return 0;
-}
-
-
-
-
-
-
-
-
-       int main(void){
-               PRR|=(1<<PRUSI)|(1<<PRADC);   // adc and usi for save Power
-               PORTA=0xFF;
-               PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-               DDRB|=(1<<PORTB0); //Als Ausgang und 0
-               
-               
-               OWINIT();
-
-               ACSR|=(1<<ACD);  //Disable Comparator
-               ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-               MCUCR &=~(1<<PUD); //All Pins Pullup...
-               MCUCR |=(1<<BODS);
-
-               
-               DDRA|=(1<<PINA1); //stromversorgung
-#define SENSON PORTA|=(1<<PINA1);
-#define SENSOFF PORTA&=~(1<<PINA1);
-
-               // Set up Watch Dog Timer for Inactivity
-               WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit
-               WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt
-                       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds           
-               
-               if (testSW()) {
-                       config_info[5]=12;  //hum *10
-                       }else{
-                       config_info[5]=7; //HIH4031
-               }
-               
-               uint8_t i;
-               for(i=0;i<64;i++) pack.bytes[i]=0;
-               MCUSR=0;
-               
-               uint8_t err;
-               uint8_t pn=1;
-               SENSON
-               _delay_ms(4000);
-               err =am2302();
-               
-               sei();
-               
-               while(1)   {
-                       if (gcontrol) {
-                               if (wdcounter>2) {
-                                       wdcounter=0;
-                                       SENSON
-                               }
-                               gcontrol=0;
-                       }
-                       if (wdcounter==2) {
-                               err=am2302();
-                               if (err!=0) {
-                                       pack.page3[pn]=err;
-                                       pn=pn+1;if (pn>31) pn=1;
-                               }
-                               SENSOFF
-                               wdcounter=3;
-                       }
-                       if (wdcounter>=16) {
-                               wdcounter=0;
-                               SENSON
-                       }
-                       
-                       
-
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
-                               MCUCR|=(1<<SE)|(1<<SM1);
-                               MCUCR&=~(1<<ISC01);
-                               } else {
-                               MCUCR|=(1<<SE);
-                               MCUCR&=~(1<<SM1);
-                       }
-                       asm("SLEEP");
-               }
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/\r
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+\r
+typedef union {\r
+\r
+       volatile uint8_t bytes[64];\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+#define DDR_SENSOR   DDRA\r
+#define PORT_SENSOR  PORTA\r
+#define PIN_SENSOR   PINA\r
+#define SENSOR       PINA2\r
+\r
+#define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)\r
+#define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup\r
+#define SENSOR_sda_low    PORT_SENSOR &= ~(1 << SENSOR)\r
+#define SENSOR_is_hi                   PIN_SENSOR & (1 << SENSOR)\r
+#define SENSOR_is_low          !(PIN_SENSOR & (1 << SENSOR))\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+uint8_t am_wait(uint8_t _time,uint8_t _signal){\r
+       TCNT1=0;\r
+       while(TCNT1==0);\r
+       if (_signal)\r
+       while((SENSOR_is_hi)&&(TCNT1<_time)) {}\r
+       else\r
+       while((SENSOR_is_low)&&(TCNT1<_time)) {}\r
+       \r
+       if (TCNT1>=_time) {return 1;}\r
+       return 0;\r
+}\r
+\r
+volatile uint8_t am2302_mode=0;\r
+volatile uint8_t timeout=0;\r
+\r
+\r
+\r
+\r
+\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+       #else\r
+ISR(WDT_vect) {\r
+       #endif\r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+}\r
+       \r
+int testSW(void) {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB|=(1<<PORTB0); //Pullup\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       __asm__ __volatile__ ("nop");\r
+       r=PINB&(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       PORTB&=~(1<<PORTB0);\r
+       __asm__ __volatile__ ("nop");\r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+}\r
+\r
+uint8_t am2302() {\r
+       int16_t lam2302_temp;\r
+       uint16_t lam2302_hum;\r
+       uint8_t rSREG;\r
+       uint8_t sensor_data[5];\r
+\r
+       TCCR1B=(1<<CS11); //Clock/8 1µs\r
+\r
+       SENSOR_sda_out;\r
+       SENSOR_sda_low; // MCU start signal\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)\r
+       SENSOR_sda_in;\r
+       if (am_wait(200,1)) return 2;\r
+\r
+       // AM2302 response signal min: 75us typ:80us max:85us or 500us different types\r
+       if (am_wait(100,0)) return 3;\r
+       if (am_wait(100,1)) return 4;\r
+       \r
+       for(uint8_t i = 0; i < 5; i++)  {\r
+               uint8_t sensor_byte = 0;\r
+               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor\r
+                       if (am_wait(88,0)) return 5;\r
+                       \r
+                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;\r
+                       sensor_byte <<= 1; // add new lower byte\r
+                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0\r
+                               sensor_byte |= 1;\r
+                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us\r
+                       }\r
+               }\r
+               sensor_data[i] = sensor_byte;\r
+       }\r
+\r
+       // checksum\r
+       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])\r
+       {\r
+               PORTB&=~(1<<PINB0);\r
+               return 7;\r
+       }\r
+       if (sensor_data[2]&0x80) { //minus\r
+               sensor_data[2]&=~(0x80);\r
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);\r
+       } else\r
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);\r
+       if (!testSW()) {\r
+               double htemp=lam2302_temp;\r
+        double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);\r
+               //htemp=Temperauter * 10 \r
+               //lam2302_hum=0.318*hhum +76;\r
+               lam2302_hum=0.31*hhum +80; //hhum = Hum*10 -> 5V also all *5\r
+               config_info[5]=7;\r
+       }\r
+       else {\r
+               \r
+               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);\r
+               config_info[5]=12;\r
+       }\r
+       lam2302_temp=lam2302_temp*25.6;\r
+       rSREG=SREG;\r
+       cli();\r
+       am2302_hum=lam2302_hum;\r
+       am2302_temp=lam2302_temp;\r
+       SREG=rSREG;\r
+       return 0;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       int main(void){\r
+               PRR|=(1<<PRUSI)|(1<<PRADC);   // adc and usi for save Power\r
+               PORTA=0xFF;\r
+               PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+               DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+               \r
+               \r
+               OWINIT();\r
+\r
+               ACSR|=(1<<ACD);  //Disable Comparator\r
+               ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+               MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+               MCUCR |=(1<<BODS);\r
+\r
+               \r
+               DDRA|=(1<<PINA1); //stromversorgung\r
+#define SENSON PORTA|=(1<<PINA1);\r
+#define SENSOFF PORTA&=~(1<<PINA1);\r
+\r
+               // Set up Watch Dog Timer for Inactivity\r
+               WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit\r
+               WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt\r
+                       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds           \r
+               \r
+               if (testSW()) {\r
+                       config_info[5]=12;  //hum *10\r
+                       }else{\r
+                       config_info[5]=7; //HIH4031\r
+               }\r
+               \r
+               uint8_t i;\r
+               for(i=0;i<64;i++) pack.bytes[i]=0;\r
+               MCUSR=0;\r
+               \r
+               uint8_t err;\r
+               uint8_t pn=1;\r
+               SENSON\r
+               _delay_ms(4000);\r
+               err =am2302();\r
+               \r
+               sei();\r
+               \r
+               while(1)   {\r
+                       if (gcontrol) {\r
+                               if (wdcounter>2) {\r
+                                       wdcounter=0;\r
+                                       SENSON\r
+                               }\r
+                               gcontrol=0;\r
+                       }\r
+                       if (wdcounter==2) {\r
+                               err=am2302();\r
+                               if (err!=0) {\r
+                                       pack.page3[pn]=err;\r
+                                       pn=pn+1;if (pn>31) pn=1;\r
+                               }\r
+                               SENSOFF\r
+                               wdcounter=3;\r
+                       }\r
+                       if (wdcounter>=16) {\r
+                               wdcounter=0;\r
+                               SENSON\r
+                       }\r
+                       \r
+                       \r
+\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {\r
+                               MCUCR|=(1<<SE)|(1<<SM1);\r
+                               MCUCR&=~(1<<ISC01);\r
+                               } else {\r
+                               MCUCR|=(1<<SE);\r
+                               MCUCR&=~(1<<SM1);\r
+                       }\r
+                       asm("SLEEP");\r
+               }\r
+\r
+\r
        }
\ No newline at end of file
index 93b2372..cf7d407 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2438_DHT22</AssemblyName>
-    <Name>DS2438_DHT22</Name>
-    <RootNamespace>DS2438_DHT22</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <ExternalProgrammingToolCommand />
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000789</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>NDEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="..\common\OWDS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS2438.S</Link>
-    </Compile>
-    <Compile Include="DS2438_DHT22.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2438_DHT22</AssemblyName>\r
+    <Name>DS2438_DHT22</Name>\r
+    <RootNamespace>DS2438_DHT22</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <ExternalProgrammingToolCommand />\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000789</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>NDEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="..\common\OWDS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS2438_DHT22.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 35bc463..a7d92fa 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-//#define _DIS_FLASH_
-#define _ZERO_POLLING_
-//#define _DB_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC8.s"
-
-#if  defined(__AVR_ATtiny25__)
-.extern pack,16
-#else
-.extern pack,64
-#endif
-.extern  am2302_temp,2
-.extern  am2302_hum,2
-.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
-
-
-.macro CHIP_INIT
-.endm
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0
-#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1
-#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2
-#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3
-
-
-
-.macro COMMAND_TABLE
-               rjmp h_readscratchpad_adr
-               rjmp h_readscratchpad
-               rjmp h_writescratchpad_adr
-               rjmp h_writescratchpad
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0xBE,OW_READ_SCRATCHPAD_ADR
-       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR
-       cjmp 0x44,hrc_set_convertT
-       cjmp 0xB4,hrc_set_convertV
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       rjmp handle_end_sleep
-
-
-hrc_set_convertT:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-       lds r_temp,am2302_temp
-       sts pack+1,r_temp
-       lds r_temp,am2302_temp+1
-       sts pack+2,r_temp
-       rjmp handle_end_sleep
-hrc_set_convertV:
-       ldi r_temp,2
-       sts gcontrol,r_temp
-       lds r_temp,pack
-       sbrs r_temp,3
-       rjmp hrc_set_convertVV
-       ldi r_temp,0xF4
-       sts pack+3,r_temp
-       ldi r_temp,0x01
-       sts pack+4,r_temp
-       rjmp hrc_set_convertend
-hrc_set_convertVV:
-       lds r_temp,am2302_hum
-       sts pack+3,r_temp
-       lds r_temp,am2302_hum+1
-       sts pack+4,r_temp
-hrc_set_convertend:
-       rjmp handle_end_sleep
-
-
-
-;---------------------------------------------------
-;   READ SCRATCHPAD
-;---------------------------------------------------
-
-h_readscratchpad_adr:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_sendflag,1
-       ldi r_mode,OW_READ_SCRATCHPAD
-       CRCInit2
-h_readscratchpad:
-       cpi  r_bytep,8
-       breq h_readscratchpad_crc
-       cpi  r_bytep,9
-       breq h_readscratchpad_all
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack,r_temp
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_crc:
-       lds  r_rwbyte,crc
-       rjmp handle_end_inc
-h_readscratchpad_all:
-       rjmp handle_end_sleep
-
-
-
-
-;---------------------------------------------------
-;   WRITE SCRATCHPAD
-;---------------------------------------------------
-h_writescratchpad_adr:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_mode,OW_WRITE_SCRATCHPAD
-       ldi  r_bcount,1 
-       rjmp handle_end 
-h_writescratchpad:
-       cpi  r_bytep,8
-       breq h_writescratchpad_all
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack,r_temp
-       st   Z,r_rwbyte
-       rjmp handle_end_inc
-h_writescratchpad_all:
-       rjmp handle_end_sleep
-
-
-
-
-
-#include "../common/OWPinInterrupt.s"
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+//#define _DIS_FLASH_\r
+#define _ZERO_POLLING_\r
+//#define _DB_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC8.s"\r
+\r
+#if  defined(__AVR_ATtiny25__)\r
+.extern pack,16\r
+#else\r
+.extern pack,64\r
+#endif\r
+.extern  am2302_temp,2\r
+.extern  am2302_hum,2\r
+.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)\r
+\r
+\r
+.macro CHIP_INIT\r
+.endm\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0\r
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1\r
+#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2\r
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3\r
+\r
+\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readscratchpad_adr\r
+               rjmp h_readscratchpad\r
+               rjmp h_writescratchpad_adr\r
+               rjmp h_writescratchpad\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0xBE,OW_READ_SCRATCHPAD_ADR\r
+       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR\r
+       cjmp 0x44,hrc_set_convertT\r
+       cjmp 0xB4,hrc_set_convertV\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_set_convertT:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+       lds r_temp,am2302_temp\r
+       sts pack+1,r_temp\r
+       lds r_temp,am2302_temp+1\r
+       sts pack+2,r_temp\r
+       rjmp handle_end_sleep\r
+hrc_set_convertV:\r
+       ldi r_temp,2\r
+       sts gcontrol,r_temp\r
+       lds r_temp,pack\r
+       sbrs r_temp,3\r
+       rjmp hrc_set_convertVV\r
+       ldi r_temp,0xF4\r
+       sts pack+3,r_temp\r
+       ldi r_temp,0x01\r
+       sts pack+4,r_temp\r
+       rjmp hrc_set_convertend\r
+hrc_set_convertVV:\r
+       lds r_temp,am2302_hum\r
+       sts pack+3,r_temp\r
+       lds r_temp,am2302_hum+1\r
+       sts pack+4,r_temp\r
+hrc_set_convertend:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_readscratchpad_adr:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_sendflag,1\r
+       ldi r_mode,OW_READ_SCRATCHPAD\r
+       CRCInit2\r
+h_readscratchpad:\r
+       cpi  r_bytep,8\r
+       breq h_readscratchpad_crc\r
+       cpi  r_bytep,9\r
+       breq h_readscratchpad_all\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack,r_temp\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readscratchpad_crc:\r
+       lds  r_rwbyte,crc\r
+       rjmp handle_end_inc\r
+h_readscratchpad_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   WRITE SCRATCHPAD\r
+;---------------------------------------------------\r
+h_writescratchpad_adr:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_mode,OW_WRITE_SCRATCHPAD\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end \r
+h_writescratchpad:\r
+       cpi  r_bytep,8\r
+       breq h_writescratchpad_all\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack,r_temp\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end_inc\r
+h_writescratchpad_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 453b0e3..467ae24 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_HIH9121", "DS2438_HIH9121.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_HIH9121", "DS2438_HIH9121.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index a7e115c..6c59d8c 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX44009.h"
-#include "../common/I2C/SHT2x.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/
-uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-volatile uint8_t wdcounter;
-
-
-typedef union {
-
-       volatile uint8_t bytes[64];
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-
-
-}
-
-int testSW(void) {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-        __asm__ __volatile__ ("nop"); 
-        PORTB|=(1<<PORTB0); //Pullup
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        r=PINB&(1<<PORTB0);
-        __asm__ __volatile__ ("nop");  
-        PORTB&=~(1<<PORTB0); 
-        __asm__ __volatile__ ("nop"); 
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-        
-        
-}
-
-int main(void){
-     PRR|=(1<<PRADC);  // adc for save Power
-       PORTA=0xFF;
-       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-       DDRB|=(1<<PORTB0); //Als Ausgang und 0
-       
-       
-       OWINIT();
-
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-        if (testSW()) {
-               config_info[5]=8;
-       }else{
-               config_info[5]=7;
-        }
-       
-    uint8_t i;
-    for(i=0;i<64;i++) pack.bytes[i]=0;
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       volatile uint16_t res,res1;
-       I2c_StartCondition();
-       I2c_WriteByte (0b01001110);
-       I2c_StopCondition();
-       _delay_us(100);
-       
-       I2c_StartCondition();
-       I2c_WriteByte (0b01001111);
-       _delay_us(80);
-       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;
-       res|=I2c_ReadByte(ACK);
-       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;
-       res1|=I2c_ReadByte(NO_ACK)>>2;
-
-       I2c_StopCondition();
-       temperatureC=res1/16382.0*160.0-40.0;
-       humidityRH=res/16382.0*100.0;
-       //temperatureC = SHT2x_CalcTemperatureC(sT);
-       //humidityRH = SHT2x_CalcRH(sRH);
-       
-       sei();
-       
-        while(1)   {
-                if (gcontrol) {
-                        wdcounter=3;
-                        gcontrol=0;
-                }
-                if (wdcounter>2) {
-                        I2c_StartCondition();
-                       I2c_WriteByte (0b01001110);
-                       I2c_StopCondition();
-                       _delay_us(100);
-                       I2c_StartCondition();
-                       I2c_WriteByte (0b01001111);
-                       _delay_us(80);
-                       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;
-                       res|=I2c_ReadByte(ACK);
-                       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;
-                       res1|=I2c_ReadByte(NO_ACK)>>2;
-
-                       I2c_StopCondition();
-                       temperatureC=res1/16382.0*1650.0-400.0;
-                       humidityRH=res/16382.0*1000.0;
-
-                        if (testSW()) {
-                                am2302_hum= humidityRH*10.0;
-                                am2302_temp=temperatureC*25.6;
-                                //am2302_temp=am2302_temp-45;
-                                config_info[5]=8;      
-                                
-                        }else{
-                                
-                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                               //am2302_hum=0.318*hhum +76.0;
-                               am2302_hum=0.31*hhum +80;
-                               am2302_temp=temperatureC*25.6;
-                               //am2302_temp=am2302_temp-45;
-                               config_info[5]=7;
-                        }
-                        //PORTB&=~(1<<PINB1);
-                        wdcounter=0;
-                }
-
-               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-       }
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX44009.h"\r
+#include "../common/I2C/SHT2x.h"\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/\r
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+volatile uint8_t wdcounter;\r
+\r
+\r
+typedef union {\r
+\r
+       volatile uint8_t bytes[64];\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+\r
+\r
+}\r
+\r
+int testSW(void) {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+        __asm__ __volatile__ ("nop"); \r
+        PORTB|=(1<<PORTB0); //Pullup\r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        r=PINB&(1<<PORTB0);\r
+        __asm__ __volatile__ ("nop");  \r
+        PORTB&=~(1<<PORTB0); \r
+        __asm__ __volatile__ ("nop"); \r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+        \r
+        \r
+}\r
+\r
+int main(void){\r
+     PRR|=(1<<PRADC);  // adc for save Power\r
+       PORTA=0xFF;\r
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+       \r
+       \r
+       OWINIT();\r
+\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       \r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+        if (testSW()) {\r
+               config_info[5]=8;\r
+       }else{\r
+               config_info[5]=7;\r
+        }\r
+       \r
+    uint8_t i;\r
+    for(i=0;i<64;i++) pack.bytes[i]=0;\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       volatile uint16_t res,res1;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b01001110);\r
+       I2c_StopCondition();\r
+       _delay_us(100);\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b01001111);\r
+       _delay_us(80);\r
+       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;\r
+       res|=I2c_ReadByte(ACK);\r
+       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;\r
+       res1|=I2c_ReadByte(NO_ACK)>>2;\r
+\r
+       I2c_StopCondition();\r
+       temperatureC=res1/16382.0*160.0-40.0;\r
+       humidityRH=res/16382.0*100.0;\r
+       //temperatureC = SHT2x_CalcTemperatureC(sT);\r
+       //humidityRH = SHT2x_CalcRH(sRH);\r
+       \r
+       sei();\r
+       \r
+        while(1)   {\r
+                if (gcontrol) {\r
+                        wdcounter=3;\r
+                        gcontrol=0;\r
+                }\r
+                if (wdcounter>2) {\r
+                        I2c_StartCondition();\r
+                       I2c_WriteByte (0b01001110);\r
+                       I2c_StopCondition();\r
+                       _delay_us(100);\r
+                       I2c_StartCondition();\r
+                       I2c_WriteByte (0b01001111);\r
+                       _delay_us(80);\r
+                       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;\r
+                       res|=I2c_ReadByte(ACK);\r
+                       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;\r
+                       res1|=I2c_ReadByte(NO_ACK)>>2;\r
+\r
+                       I2c_StopCondition();\r
+                       temperatureC=res1/16382.0*1650.0-400.0;\r
+                       humidityRH=res/16382.0*1000.0;\r
+\r
+                        if (testSW()) {\r
+                                am2302_hum= humidityRH*10.0;\r
+                                am2302_temp=temperatureC*25.6;\r
+                                //am2302_temp=am2302_temp-45;\r
+                                config_info[5]=8;      \r
+                                \r
+                        }else{\r
+                                \r
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                               //am2302_hum=0.318*hhum +76.0;\r
+                               am2302_hum=0.31*hhum +80;\r
+                               am2302_temp=temperatureC*25.6;\r
+                               //am2302_temp=am2302_temp-45;\r
+                               config_info[5]=7;\r
+                        }\r
+                        //PORTB&=~(1<<PINB1);\r
+                        wdcounter=0;\r
+                }\r
+\r
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+       }\r
+\r
+\r
 }
\ No newline at end of file
index eb00b22..5933d2f 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2438_SHT2X</AssemblyName>
-    <Name>DS2438_HIH9121</Name>
-    <RootNamespace>DS2438_SHT2X</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS2438.S</Link>
-    </Compile>
-    <Compile Include="DS2438_HIH9121.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2438_SHT2X</AssemblyName>\r
+    <Name>DS2438_HIH9121</Name>\r
+    <RootNamespace>DS2438_SHT2X</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS2438_HIH9121.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 1a91fb0..9a19423 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_SHT2X", "DS2438_SHT2X.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR
-               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_SHT2X", "DS2438_SHT2X.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR\r
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index dddca10..0da9838 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX44009.h"
-#include "../common/I2C/SHT2x.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/
-uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-       
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-volatile uint8_t wdcounter=5;
-
-
-typedef union {
-
-       volatile uint8_t bytes[64];
-       struct {
-               uint8_t status;  //1
-               int16_t temp;  //2
-               uint16_t voltage;  //4
-               uint16_t current;  //6
-               uint8_t threshold; //8
-               
-               uint8_t page1[8]; //9
-               uint8_t page2[8]; //17
-               uint8_t page3[8]; //25
-               uint8_t page4[8];  //33
-               uint8_t page5[8];  //41
-               uint8_t page6[8];  //49
-               uint8_t page7[8];  //57
-               //uint8_t crc;  //65
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-
-
-}
-
-int testSW(void) {
-       uint8_t r;
-       DDRB&=~(1<<PORTB0);  //Eingang
-        __asm__ __volatile__ ("nop"); 
-        PORTB|=(1<<PORTB0); //Pullup
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        __asm__ __volatile__ ("nop"); 
-        r=PINB&(1<<PORTB0);
-        __asm__ __volatile__ ("nop"); 
-        PORTB&=~(1<<PORTB0); 
-        __asm__ __volatile__ ("nop"); 
-       DDRB|=(1<<PORTB0);  //Eingang
-       return (r==0);
-        
-        
-}
-
-int main(void){
-     PRR|=(1<<PRADC);  // adc for save Power
-       PORTA=0xFF;
-       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-       DDRB|=(1<<PORTB0); //Als Ausgang und 0
-       
-       
-       OWINIT();
-
-       ACSR|=(1<<ACD);  //Disable Comparator
-       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-
-       
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-        if (testSW()) {
-               config_info[5]=8;
-       }else{
-               config_info[5]=7;
-        }
-       
-    uint8_t i;
-    for(i=0;i<64;i++) pack.bytes[i]=0;
-       MCUSR=0;
-       USI_TWI_Master_Initialise();
-       SHT2x_SoftReset();
-       SHT2x_ReadUserRegister(userRegister);
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg
-       // --- measure humidity with "Hold Master Mode (HM)" ---
-       SHT2x_MeasurePoll(HUMIDITY, &sRH);
-       // --- measure temperature with "Polling Mode" (no hold master) ---
-       SHT2x_MeasurePoll(TEMP, &sT);
-       //-- calculate humidity and temperature --
-       temperatureC = SHT2x_CalcTemperatureC(sT);
-       humidityRH = SHT2x_CalcRH(sRH);
-       
-       sei();
-       
-        while(1)   {
-                if (gcontrol) {
-                        wdcounter=3;
-                        gcontrol=0;
-                }
-                if (wdcounter>2) {
-                        //PORTB|=(1<<PINB1); //Dauer 440ms
-                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
-                        // --- measure temperature with "Polling Mode" (no hold master) ---
-                        SHT2x_MeasurePoll(TEMP, &sT);
-                        //-- calculate humidity and temperature --
-                        temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
-                        humidityRH = SHT2x_CalcRH(sRH)*10.0;
-                        if (testSW()) {
-                                am2302_hum= humidityRH*10.0;
-                                am2302_temp=temperatureC*25.6;
-                                //am2302_temp=am2302_temp-45;
-                                config_info[5]=8;      
-                                
-                        }else{
-                                
-                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                               //am2302_hum=0.318*hhum +76.0;
-                               am2302_hum=0.31*hhum +80;
-                               am2302_temp=temperatureC*25.6;
-                               //am2302_temp=am2302_temp-45;
-                               config_info[5]=7;
-                        }
-                        //PORTB&=~(1<<PINB1);
-                        wdcounter=0;
-                }
-
-               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-               asm("SLEEP");
-       }
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX44009.h"\r
+#include "../common/I2C/SHT2x.h"\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/\r
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+       \r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+volatile uint8_t wdcounter=5;\r
+\r
+\r
+typedef union {\r
+\r
+       volatile uint8_t bytes[64];\r
+       struct {\r
+               uint8_t status;  //1\r
+               int16_t temp;  //2\r
+               uint16_t voltage;  //4\r
+               uint16_t current;  //6\r
+               uint8_t threshold; //8\r
+               \r
+               uint8_t page1[8]; //9\r
+               uint8_t page2[8]; //17\r
+               uint8_t page3[8]; //25\r
+               uint8_t page4[8];  //33\r
+               uint8_t page5[8];  //41\r
+               uint8_t page6[8];  //49\r
+               uint8_t page7[8];  //57\r
+               //uint8_t crc;  //65\r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+\r
+\r
+}\r
+\r
+int testSW(void) {\r
+       uint8_t r;\r
+       DDRB&=~(1<<PORTB0);  //Eingang\r
+        __asm__ __volatile__ ("nop"); \r
+        PORTB|=(1<<PORTB0); //Pullup\r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        __asm__ __volatile__ ("nop"); \r
+        r=PINB&(1<<PORTB0);\r
+        __asm__ __volatile__ ("nop"); \r
+        PORTB&=~(1<<PORTB0); \r
+        __asm__ __volatile__ ("nop"); \r
+       DDRB|=(1<<PORTB0);  //Eingang\r
+       return (r==0);\r
+        \r
+        \r
+}\r
+\r
+int main(void){\r
+     PRR|=(1<<PRADC);  // adc for save Power\r
+       PORTA=0xFF;\r
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+       \r
+       \r
+       OWINIT();\r
+\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+\r
+       \r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+        if (testSW()) {\r
+               config_info[5]=8;\r
+       }else{\r
+               config_info[5]=7;\r
+        }\r
+       \r
+    uint8_t i;\r
+    for(i=0;i<64;i++) pack.bytes[i]=0;\r
+       MCUSR=0;\r
+       USI_TWI_Master_Initialise();\r
+       SHT2x_SoftReset();\r
+       SHT2x_ReadUserRegister(userRegister);\r
+       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
+       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
+       // --- measure humidity with "Hold Master Mode (HM)" ---\r
+       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+       SHT2x_MeasurePoll(TEMP, &sT);\r
+       //-- calculate humidity and temperature --\r
+       temperatureC = SHT2x_CalcTemperatureC(sT);\r
+       humidityRH = SHT2x_CalcRH(sRH);\r
+       \r
+       sei();\r
+       \r
+        while(1)   {\r
+                if (gcontrol) {\r
+                        wdcounter=3;\r
+                        gcontrol=0;\r
+                }\r
+                if (wdcounter>2) {\r
+                        //PORTB|=(1<<PINB1); //Dauer 440ms\r
+                        SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+                        // --- measure temperature with "Polling Mode" (no hold master) ---\r
+                        SHT2x_MeasurePoll(TEMP, &sT);\r
+                        //-- calculate humidity and temperature --\r
+                        temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;\r
+                        humidityRH = SHT2x_CalcRH(sRH)*10.0;\r
+                        if (testSW()) {\r
+                                am2302_hum= humidityRH*10.0;\r
+                                am2302_temp=temperatureC*25.6;\r
+                                //am2302_temp=am2302_temp-45;\r
+                                config_info[5]=8;      \r
+                                \r
+                        }else{\r
+                                \r
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                               //am2302_hum=0.318*hhum +76.0;\r
+                               am2302_hum=0.31*hhum +80;\r
+                               am2302_temp=temperatureC*25.6;\r
+                               //am2302_temp=am2302_temp-45;\r
+                               config_info[5]=7;\r
+                        }\r
+                        //PORTB&=~(1<<PINB1);\r
+                        wdcounter=0;\r
+                }\r
+\r
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+               asm("SLEEP");\r
+       }\r
+\r
+\r
 }
\ No newline at end of file
index 7262f23..0bdb091 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2438_SHT2X</AssemblyName>
-    <Name>DS2438_SHT2X</Name>
-    <RootNamespace>DS2438_SHT2X</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">
-      <SubType>compile</SubType>
-      <Link>SHT2x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">
-      <SubType>compile</SubType>
-      <Link>OWDS2438.S</Link>
-    </Compile>
-    <Compile Include="DS2438_SHT2X.c">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2438_SHT2X</AssemblyName>\r
+    <Name>DS2438_SHT2X</Name>\r
+    <RootNamespace>DS2438_SHT2X</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>SHT2x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">\r
+      <SubType>compile</SubType>\r
+      <Link>OWDS2438.S</Link>\r
+    </Compile>\r
+    <Compile Include="DS2438_SHT2X.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index 848bac3..09276c9 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450", "DS2450.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450", "DS2450.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 3567ab2..cf4e588 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/
-uint8_t config_info[16]={0x06,0x09,0x06,0x09,0x06,0x09,0x06,0x09,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-typedef union {
-       volatile uint8_t bytes[0x20];
-       struct {
-               //Page0
-               uint16_t A;  //0
-               uint16_t B;  //2
-               uint16_t C;  //4
-               uint16_t D;  //6
-               //Page1
-               uint8_t CSA1;
-               uint8_t CSA2;
-               uint8_t CSB1;
-               uint8_t CSB2;
-               uint8_t CSC1;
-               uint8_t CSC2;
-               uint8_t CSD1;
-               uint8_t CSD2;
-               //Page2
-               uint8_t LA;
-               uint8_t HA;
-               uint8_t LB;
-               uint8_t HB;
-               uint8_t LC;
-               uint8_t HC;
-               uint8_t LD;
-               uint8_t HD;
-               //Page3
-               uint8_t FC1;
-               uint8_t FC2;
-               uint8_t FC3;
-               uint8_t FC4;
-               uint8_t VCCP;
-               uint8_t FC5;
-               uint8_t FC6;
-               uint8_t FC7;
-               uint8_t convc1;
-               uint8_t convc2;
-               
-               
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-
-
-
-int main(void){
-       pack.A=0;
-       pack.B=0;
-       pack.C=0;
-       pack.D=0;
-       pack.CSA1=0x08;
-       pack.CSA2=0x8C;
-       pack.CSB1=0x08;
-       pack.CSB2=0x8C;
-       pack.CSC1=0x08;
-       pack.CSC2=0x8C;
-       pack.CSD1=0x08;
-       pack.CSD2=0x8C;
-       pack.HA=0xFF;
-       pack.LA=0x00;
-       pack.HB=0xFF;
-       pack.LB=0x00;
-       pack.HC=0xFF;
-       pack.LC=0x00;
-       pack.HD=0xFF;
-       pack.LD=0x00;
-       pack.VCCP=0;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));
-       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);
-
-       
-       
-       gcontrol=1;
-       ADCSRB|=(1<<ADLAR); 
-       sei();
-       
-       //DDRB|=(1<<PINB1);
-
-    while(1)   {
-
-
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1);
-                       uint8_t bb=1;
-                       uint8_t bb1=1;
-                       for(uint8_t i=0;i<4;i++){
-                               if (pack.convc1&bb1) {
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}
-                                       bb=bb<<1;
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}
-                                       bb=bb<<1;
-                               } else bb=bb<<2;
-                               bb1=bb1<<1;                             
-                       }
-                       //CHanel A
-                       if (pack.convc1&1) {
-                               if (pack.CSA2&0x01)     ADMUX=0; else ADMUX=0x80;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.A=ADC;sei();
-                               alarmflag=0;
-                               if (pack.CSA2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}
-                               if (pack.CSA2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}
-                       }
-
-                       if (pack.convc1&2) {
-                               if (pack.CSB2&0x01)     ADMUX=1; else ADMUX=0x81;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.B=ADC;sei();
-                               if (pack.CSB2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}
-                               if (pack.CSB2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}
-                       }
-
-                       if (pack.convc1&4) {
-                               if (pack.CSC2&0x01)     ADMUX=2; else ADMUX=0x82;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.C=ADC;sei();
-                               if (pack.CSC2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}
-                               if (pack.CSC2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}
-                       } 
-                       if (pack.convc1&8) {
-                               if (pack.CSD2&0x01)     ADMUX=3; else ADMUX=0x83;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.D=ADC;sei();
-                               if (pack.CSD2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}
-                               if (pack.CSD2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}
-                       }
-                       
-                       EXTERN_SLEEP();
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               uint8_t bb=1;
-               for(uint8_t i=0;i<4;i++) {
-                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output
-                               if (pack.bytes[8+i*2]&0x40) {
-                                       DDRA|=bb;
-                               } else {
-                                       DDRA&=~bb;
-                               }
-                       } else {
-                               DDRA&=~bb;
-                       }
-                       bb=bb*2;
-               }
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-       //      asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/\r
+uint8_t config_info[16]={0x06,0x09,0x06,0x09,0x06,0x09,0x06,0x09,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[0x20];\r
+       struct {\r
+               //Page0\r
+               uint16_t A;  //0\r
+               uint16_t B;  //2\r
+               uint16_t C;  //4\r
+               uint16_t D;  //6\r
+               //Page1\r
+               uint8_t CSA1;\r
+               uint8_t CSA2;\r
+               uint8_t CSB1;\r
+               uint8_t CSB2;\r
+               uint8_t CSC1;\r
+               uint8_t CSC2;\r
+               uint8_t CSD1;\r
+               uint8_t CSD2;\r
+               //Page2\r
+               uint8_t LA;\r
+               uint8_t HA;\r
+               uint8_t LB;\r
+               uint8_t HB;\r
+               uint8_t LC;\r
+               uint8_t HC;\r
+               uint8_t LD;\r
+               uint8_t HD;\r
+               //Page3\r
+               uint8_t FC1;\r
+               uint8_t FC2;\r
+               uint8_t FC3;\r
+               uint8_t FC4;\r
+               uint8_t VCCP;\r
+               uint8_t FC5;\r
+               uint8_t FC6;\r
+               uint8_t FC7;\r
+               uint8_t convc1;\r
+               uint8_t convc2;\r
+               \r
+               \r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+\r
+\r
+\r
+int main(void){\r
+       pack.A=0;\r
+       pack.B=0;\r
+       pack.C=0;\r
+       pack.D=0;\r
+       pack.CSA1=0x08;\r
+       pack.CSA2=0x8C;\r
+       pack.CSB1=0x08;\r
+       pack.CSB2=0x8C;\r
+       pack.CSC1=0x08;\r
+       pack.CSC2=0x8C;\r
+       pack.CSD1=0x08;\r
+       pack.CSD2=0x8C;\r
+       pack.HA=0xFF;\r
+       pack.LA=0x00;\r
+       pack.HB=0xFF;\r
+       pack.LB=0x00;\r
+       pack.HC=0xFF;\r
+       pack.LC=0x00;\r
+       pack.HD=0xFF;\r
+       pack.LD=0x00;\r
+       pack.VCCP=0;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));\r
+       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);\r
+\r
+       \r
+       \r
+       gcontrol=1;\r
+       ADCSRB|=(1<<ADLAR); \r
+       sei();\r
+       \r
+       //DDRB|=(1<<PINB1);\r
+\r
+    while(1)   {\r
+\r
+\r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1);\r
+                       uint8_t bb=1;\r
+                       uint8_t bb1=1;\r
+                       for(uint8_t i=0;i<4;i++){\r
+                               if (pack.convc1&bb1) {\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}\r
+                                       bb=bb<<1;\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}\r
+                                       bb=bb<<1;\r
+                               } else bb=bb<<2;\r
+                               bb1=bb1<<1;                             \r
+                       }\r
+                       //CHanel A\r
+                       if (pack.convc1&1) {\r
+                               if (pack.CSA2&0x01)     ADMUX=0; else ADMUX=0x80;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.A=ADC;sei();\r
+                               alarmflag=0;\r
+                               if (pack.CSA2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}\r
+                               if (pack.CSA2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&2) {\r
+                               if (pack.CSB2&0x01)     ADMUX=1; else ADMUX=0x81;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.B=ADC;sei();\r
+                               if (pack.CSB2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}\r
+                               if (pack.CSB2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&4) {\r
+                               if (pack.CSC2&0x01)     ADMUX=2; else ADMUX=0x82;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.C=ADC;sei();\r
+                               if (pack.CSC2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}\r
+                               if (pack.CSC2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}\r
+                       } \r
+                       if (pack.convc1&8) {\r
+                               if (pack.CSD2&0x01)     ADMUX=3; else ADMUX=0x83;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.D=ADC;sei();\r
+                               if (pack.CSD2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}\r
+                               if (pack.CSD2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}\r
+                       }\r
+                       \r
+                       EXTERN_SLEEP();\r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               uint8_t bb=1;\r
+               for(uint8_t i=0;i<4;i++) {\r
+                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output\r
+                               if (pack.bytes[8+i*2]&0x40) {\r
+                                       DDRA|=bb;\r
+                               } else {\r
+                                       DDRA&=~bb;\r
+                               }\r
+                       } else {\r
+                               DDRA&=~bb;\r
+                       }\r
+                       bb=bb*2;\r
+               }\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+       //      asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 618c54f..a79f289 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2450</AssemblyName>
-    <Name>DS2450</Name>
-    <RootNamespace>DS2450</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <ExternalProgrammingToolCommand />
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool />
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>NDEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-</AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="DS2450.c">
-      <SubType>compile</SubType>
-    </Compile>
-    <Compile Include="OWDS2450.S">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2450</AssemblyName>\r
+    <Name>DS2450</Name>\r
+    <RootNamespace>DS2450</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <ExternalProgrammingToolCommand />\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool />\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcc.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>NDEBUG</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.symbols.DefSymbols>\r
+  <avrgcc.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.directories.IncludePaths>\r
+  <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>\r
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+  <avrgcc.linker.libraries.Libraries>\r
+    <ListValues>\r
+      <Value>libm</Value>\r
+    </ListValues>\r
+  </avrgcc.linker.libraries.Libraries>\r
+</AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+  <avrgcc.compiler.symbols.DefSymbols>\r
+    <ListValues>\r
+      <Value>DEBUG</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.symbols.DefSymbols>\r
+  <avrgcc.compiler.directories.IncludePaths>\r
+    <ListValues>\r
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+    </ListValues>\r
+  </avrgcc.compiler.directories.IncludePaths>\r
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+  <avrgcc.linker.libraries.Libraries>\r
+    <ListValues>\r
+      <Value>libm</Value>\r
+    </ListValues>\r
+  </avrgcc.linker.libraries.Libraries>\r
+  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+</AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="DS2450.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+    <Compile Include="OWDS2450.S">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index aec56b7..1d81abd 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-#define _ZERO_POLLING_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC16.s"
-
-.extern pack,8
-.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)
-.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....
-//.extern  am2302_temp,2
-
-
-
-.macro CHIP_INIT       
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_readmemoryaddr
-               rjmp h_readmemory
-               rjmp h_readmemorycrc1
-               rjmp h_readmemorycrc2
-               rjmp h_writememoryaddr
-               rjmp h_writememory
-               rjmp h_writememorycrc1
-               rjmp h_writememorycrc2
-               rjmp h_writememoryreadback
-               rjmp h_convert
-               rjmp h_convertcrc1
-               rjmp h_convertcrc2
-               rjmp h_convert_conv
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0
-#define OW_READ_MEMORY OW_FIRST_COMMAND+1
-#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2
-#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3
-#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4
-#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5
-#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6
-#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7
-#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8
-#define OW_CONVERT OW_FIRST_COMMAND+9
-#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10
-#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11
-#define OW_CONVERT_CONV OW_FIRST_COMMAND+12
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0xAA,OW_READ_MEMORY_ADDR
-       cset 0x55,OW_WRITE_MEMORY_ADDR
-       cset 0x3C,OW_CONVERT
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-
-h_readmemoryaddr:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_readmemory_addr_byte1 ;nein dann weiter
-       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
-       sts addr,r_rwbyte  ;speichern des ersten bytes
-       rjmp handle_end_inc
-h_readmemory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
-       ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory
-       ;;ldi r_bcount,1 ;ist unten
-       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
-       clr r_bytep
-       rjmp h_readmemory2
-h_readmemory:
-       lds r_bytep,addr
-       inc r_bytep
-       sts addr,r_bytep
-       andi r_bytep,0x07
-       breq h_readmemory_init_crc
-h_readmemory2:
-       lds r_bytep,addr
-       ;andi r_bytep,0x1F ist oben
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       ;ldi r_bcount,1
-       rjmp handle_end ;sendet das Byte und geht zu h_readmemory
-h_readmemory_init_crc:; init erstes CRC byte
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       ldi r_mode,OW_READ_MEMORY_CRC1
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_readmemory_end:
-       ldi  r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end
-h_readmemorycrc1:;init zweites CRC Byte
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_READ_MEMORY_CRC2
-       rjmp handle_end
-h_readmemorycrc2:;weiteres senden..... nach zweitem Byte
-       lds r_temp,addr
-       andi r_temp,0xE0
-       brne h_readmemory_end; ende des speichers
-       ldi r_mode,OW_READ_MEMORY
-       CRCInit1 ;Start with new CRC
-       rjmp h_readmemory2
-
-h_writememoryaddr:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_writememory_addr_byte1 ;nein dann weiter
-       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
-       sts addr,r_rwbyte  ;speichern des ersten bytes
-       inc r_bytep
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_writememory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
-       ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory
-       ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....
-       lds r_bytep,addr
-       rjmp handle_end ;read Memory Byte
-h_writememory:
-       lds r_bytep,addr
-       configZ pack,r_bytep
-       st Z,r_rwbyte
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_CRC1
-       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       rjmp handle_end
-h_writememorycrc1:
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_CRC2
-       rjmp handle_end
-h_writememorycrc2:
-       lds r_temp,addr
-       configZ pack,r_temp
-       ld r_rwbyte,Z
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_READBACK
-       rjmp handle_end
-h_writememoryreadback:
-       ldi r_temp,0x00
-       sts crc+1,r_temp
-       lds r_temp,addr
-       inc r_temp
-       sts addr,r_temp
-       sts crc,r_temp
-       ldi r_sendflag,0
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY
-       rjmp handle_end
-
-h_convert:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_convert_byte1 ;nein dann weiter
-       inc r_bytep
-       sts pack+0x20,r_rwbyte
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_convert_byte1: ;zweies byte glesen go crc#
-       sts pack+0x21,r_rwbyte
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       ldi r_mode,OW_CONVERT_CRC1
-       ;ldi r_bcount,1
-       ldi r_sendflag,1
-       rjmp handle_end 
-h_convertcrc1:
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_CONVERT_CRC2
-       rjmp handle_end
-h_convertcrc2:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-       ;ldi r_bcount,1
-       ldi r_mode,OW_CONVERT_CONV
-       ;clr r_sendflag
-       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
-h_convert_conv:
-       ldi r_bcount,0
-       ldi r_rwbyte,0
-       rjmp handle_end_no_bcount       
-
-
-
-
-#include "../common/OWPinInterrupt.s"
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+#define _ZERO_POLLING_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC16.s"\r
+\r
+.extern pack,8\r
+.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)\r
+.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....\r
+//.extern  am2302_temp,2\r
+\r
+\r
+\r
+.macro CHIP_INIT       \r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readmemoryaddr\r
+               rjmp h_readmemory\r
+               rjmp h_readmemorycrc1\r
+               rjmp h_readmemorycrc2\r
+               rjmp h_writememoryaddr\r
+               rjmp h_writememory\r
+               rjmp h_writememorycrc1\r
+               rjmp h_writememorycrc2\r
+               rjmp h_writememoryreadback\r
+               rjmp h_convert\r
+               rjmp h_convertcrc1\r
+               rjmp h_convertcrc2\r
+               rjmp h_convert_conv\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0\r
+#define OW_READ_MEMORY OW_FIRST_COMMAND+1\r
+#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2\r
+#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3\r
+#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4\r
+#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5\r
+#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6\r
+#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7\r
+#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8\r
+#define OW_CONVERT OW_FIRST_COMMAND+9\r
+#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10\r
+#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11\r
+#define OW_CONVERT_CONV OW_FIRST_COMMAND+12\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0xAA,OW_READ_MEMORY_ADDR\r
+       cset 0x55,OW_WRITE_MEMORY_ADDR\r
+       cset 0x3C,OW_CONVERT\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       ldi r_mode,OW_SLEEP\r
+       rjmp handle_end\r
+\r
+\r
+h_readmemoryaddr:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_readmemory_addr_byte1 ;nein dann weiter\r
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen\r
+       sts addr,r_rwbyte  ;speichern des ersten bytes\r
+       rjmp handle_end_inc\r
+h_readmemory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!\r
+       ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory\r
+       ;;ldi r_bcount,1 ;ist unten\r
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master\r
+       clr r_bytep\r
+       rjmp h_readmemory2\r
+h_readmemory:\r
+       lds r_bytep,addr\r
+       inc r_bytep\r
+       sts addr,r_bytep\r
+       andi r_bytep,0x07\r
+       breq h_readmemory_init_crc\r
+h_readmemory2:\r
+       lds r_bytep,addr\r
+       ;andi r_bytep,0x1F ist oben\r
+       configZ pack,r_bytep\r
+       ld   r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end ;sendet das Byte und geht zu h_readmemory\r
+h_readmemory_init_crc:; init erstes CRC byte\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       ldi r_mode,OW_READ_MEMORY_CRC1\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_readmemory_end:\r
+       ldi  r_mode,OW_SLEEP\r
+       clr r_sendflag\r
+       rjmp handle_end\r
+h_readmemorycrc1:;init zweites CRC Byte\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_READ_MEMORY_CRC2\r
+       rjmp handle_end\r
+h_readmemorycrc2:;weiteres senden..... nach zweitem Byte\r
+       lds r_temp,addr\r
+       andi r_temp,0xE0\r
+       brne h_readmemory_end; ende des speichers\r
+       ldi r_mode,OW_READ_MEMORY\r
+       CRCInit1 ;Start with new CRC\r
+       rjmp h_readmemory2\r
+\r
+h_writememoryaddr:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_writememory_addr_byte1 ;nein dann weiter\r
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen\r
+       sts addr,r_rwbyte  ;speichern des ersten bytes\r
+       inc r_bytep\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_writememory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!\r
+       ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory\r
+       ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....\r
+       lds r_bytep,addr\r
+       rjmp handle_end ;read Memory Byte\r
+h_writememory:\r
+       lds r_bytep,addr\r
+       configZ pack,r_bytep\r
+       st Z,r_rwbyte\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_CRC1\r
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       rjmp handle_end\r
+h_writememorycrc1:\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_CRC2\r
+       rjmp handle_end\r
+h_writememorycrc2:\r
+       lds r_temp,addr\r
+       configZ pack,r_temp\r
+       ld r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_READBACK\r
+       rjmp handle_end\r
+h_writememoryreadback:\r
+       ldi r_temp,0x00\r
+       sts crc+1,r_temp\r
+       lds r_temp,addr\r
+       inc r_temp\r
+       sts addr,r_temp\r
+       sts crc,r_temp\r
+       ldi r_sendflag,0\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY\r
+       rjmp handle_end\r
+\r
+h_convert:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_convert_byte1 ;nein dann weiter\r
+       inc r_bytep\r
+       sts pack+0x20,r_rwbyte\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_convert_byte1: ;zweies byte glesen go crc#\r
+       sts pack+0x21,r_rwbyte\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       ldi r_mode,OW_CONVERT_CRC1\r
+       ;ldi r_bcount,1\r
+       ldi r_sendflag,1\r
+       rjmp handle_end \r
+h_convertcrc1:\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_CONVERT_CRC2\r
+       rjmp handle_end\r
+h_convertcrc2:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_CONVERT_CONV\r
+       ;clr r_sendflag\r
+       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling\r
+h_convert_conv:\r
+       ldi r_bcount,0\r
+       ldi r_rwbyte,0\r
+       rjmp handle_end_no_bcount       \r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index ec60614..37ab426 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Atmel Studio Solution File, Format Version 11.00
-VisualStudioVersion = 14.0.23107.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450_SHT2X_BMP280_MAX44009", "DS2450_SHT2X_BMP280_MAX44009.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
-               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+VisualStudioVersion = 14.0.23107.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2450_SHT2X_BMP280_MAX44009", "DS2450_SHT2X_BMP280_MAX44009.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR\r
+               {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 3e01956..73cca74 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/SHT2x.h"
-#include "../common/I2C/BMP280.h"
-#include "../common/I2C/MAX44009.h"
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/
-uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-volatile uint8_t wdcounter=10;
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
-#endif 
-       wdcounter++;
-       if (reset_indicator==1) reset_indicator++;
-       else if (reset_indicator==2) mode=0;
-}
-
-typedef union {
-       volatile uint8_t bytes[0x20];
-       struct {
-               //Page0
-               uint16_t A;  //0
-               uint16_t B;  //2
-               uint16_t C;  //4
-               uint16_t D;  //6
-               //Page1
-               uint8_t CSA1;
-               uint8_t CSA2;
-               uint8_t CSB1;
-               uint8_t CSB2;
-               uint8_t CSC1;
-               uint8_t CSC2;
-               uint8_t CSD1;
-               uint8_t CSD2;
-               //Page2
-               uint8_t LA;
-               uint8_t HA;
-               uint8_t LB;
-               uint8_t HB;
-               uint8_t LC;
-               uint8_t HC;
-               uint8_t LD;
-               uint8_t HD;
-               //Page3
-               uint8_t FC1;
-               uint8_t FC2;
-               uint8_t FC3;
-               uint8_t FC4;
-               uint8_t VCCP;
-               uint8_t FC5;
-               uint8_t FC6;
-               uint8_t FC7;
-               uint8_t convc1;
-               uint8_t convc2;
-               
-               
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-volatile int16_t am2302_temp;
-volatile uint16_t am2302_hum;
-
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
-uint32_t P;
-int32_t t;
-uint8_t max_adr=0;
-
-
-
-int main(void){
-       pack.A=0;
-       pack.B=0;
-       pack.C=0;
-       pack.D=0;
-       pack.CSA1=0x08;
-       pack.CSA2=0x8C;
-       pack.CSB1=0x08;
-       pack.CSB2=0x8C;
-       pack.CSC1=0x08;
-       pack.CSC2=0x8C;
-       pack.CSD1=0x08;
-       pack.CSD2=0x8C;
-       pack.HA=0xFF;
-       pack.LA=0x00;
-       pack.HB=0xFF;
-       pack.LB=0x00;
-       pack.HC=0xFF;
-       pack.LC=0x00;
-       pack.HD=0xFF;
-       pack.LD=0x00;
-       pack.VCCP=0;
-    PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
-       DDRB|=(1<<PORTB0); //Als Ausgang und 0
-       PORTA=0xFF;  //All Pull up;
-        PRR|=(1<<PRADC);  // adc for save Power
-
-       ACSR|=(1<<ACD);  //Disable Comparator
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
-       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
-       
-       gcontrol=1;
-       
-       USI_TWI_Master_Initialise();
-       bmp280Init();
-       SHT2x_SoftReset();
-       SHT2x_ReadUserRegister(userRegister);
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg
-       // --- measure humidity with "Hold Master Mode (HM)" ---
-       //SHT2x_MeasurePoll(HUMIDITY, &sRH);
-       // --- measure temperature with "Polling Mode" (no hold master) ---
-       //SHT2x_MeasurePoll(TEMP, &sT);
-       //-- calculate humidity and temperature --
-       //temperatureC = SHT2x_CalcTemperatureC(sT);
-       //humidityRH = SHT2x_CalcRH(sRH);
-       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
-       
-       sei();
-       
-       //DDRB|=(1<<PINB1);
-
-    while(1)   {
-       
-       if (wdcounter>3) {      
-               SHT2x_MeasurePoll(HUMIDITY, &sRH);
-               // --- measure temperature with "Polling Mode" (no hold master) ---
-               SHT2x_MeasurePoll(TEMP, &sT);
-               //-- calculate humidity and temperature --
-               temperatureC = SHT2x_CalcTemperatureC(sT);
-               humidityRH = SHT2x_CalcRH(sRH);
-               bmp280ConvertInt(&t,&P,1);
-               l=MAX44009getlux(max_adr);
-               if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
-               //double l=1000;
-               l=(log(l)*1000)+32767.0;
-               wdcounter=0;
-       }
-       
-
-               
-               
-
-
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1);
-                       uint8_t bb=1;
-                       uint8_t bb1=1;
-                       for(uint8_t i=0;i<4;i++){
-                               if (pack.convc1&bb1) {
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}
-                                       bb=bb<<1;
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}
-                                       bb=bb<<1;
-                               } else bb=bb<<2;
-                               bb1=bb1<<1;                             
-                       }
-                       //CHanel A
-                       if (pack.convc1&1) {
-                               /*if (pack.CSA2&0x01)   ADMUX=0; else ADMUX=0x80;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.A=ADC;sei();*/
-                               uint16_t ct=(temperatureC*100.0)+32767;
-                               cli();pack.A=ct;sei();
-                               wdcounter=10;
-                               alarmflag=0;
-                               
-                               if (pack.CSA2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}
-                               if (pack.CSA2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}
-                       }
-
-                       if (pack.convc1&2) {
-                               /*if (pack.CSB2&0x01)   ADMUX=1; else ADMUX=0x81;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.B=ADC;sei();*/
-                               wdcounter=10;
-                               cli();pack.B=humidityRH*100;sei();
-                               if (pack.CSB2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}
-                               if (pack.CSB2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}
-                       }
-
-                       if (pack.convc1&4) {
-                               /*if (pack.CSC2&0x01)   ADMUX=2; else ADMUX=0x82;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.C=ADC;sei();*/
-                               wdcounter=10;
-                               cli();pack.C=l;sei();
-                               if (pack.CSC2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}
-                               if (pack.CSC2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}
-                       } 
-                       if (pack.convc1&8) {
-                               /*if (pack.CSD2&0x01)   ADMUX=3; else ADMUX=0x83;
-                               _delay_us(100);
-                               ADCSRA|=(1<<ADSC);
-                               while ((ADCSRA&(1<<ADSC)));
-                               cli();pack.D=ADC;sei();*/
-                               wdcounter=10;
-                               cli();pack.D=P/100.0*32.0;sei();
-                               if (pack.CSD2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}
-                               if (pack.CSD2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}
-                       }
-                       
-                       EXTERN_SLEEP();
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               /*uint8_t bb=1;
-               for(uint8_t i=0;i<4;i++) {
-                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output
-                               if (pack.bytes[8+i*2]&0x40) {
-                                       DDRA|=bb;
-                               } else {
-                                       DDRA&=~bb;
-                               }
-                       } else {
-                               DDRA&=~bb;
-                       }
-                       bb=bb*2;
-               }*/
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-       //      asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/SHT2x.h"\r
+#include "../common/I2C/BMP280.h"\r
+#include "../common/I2C/MAX44009.h"\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/\r
+uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+#if (owid>128) \r
+#error "Variable not correct"\r
+#endif\r
+\r
+extern uint8_t mode;\r
+extern uint8_t gcontrol;\r
+extern uint8_t reset_indicator;\r
+extern uint8_t alarmflag;\r
+volatile uint8_t wdcounter=10;\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+ISR(WATCHDOG_vect) {\r
+#else\r
+ISR(WDT_vect) {\r
+#endif \r
+       wdcounter++;\r
+       if (reset_indicator==1) reset_indicator++;\r
+       else if (reset_indicator==2) mode=0;\r
+}\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[0x20];\r
+       struct {\r
+               //Page0\r
+               uint16_t A;  //0\r
+               uint16_t B;  //2\r
+               uint16_t C;  //4\r
+               uint16_t D;  //6\r
+               //Page1\r
+               uint8_t CSA1;\r
+               uint8_t CSA2;\r
+               uint8_t CSB1;\r
+               uint8_t CSB2;\r
+               uint8_t CSC1;\r
+               uint8_t CSC2;\r
+               uint8_t CSD1;\r
+               uint8_t CSD2;\r
+               //Page2\r
+               uint8_t LA;\r
+               uint8_t HA;\r
+               uint8_t LB;\r
+               uint8_t HB;\r
+               uint8_t LC;\r
+               uint8_t HC;\r
+               uint8_t LD;\r
+               uint8_t HD;\r
+               //Page3\r
+               uint8_t FC1;\r
+               uint8_t FC2;\r
+               uint8_t FC3;\r
+               uint8_t FC4;\r
+               uint8_t VCCP;\r
+               uint8_t FC5;\r
+               uint8_t FC6;\r
+               uint8_t FC7;\r
+               uint8_t convc1;\r
+               uint8_t convc2;\r
+               \r
+               \r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+volatile int16_t am2302_temp;\r
+volatile uint16_t am2302_hum;\r
+\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+volatile double temperatureC,humidityRH;\r
+volatile double l;\r
+uint32_t P;\r
+int32_t t;\r
+uint8_t max_adr=0;\r
+\r
+\r
+\r
+int main(void){\r
+       pack.A=0;\r
+       pack.B=0;\r
+       pack.C=0;\r
+       pack.D=0;\r
+       pack.CSA1=0x08;\r
+       pack.CSA2=0x8C;\r
+       pack.CSB1=0x08;\r
+       pack.CSB2=0x8C;\r
+       pack.CSC1=0x08;\r
+       pack.CSC2=0x8C;\r
+       pack.CSD1=0x08;\r
+       pack.CSD2=0x8C;\r
+       pack.HA=0xFF;\r
+       pack.LA=0x00;\r
+       pack.HB=0xFF;\r
+       pack.LB=0x00;\r
+       pack.HC=0xFF;\r
+       pack.LC=0x00;\r
+       pack.HD=0xFF;\r
+       pack.LD=0x00;\r
+       pack.VCCP=0;\r
+    PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom\r
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0\r
+       PORTA=0xFF;  //All Pull up;\r
+        PRR|=(1<<PRADC);  // adc for save Power\r
+\r
+       ACSR|=(1<<ACD);  //Disable Comparator\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)\r
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt\r
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds\r
+       \r
+       gcontrol=1;\r
+       \r
+       USI_TWI_Master_Initialise();\r
+       bmp280Init();\r
+       SHT2x_SoftReset();\r
+       SHT2x_ReadUserRegister(userRegister);\r
+       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
+       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
+       // --- measure humidity with "Hold Master Mode (HM)" ---\r
+       //SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+       // --- measure temperature with "Polling Mode" (no hold master) ---\r
+       //SHT2x_MeasurePoll(TEMP, &sT);\r
+       //-- calculate humidity and temperature --\r
+       //temperatureC = SHT2x_CalcTemperatureC(sT);\r
+       //humidityRH = SHT2x_CalcRH(sRH);\r
+       if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;\r
+       \r
+       sei();\r
+       \r
+       //DDRB|=(1<<PINB1);\r
+\r
+    while(1)   {\r
+       \r
+       if (wdcounter>3) {      \r
+               SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
+               // --- measure temperature with "Polling Mode" (no hold master) ---\r
+               SHT2x_MeasurePoll(TEMP, &sT);\r
+               //-- calculate humidity and temperature --\r
+               temperatureC = SHT2x_CalcTemperatureC(sT);\r
+               humidityRH = SHT2x_CalcRH(sRH);\r
+               bmp280ConvertInt(&t,&P,1);\r
+               l=MAX44009getlux(max_adr);\r
+               if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045\r
+               //double l=1000;\r
+               l=(log(l)*1000)+32767.0;\r
+               wdcounter=0;\r
+       }\r
+       \r
+\r
+               \r
+               \r
+\r
+\r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1);\r
+                       uint8_t bb=1;\r
+                       uint8_t bb1=1;\r
+                       for(uint8_t i=0;i<4;i++){\r
+                               if (pack.convc1&bb1) {\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}\r
+                                       bb=bb<<1;\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}\r
+                                       bb=bb<<1;\r
+                               } else bb=bb<<2;\r
+                               bb1=bb1<<1;                             \r
+                       }\r
+                       //CHanel A\r
+                       if (pack.convc1&1) {\r
+                               /*if (pack.CSA2&0x01)   ADMUX=0; else ADMUX=0x80;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.A=ADC;sei();*/\r
+                               uint16_t ct=(temperatureC*100.0)+32767;\r
+                               cli();pack.A=ct;sei();\r
+                               wdcounter=10;\r
+                               alarmflag=0;\r
+                               \r
+                               if (pack.CSA2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}\r
+                               if (pack.CSA2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&2) {\r
+                               /*if (pack.CSB2&0x01)   ADMUX=1; else ADMUX=0x81;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.B=ADC;sei();*/\r
+                               wdcounter=10;\r
+                               cli();pack.B=humidityRH*100;sei();\r
+                               if (pack.CSB2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}\r
+                               if (pack.CSB2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&4) {\r
+                               /*if (pack.CSC2&0x01)   ADMUX=2; else ADMUX=0x82;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.C=ADC;sei();*/\r
+                               wdcounter=10;\r
+                               cli();pack.C=l;sei();\r
+                               if (pack.CSC2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}\r
+                               if (pack.CSC2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}\r
+                       } \r
+                       if (pack.convc1&8) {\r
+                               /*if (pack.CSD2&0x01)   ADMUX=3; else ADMUX=0x83;\r
+                               _delay_us(100);\r
+                               ADCSRA|=(1<<ADSC);\r
+                               while ((ADCSRA&(1<<ADSC)));\r
+                               cli();pack.D=ADC;sei();*/\r
+                               wdcounter=10;\r
+                               cli();pack.D=P/100.0*32.0;sei();\r
+                               if (pack.CSD2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}\r
+                               if (pack.CSD2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}\r
+                       }\r
+                       \r
+                       EXTERN_SLEEP();\r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               /*uint8_t bb=1;\r
+               for(uint8_t i=0;i<4;i++) {\r
+                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output\r
+                               if (pack.bytes[8+i*2]&0x40) {\r
+                                       DDRA|=bb;\r
+                               } else {\r
+                                       DDRA&=~bb;\r
+                               }\r
+                       } else {\r
+                               DDRA&=~bb;\r
+                       }\r
+                       bb=bb*2;\r
+               }*/\r
+               \r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
+#endif                 \r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
+#endif\r
+                         {\r
+\r
+                       MCUCR|=(1<<SE)|(1<<SM1);\r
+                       MCUCR&=~(1<<ISC01);\r
+               } else {\r
+                       MCUCR|=(1<<SE);\r
+                       MCUCR&=~(1<<SM1);\r
+               }\r
+       //      asm("SLEEP");\r
+   }\r
+\r
+\r
 }
\ No newline at end of file
index cc9be46..d3a73c9 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
-    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
-    <avrdevice>ATtiny84A</avrdevice>
-    <avrdeviceseries>none</avrdeviceseries>
-    <OutputType>Executable</OutputType>
-    <Language>C</Language>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.elf</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <AssemblyName>DS2450</AssemblyName>
-    <Name>DS2450_SHT2X_BMP280_MAX44009</Name>
-    <RootNamespace>DS2450</RootNamespace>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <ExternalProgrammingToolCommand />
-    <AsfFrameworkConfig>
-      <framework-data xmlns="">
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>NDEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
-      <SubType>compile</SubType>
-      <Link>BMP280.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">
-      <SubType>compile</SubType>
-      <Link>MAX44009.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">
-      <SubType>compile</SubType>
-      <Link>SHT2x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\TSL256x.c">
-      <SubType>compile</SubType>
-      <Link>TSL256x.c</Link>
-    </Compile>
-    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
-      <SubType>compile</SubType>
-      <Link>USI_TWI_Master.c</Link>
-    </Compile>
-    <Compile Include="DS2450_SHT2X_BMP280_MAX44009.c">
-      <SubType>compile</SubType>
-    </Compile>
-    <Compile Include="OWDS2450.S">
-      <SubType>compile</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>\r
+    <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <OutputType>Executable</OutputType>\r
+    <Language>C</Language>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.elf</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <AssemblyName>DS2450</AssemblyName>\r
+    <Name>DS2450_SHT2X_BMP280_MAX44009</Name>\r
+    <RootNamespace>DS2450</RootNamespace>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <ExternalProgrammingToolCommand />\r
+    <AsfFrameworkConfig>\r
+      <framework-data xmlns="">\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>NDEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrGcc>\r
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>\r
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>\r
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>\r
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>\r
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>\r
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>\r
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>\r
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>\r
+        <avrgcc.compiler.symbols.DefSymbols>\r
+          <ListValues>\r
+            <Value>DEBUG</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.symbols.DefSymbols>\r
+        <avrgcc.compiler.directories.IncludePaths>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>\r
+          </ListValues>\r
+        </avrgcc.compiler.directories.IncludePaths>\r
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>\r
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>\r
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>\r
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>\r
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>\r
+        <avrgcc.linker.libraries.Libraries>\r
+          <ListValues>\r
+            <Value>libm</Value>\r
+          </ListValues>\r
+        </avrgcc.linker.libraries.Libraries>\r
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>\r
+      </AvrGcc>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">\r
+      <SubType>compile</SubType>\r
+      <Link>BMP280.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\MAX44009.c">\r
+      <SubType>compile</SubType>\r
+      <Link>MAX44009.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\SHT2x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>SHT2x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\TSL256x.c">\r
+      <SubType>compile</SubType>\r
+      <Link>TSL256x.c</Link>\r
+    </Compile>\r
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">\r
+      <SubType>compile</SubType>\r
+      <Link>USI_TWI_Master.c</Link>\r
+    </Compile>\r
+    <Compile Include="DS2450_SHT2X_BMP280_MAX44009.c">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+    <Compile Include="OWDS2450.S">\r
+      <SubType>compile</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />\r
 </Project>
\ No newline at end of file
index aec56b7..1d81abd 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-#define _ZERO_POLLING_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC16.s"
-
-.extern pack,8
-.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)
-.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....
-//.extern  am2302_temp,2
-
-
-
-.macro CHIP_INIT       
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_readmemoryaddr
-               rjmp h_readmemory
-               rjmp h_readmemorycrc1
-               rjmp h_readmemorycrc2
-               rjmp h_writememoryaddr
-               rjmp h_writememory
-               rjmp h_writememorycrc1
-               rjmp h_writememorycrc2
-               rjmp h_writememoryreadback
-               rjmp h_convert
-               rjmp h_convertcrc1
-               rjmp h_convertcrc2
-               rjmp h_convert_conv
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0
-#define OW_READ_MEMORY OW_FIRST_COMMAND+1
-#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2
-#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3
-#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4
-#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5
-#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6
-#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7
-#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8
-#define OW_CONVERT OW_FIRST_COMMAND+9
-#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10
-#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11
-#define OW_CONVERT_CONV OW_FIRST_COMMAND+12
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0xAA,OW_READ_MEMORY_ADDR
-       cset 0x55,OW_WRITE_MEMORY_ADDR
-       cset 0x3C,OW_CONVERT
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-
-h_readmemoryaddr:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_readmemory_addr_byte1 ;nein dann weiter
-       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
-       sts addr,r_rwbyte  ;speichern des ersten bytes
-       rjmp handle_end_inc
-h_readmemory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
-       ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory
-       ;;ldi r_bcount,1 ;ist unten
-       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
-       clr r_bytep
-       rjmp h_readmemory2
-h_readmemory:
-       lds r_bytep,addr
-       inc r_bytep
-       sts addr,r_bytep
-       andi r_bytep,0x07
-       breq h_readmemory_init_crc
-h_readmemory2:
-       lds r_bytep,addr
-       ;andi r_bytep,0x1F ist oben
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       ;ldi r_bcount,1
-       rjmp handle_end ;sendet das Byte und geht zu h_readmemory
-h_readmemory_init_crc:; init erstes CRC byte
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       ldi r_mode,OW_READ_MEMORY_CRC1
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_readmemory_end:
-       ldi  r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end
-h_readmemorycrc1:;init zweites CRC Byte
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_READ_MEMORY_CRC2
-       rjmp handle_end
-h_readmemorycrc2:;weiteres senden..... nach zweitem Byte
-       lds r_temp,addr
-       andi r_temp,0xE0
-       brne h_readmemory_end; ende des speichers
-       ldi r_mode,OW_READ_MEMORY
-       CRCInit1 ;Start with new CRC
-       rjmp h_readmemory2
-
-h_writememoryaddr:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_writememory_addr_byte1 ;nein dann weiter
-       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen
-       sts addr,r_rwbyte  ;speichern des ersten bytes
-       inc r_bytep
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_writememory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!
-       ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory
-       ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....
-       lds r_bytep,addr
-       rjmp handle_end ;read Memory Byte
-h_writememory:
-       lds r_bytep,addr
-       configZ pack,r_bytep
-       st Z,r_rwbyte
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_CRC1
-       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       rjmp handle_end
-h_writememorycrc1:
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_CRC2
-       rjmp handle_end
-h_writememorycrc2:
-       lds r_temp,addr
-       configZ pack,r_temp
-       ld r_rwbyte,Z
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY_READBACK
-       rjmp handle_end
-h_writememoryreadback:
-       ldi r_temp,0x00
-       sts crc+1,r_temp
-       lds r_temp,addr
-       inc r_temp
-       sts addr,r_temp
-       sts crc,r_temp
-       ldi r_sendflag,0
-       ;ldi r_bcount,1
-       ldi r_mode,OW_WRITE_MEMORY
-       rjmp handle_end
-
-h_convert:
-       cpi r_bytep,0  ;erstes Adressbyte ?
-       brne h_convert_byte1 ;nein dann weiter
-       inc r_bytep
-       sts pack+0x20,r_rwbyte
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_convert_byte1: ;zweies byte glesen go crc#
-       sts pack+0x21,r_rwbyte
-       lds r_rwbyte,crc
-       com r_rwbyte
-       lds r_temp,crc+1
-       com r_temp
-       sts crcsave,r_temp
-       ldi r_mode,OW_CONVERT_CRC1
-       ;ldi r_bcount,1
-       ldi r_sendflag,1
-       rjmp handle_end 
-h_convertcrc1:
-       lds r_rwbyte,crcsave
-       ;ldi r_bcount,1
-       ldi r_mode,OW_CONVERT_CRC2
-       rjmp handle_end
-h_convertcrc2:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-       ;ldi r_bcount,1
-       ldi r_mode,OW_CONVERT_CONV
-       ;clr r_sendflag
-       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
-h_convert_conv:
-       ldi r_bcount,0
-       ldi r_rwbyte,0
-       rjmp handle_end_no_bcount       
-
-
-
-
-#include "../common/OWPinInterrupt.s"
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+#define _ZERO_POLLING_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC16.s"\r
+\r
+.extern pack,8\r
+.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....)\r
+.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte....\r
+//.extern  am2302_temp,2\r
+\r
+\r
+\r
+.macro CHIP_INIT       \r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readmemoryaddr\r
+               rjmp h_readmemory\r
+               rjmp h_readmemorycrc1\r
+               rjmp h_readmemorycrc2\r
+               rjmp h_writememoryaddr\r
+               rjmp h_writememory\r
+               rjmp h_writememorycrc1\r
+               rjmp h_writememorycrc2\r
+               rjmp h_writememoryreadback\r
+               rjmp h_convert\r
+               rjmp h_convertcrc1\r
+               rjmp h_convertcrc2\r
+               rjmp h_convert_conv\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0\r
+#define OW_READ_MEMORY OW_FIRST_COMMAND+1\r
+#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2\r
+#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3\r
+#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4\r
+#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5\r
+#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6\r
+#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7\r
+#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8\r
+#define OW_CONVERT OW_FIRST_COMMAND+9\r
+#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10\r
+#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11\r
+#define OW_CONVERT_CONV OW_FIRST_COMMAND+12\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0xAA,OW_READ_MEMORY_ADDR\r
+       cset 0x55,OW_WRITE_MEMORY_ADDR\r
+       cset 0x3C,OW_CONVERT\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       ldi r_mode,OW_SLEEP\r
+       rjmp handle_end\r
+\r
+\r
+h_readmemoryaddr:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_readmemory_addr_byte1 ;nein dann weiter\r
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen\r
+       sts addr,r_rwbyte  ;speichern des ersten bytes\r
+       rjmp handle_end_inc\r
+h_readmemory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!\r
+       ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory\r
+       ;;ldi r_bcount,1 ;ist unten\r
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master\r
+       clr r_bytep\r
+       rjmp h_readmemory2\r
+h_readmemory:\r
+       lds r_bytep,addr\r
+       inc r_bytep\r
+       sts addr,r_bytep\r
+       andi r_bytep,0x07\r
+       breq h_readmemory_init_crc\r
+h_readmemory2:\r
+       lds r_bytep,addr\r
+       ;andi r_bytep,0x1F ist oben\r
+       configZ pack,r_bytep\r
+       ld   r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end ;sendet das Byte und geht zu h_readmemory\r
+h_readmemory_init_crc:; init erstes CRC byte\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       ldi r_mode,OW_READ_MEMORY_CRC1\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_readmemory_end:\r
+       ldi  r_mode,OW_SLEEP\r
+       clr r_sendflag\r
+       rjmp handle_end\r
+h_readmemorycrc1:;init zweites CRC Byte\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_READ_MEMORY_CRC2\r
+       rjmp handle_end\r
+h_readmemorycrc2:;weiteres senden..... nach zweitem Byte\r
+       lds r_temp,addr\r
+       andi r_temp,0xE0\r
+       brne h_readmemory_end; ende des speichers\r
+       ldi r_mode,OW_READ_MEMORY\r
+       CRCInit1 ;Start with new CRC\r
+       rjmp h_readmemory2\r
+\r
+h_writememoryaddr:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_writememory_addr_byte1 ;nein dann weiter\r
+       andi r_rwbyte,0x1F  ; nur Adressen zwischen 0 und 0x1F zulassen\r
+       sts addr,r_rwbyte  ;speichern des ersten bytes\r
+       inc r_bytep\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_writememory_addr_byte1:  ;zweiters Addressbyte wird nicht gespeichert!\r
+       ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory\r
+       ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren.....\r
+       lds r_bytep,addr\r
+       rjmp handle_end ;read Memory Byte\r
+h_writememory:\r
+       lds r_bytep,addr\r
+       configZ pack,r_bytep\r
+       st Z,r_rwbyte\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_CRC1\r
+       ldi r_sendflag,1 ;jetzt sendet der Slave zum Master\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       rjmp handle_end\r
+h_writememorycrc1:\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_CRC2\r
+       rjmp handle_end\r
+h_writememorycrc2:\r
+       lds r_temp,addr\r
+       configZ pack,r_temp\r
+       ld r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY_READBACK\r
+       rjmp handle_end\r
+h_writememoryreadback:\r
+       ldi r_temp,0x00\r
+       sts crc+1,r_temp\r
+       lds r_temp,addr\r
+       inc r_temp\r
+       sts addr,r_temp\r
+       sts crc,r_temp\r
+       ldi r_sendflag,0\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_WRITE_MEMORY\r
+       rjmp handle_end\r
+\r
+h_convert:\r
+       cpi r_bytep,0  ;erstes Adressbyte ?\r
+       brne h_convert_byte1 ;nein dann weiter\r
+       inc r_bytep\r
+       sts pack+0x20,r_rwbyte\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_convert_byte1: ;zweies byte glesen go crc#\r
+       sts pack+0x21,r_rwbyte\r
+       lds r_rwbyte,crc\r
+       com r_rwbyte\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts crcsave,r_temp\r
+       ldi r_mode,OW_CONVERT_CRC1\r
+       ;ldi r_bcount,1\r
+       ldi r_sendflag,1\r
+       rjmp handle_end \r
+h_convertcrc1:\r
+       lds r_rwbyte,crcsave\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_CONVERT_CRC2\r
+       rjmp handle_end\r
+h_convertcrc2:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+       ;ldi r_bcount,1\r
+       ldi r_mode,OW_CONVERT_CONV\r
+       ;clr r_sendflag\r
+       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling\r
+h_convert_conv:\r
+       ldi r_bcount,0\r
+       ldi r_rwbyte,0\r
+       rjmp handle_end_no_bcount       \r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 3fdc81d..27adba5 100644 (file)
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include "USI_TWI_Master.h"
-
-uint16_t dig_T1;
-int16_t dig_T2;
-int16_t dig_T3;
-uint16_t dig_P1;
-int16_t dig_P2;
-int16_t dig_P3;
-int16_t dig_P4;
-int16_t dig_P5;
-int16_t dig_P6;
-int16_t dig_P7;
-int16_t dig_P8;
-int16_t dig_P9;
-
-
-
-
-short bmp280ReadShort(unsigned char address)
-{
-       char msb, lsb;
-       short data;
-       I2c_StartCondition();
-       I2c_WriteByte(0xEC);
-       I2c_WriteByte(address);
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0xED);
-       lsb=I2c_ReadByte(ACK);
-       msb=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       
-
-       
-       data = msb << 8;
-       data |= lsb;
-       
-       return data;
-}
-
-void bmp280Init(void) {
-       dig_T1=bmp280ReadShort(0x88);
-       dig_T2=bmp280ReadShort(0x8A);
-       dig_T3=bmp280ReadShort(0x8C);
-       dig_P1=bmp280ReadShort(0x8E);
-       dig_P2=bmp280ReadShort(0x90);
-       dig_P3=bmp280ReadShort(0x92);
-       dig_P4=bmp280ReadShort(0x94);
-       dig_P5=bmp280ReadShort(0x96);
-       dig_P6=bmp280ReadShort(0x98);
-       dig_P7=bmp280ReadShort(0x9A);
-       dig_P8=bmp280ReadShort(0x9C);
-       dig_P9=bmp280ReadShort(0x9E);
-       I2c_StartCondition();
-       I2c_WriteByte(0xEC);
-       I2c_WriteByte(0xF4);
-       I2c_WriteByte(0b01010111); //2x Temp over 16x Press over   Normal mode
-       I2c_WriteByte(0b11100000);  //4s time / no IIfilter
-       I2c_StopCondition();
-       
-       
-}
-int32_t bmp280ReadTemp(void) {
-       uint8_t msb, lsb,xlsb;
-       volatile int32_t data;
-       I2c_StartCondition();
-       I2c_WriteByte(0xEC);
-       I2c_WriteByte(0xFA);
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0xED);
-       msb=I2c_ReadByte(ACK);
-       lsb=I2c_ReadByte(ACK);
-       xlsb=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-               
-       data = (int32_t)msb << 12;
-       data |= (int16_t)lsb<<4;
-       data|=xlsb>>4;
-               
-               return data;
-
-       
-}
-int32_t bmp280ReadPressure(uint8_t oss) {
-               uint8_t msb, lsb,xlsb;
-               volatile int32_t data;
-               I2c_StartCondition();
-               I2c_WriteByte(0xEC);
-               I2c_WriteByte(0xF7);
-               I2c_StopCondition();
-               I2c_StartCondition();
-               I2c_WriteByte(0xED);
-               msb=I2c_ReadByte(ACK);
-               lsb=I2c_ReadByte(ACK);
-               xlsb=I2c_ReadByte(NO_ACK);
-               I2c_StopCondition();
-               
-               data = (int32_t)msb << 12;
-               data |= (int16_t)lsb<<4;
-               data|=xlsb>>4;
-               
-               return data;
-
-
-}
-void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss) {
-       int32_t var1,var2,T,t_fine;
-       
-       
-       int32_t adc_T=bmp280ReadTemp();
-       var1 = ((((adc_T>>3) - ((int32_t)dig_T1<<1))) * ((int32_t)dig_T2)) >> 11;
-       var2 = ((((((adc_T>>4) - ((int32_t)dig_T1)) * ((adc_T>>4) - (int32_t)dig_T1))) >> 12) *((int32_t)dig_T3)) >> 14;
-       t_fine = var1 + var2;
-       T = (t_fine * 5 + 128) >> 8;
-       *temperature=T;
-       int32_t adc_P= bmp280ReadPressure(oss);
-       uint32_t p;
-       var1 = (((int32_t)t_fine)>>1) - (int32_t)64000;
-       var2 = (((var1>>2) * (var1>>2)) >> 11 ) * ((int32_t)dig_P6);
-       var2 = var2 + ((var1*((int32_t)dig_P5))<<1);
-       var2 = (var2>>2)+(((int32_t)dig_P4)<<16);
-       var1 = (((dig_P3 * (((var1>>2) * (var1>>2)) >> 13 )) >> 3) + ((((int32_t)dig_P2) * var1)>>1))>>18;
-       var1 =((((32768+var1))*((int32_t)dig_P1))>>15);
-       if (var1 == 0) {
-               return ; // avoid exception caused by division by zero
-       }
-       p = (((uint32_t)(((int32_t)1048576)-adc_P)-(var2>>12)))*3125;
-       if (p < 0x80000000){
-               p = (p << 1) / ((uint32_t)var1);
-               }else{
-               p = (p / (uint32_t)var1) * 2;
-       }
-       var1 = (((int32_t)dig_P9) * ((int32_t)(((p>>3) * (p>>3))>>13)))>>12;
-       var2 = (((int32_t)(p>>2)) * ((int32_t)dig_P8))>>13;
-       p = (uint32_t)((int32_t)p + ((var1 + var2 + dig_P7) >> 4));
-       *pressure=p;
-
-}
-void bmp280Convert(double * temperature, double * pressure,uint8_t oss) {
-
-       uint32_t p;
-       int32_t T;
-       bmp280ConvertInt(&T,&p,oss);
-       *temperature=T/100.0;
-       *pressure=p/100.0;
-}
-               
-               
-               
-
-       
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include "USI_TWI_Master.h"\r
+\r
+uint16_t dig_T1;\r
+int16_t dig_T2;\r
+int16_t dig_T3;\r
+uint16_t dig_P1;\r
+int16_t dig_P2;\r
+int16_t dig_P3;\r
+int16_t dig_P4;\r
+int16_t dig_P5;\r
+int16_t dig_P6;\r
+int16_t dig_P7;\r
+int16_t dig_P8;\r
+int16_t dig_P9;\r
+\r
+\r
+\r
+\r
+short bmp280ReadShort(unsigned char address)\r
+{\r
+       char msb, lsb;\r
+       short data;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0xEC);\r
+       I2c_WriteByte(address);\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0xED);\r
+       lsb=I2c_ReadByte(ACK);\r
+       msb=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       \r
+\r
+       \r
+       data = msb << 8;\r
+       data |= lsb;\r
+       \r
+       return data;\r
+}\r
+\r
+void bmp280Init(void) {\r
+       dig_T1=bmp280ReadShort(0x88);\r
+       dig_T2=bmp280ReadShort(0x8A);\r
+       dig_T3=bmp280ReadShort(0x8C);\r
+       dig_P1=bmp280ReadShort(0x8E);\r
+       dig_P2=bmp280ReadShort(0x90);\r
+       dig_P3=bmp280ReadShort(0x92);\r
+       dig_P4=bmp280ReadShort(0x94);\r
+       dig_P5=bmp280ReadShort(0x96);\r
+       dig_P6=bmp280ReadShort(0x98);\r
+       dig_P7=bmp280ReadShort(0x9A);\r
+       dig_P8=bmp280ReadShort(0x9C);\r
+       dig_P9=bmp280ReadShort(0x9E);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0xEC);\r
+       I2c_WriteByte(0xF4);\r
+       I2c_WriteByte(0b01010111); //2x Temp over 16x Press over   Normal mode\r
+       I2c_WriteByte(0b11100000);  //4s time / no IIfilter\r
+       I2c_StopCondition();\r
+       \r
+       \r
+}\r
+int32_t bmp280ReadTemp(void) {\r
+       uint8_t msb, lsb,xlsb;\r
+       volatile int32_t data;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0xEC);\r
+       I2c_WriteByte(0xFA);\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0xED);\r
+       msb=I2c_ReadByte(ACK);\r
+       lsb=I2c_ReadByte(ACK);\r
+       xlsb=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+               \r
+       data = (int32_t)msb << 12;\r
+       data |= (int16_t)lsb<<4;\r
+       data|=xlsb>>4;\r
+               \r
+               return data;\r
+\r
+       \r
+}\r
+int32_t bmp280ReadPressure(uint8_t oss) {\r
+               uint8_t msb, lsb,xlsb;\r
+               volatile int32_t data;\r
+               I2c_StartCondition();\r
+               I2c_WriteByte(0xEC);\r
+               I2c_WriteByte(0xF7);\r
+               I2c_StopCondition();\r
+               I2c_StartCondition();\r
+               I2c_WriteByte(0xED);\r
+               msb=I2c_ReadByte(ACK);\r
+               lsb=I2c_ReadByte(ACK);\r
+               xlsb=I2c_ReadByte(NO_ACK);\r
+               I2c_StopCondition();\r
+               \r
+               data = (int32_t)msb << 12;\r
+               data |= (int16_t)lsb<<4;\r
+               data|=xlsb>>4;\r
+               \r
+               return data;\r
+\r
+\r
+}\r
+void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss) {\r
+       int32_t var1,var2,T,t_fine;\r
+       \r
+       \r
+       int32_t adc_T=bmp280ReadTemp();\r
+       var1 = ((((adc_T>>3) - ((int32_t)dig_T1<<1))) * ((int32_t)dig_T2)) >> 11;\r
+       var2 = ((((((adc_T>>4) - ((int32_t)dig_T1)) * ((adc_T>>4) - (int32_t)dig_T1))) >> 12) *((int32_t)dig_T3)) >> 14;\r
+       t_fine = var1 + var2;\r
+       T = (t_fine * 5 + 128) >> 8;\r
+       *temperature=T;\r
+       int32_t adc_P= bmp280ReadPressure(oss);\r
+       uint32_t p;\r
+       var1 = (((int32_t)t_fine)>>1) - (int32_t)64000;\r
+       var2 = (((var1>>2) * (var1>>2)) >> 11 ) * ((int32_t)dig_P6);\r
+       var2 = var2 + ((var1*((int32_t)dig_P5))<<1);\r
+       var2 = (var2>>2)+(((int32_t)dig_P4)<<16);\r
+       var1 = (((dig_P3 * (((var1>>2) * (var1>>2)) >> 13 )) >> 3) + ((((int32_t)dig_P2) * var1)>>1))>>18;\r
+       var1 =((((32768+var1))*((int32_t)dig_P1))>>15);\r
+       if (var1 == 0) {\r
+               return ; // avoid exception caused by division by zero\r
+       }\r
+       p = (((uint32_t)(((int32_t)1048576)-adc_P)-(var2>>12)))*3125;\r
+       if (p < 0x80000000){\r
+               p = (p << 1) / ((uint32_t)var1);\r
+               }else{\r
+               p = (p / (uint32_t)var1) * 2;\r
+       }\r
+       var1 = (((int32_t)dig_P9) * ((int32_t)(((p>>3) * (p>>3))>>13)))>>12;\r
+       var2 = (((int32_t)(p>>2)) * ((int32_t)dig_P8))>>13;\r
+       p = (uint32_t)((int32_t)p + ((var1 + var2 + dig_P7) >> 4));\r
+       *pressure=p;\r
+\r
+}\r
+void bmp280Convert(double * temperature, double * pressure,uint8_t oss) {\r
+\r
+       uint32_t p;\r
+       int32_t T;\r
+       bmp280ConvertInt(&T,&p,oss);\r
+       *temperature=T/100.0;\r
+       *pressure=p/100.0;\r
+}\r
+               \r
+               \r
+               \r
+\r
+       \r
index 0fab3c5..8ea7059 100644 (file)
@@ -1,13 +1,13 @@
-#ifndef BMP280_H
-#define BMP280_H
-
-
-
-void bmp280Init(void);
-int32_t bmp280ReadTemp(void);
-int32_t bmp280ReadPressure(uint8_t oss);
-void bmp280Convert(double * temperature, double * pressure,uint8_t oss);
-void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss);
-
-
+#ifndef BMP280_H\r
+#define BMP280_H\r
+\r
+\r
+\r
+void bmp280Init(void);\r
+int32_t bmp280ReadTemp(void);\r
+int32_t bmp280ReadPressure(uint8_t oss);\r
+void bmp280Convert(double * temperature, double * pressure,uint8_t oss);\r
+void bmp280ConvertInt(int32_t * temperature,uint32_t *pressure,uint8_t oss);\r
+\r
+\r
 #endif
\ No newline at end of file
index 8160ac2..404d82d 100644 (file)
@@ -1,55 +1,55 @@
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include "USI_TWI_Master.h"
-#include "MAX1164x.h"
-
-void MAX1164x_init(){
-       
-       
-}
-void MAX1164x_config(uint8_t setup,uint8_t config){
-       I2c_StartCondition();
-       I2c_WriteByte (0b01101100);
-       I2c_WriteByte (setup|0x80);
-       I2c_WriteByte (config);
-       I2c_StopCondition();
-       
-}
-int16_t MAX1164x_read() {
-       uint16_t res;
-       I2c_StartCondition();
-       I2c_WriteByte (0b01101101);
-       //DDR_USI&=~(1<<PIN_USI_SCL);
-       //while ((PIN_USI&(1<<PIN_USI_SCL))==0);
-       //DDR_USI|=(1<<PIN_USI_SCL);
-       _delay_us(80);
-       res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;
-       res|=I2c_ReadByte(NO_ACK);
-       
-       
-       I2c_StopCondition();
-       return res;
-       
-}
-
-
-int16_t MAX1164x_read8() {
-       uint16_t res;
-       I2c_StartCondition();
-       I2c_WriteByte (0b01101101);
-       //DDR_USI&=~(1<<PIN_USI_SCL);
-       //while ((PIN_USI&(1<<PIN_USI_SCL))==0);
-       //DDR_USI|=(1<<PIN_USI_SCL);
-       _delay_us(80);
-       res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;
-       res|=I2c_ReadByte(NO_ACK);
-       
-       
-       I2c_StopCondition();
-       return res;
-       
-}
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include "USI_TWI_Master.h"\r
+#include "MAX1164x.h"\r
+\r
+void MAX1164x_init(){\r
+       \r
+       \r
+}\r
+void MAX1164x_config(uint8_t setup,uint8_t config){\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b01101100);\r
+       I2c_WriteByte (setup|0x80);\r
+       I2c_WriteByte (config);\r
+       I2c_StopCondition();\r
+       \r
+}\r
+int16_t MAX1164x_read(void) {\r
+       uint16_t res;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b01101101);\r
+       //DDR_USI&=~(1<<PIN_USI_SCL);\r
+       //while ((PIN_USI&(1<<PIN_USI_SCL))==0);\r
+       //DDR_USI|=(1<<PIN_USI_SCL);\r
+       _delay_us(80);\r
+       res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;\r
+       res|=I2c_ReadByte(NO_ACK);\r
+       \r
+       \r
+       I2c_StopCondition();\r
+       return res;\r
+       \r
+}\r
+\r
+\r
+int16_t MAX1164x_read8(void) {\r
+       uint16_t res;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b01101101);\r
+       //DDR_USI&=~(1<<PIN_USI_SCL);\r
+       //while ((PIN_USI&(1<<PIN_USI_SCL))==0);\r
+       //DDR_USI|=(1<<PIN_USI_SCL);\r
+       _delay_us(80);\r
+       res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;\r
+       res|=I2c_ReadByte(NO_ACK);\r
+       \r
+       \r
+       I2c_StopCondition();\r
+       return res;\r
+       \r
+}\r
index cf8977c..3bb096a 100644 (file)
@@ -1,22 +1,22 @@
-#ifndef MAX1164x_H
-#define MAX1164x_H
-#define MAX1164x_S_SEL2 0x40
-#define MAX1164x_S_SEL1 0x20
-#define MAX1164x_S_SEL0 0x10
-#define MAX1164x_S_ECLK 0x08
-#define MAX1164x_S_BIP 0x04
-#define MAX1164_S_RESET 0x02
-
-#define MAX1164x_C_SCAN1 0x40
-#define MAX1164x_C_SCAN0 0x20
-#define MAX1164x_C_CS0  0x02
-#define MAX1164x_C_SGL 0x01
-
-
-
-void MAX1164x_init();
-void MAX1164x_config(uint8_t setup,uint8_t config);
-int16_t MAX1164x_read();
-
-
-#endif
\ No newline at end of file
+#ifndef MAX1164x_H\r
+#define MAX1164x_H\r
+#define MAX1164x_S_SEL2 0x40\r
+#define MAX1164x_S_SEL1 0x20\r
+#define MAX1164x_S_SEL0 0x10\r
+#define MAX1164x_S_ECLK 0x08\r
+#define MAX1164x_S_BIP 0x04\r
+#define MAX1164_S_RESET 0x02\r
+\r
+#define MAX1164x_C_SCAN1 0x40\r
+#define MAX1164x_C_SCAN0 0x20\r
+#define MAX1164x_C_CS0  0x02\r
+#define MAX1164x_C_SGL 0x01\r
+\r
+\r
+\r
+void MAX1164x_init(void);\r
+void MAX1164x_config(uint8_t setup,uint8_t config);\r
+int16_t MAX1164x_read(void);\r
+\r
+\r
+#endif\r
index 426098e..212524b 100644 (file)
@@ -1,85 +1,85 @@
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#define F_CPU 8000000UL
-#include <avr/io.h>
-
-#include <util/delay.h>
-
-
-#include "USI_TWI_Master.h"
-#include "MAX44009.h"
-
-uint8_t checkMAX44009(uint8_t nr) {
-       volatile uint8_t b1;
-       nr=(nr<<1)&0x02f;
-       
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x03);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b1 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       return b1!=0xFF;
-       
-}
-
-
-double MAX44009getlux(uint8_t nr)  {
-       volatile uint8_t b1,b2;
-       nr=(nr<<1)&0x02f;
-       
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x03);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b1 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x04);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b2 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register
-       uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register =
-       // upper four bits of mantissa
-       mantissa += b2 & 0x0F;    // lower four bits of low byte register =
-       // lower four bits of mantissa
-       
-       return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045;
-       
-       
-
-}
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+\r
+#include <util/delay.h>\r
+\r
+\r
+#include "USI_TWI_Master.h"\r
+#include "MAX44009.h"\r
+\r
+uint8_t checkMAX44009(uint8_t nr) {\r
+       volatile uint8_t b1;\r
+       nr=(nr<<1)&0x02f;\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x03);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b1 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       return b1!=0xFF;\r
+       \r
+}\r
+\r
+\r
+double MAX44009getlux(uint8_t nr)  {\r
+       volatile uint8_t b1,b2;\r
+       nr=(nr<<1)&0x02f;\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x03);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b1 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x04);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b2 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register\r
+       uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register =\r
+       // upper four bits of mantissa\r
+       mantissa += b2 & 0x0F;    // lower four bits of low byte register =\r
+       // lower four bits of mantissa\r
+       \r
+       return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045;\r
+       \r
+       \r
+\r
+}\r
index 366a236..a49b98f 100644 (file)
@@ -1,38 +1,38 @@
-#ifndef MAX44009_H
-#define MAX44009_H
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-double MAX44009getlux(uint8_t nr);
-uint8_t checkMAX44009(uint8_t nr);
-
+#ifndef MAX44009_H\r
+#define MAX44009_H\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+double MAX44009getlux(uint8_t nr);\r
+uint8_t checkMAX44009(uint8_t nr);\r
+\r
 #endif
\ No newline at end of file
index effe916..ae9f352 100644 (file)
-//==============================================================================
-// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
-//==============================================================================
-// Project : SHT2x Sample Code (V1.2)
-// File : SHT2x.c
-// Author : MST
-// Controller: NEC V850/SG3 (uPD70F3740)
-// Compiler : IAR compiler for V850 (3.50A)
-// Brief : Sensor layer. Functions for sensor access
-//==============================================================================
-//---------- Includes ----------------------------------------------------------
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include "USI_TWI_Master.h"
-#include "SHT2x.h"
-
-const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001
-
-
-//==============================================================================
-uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum)
-//==============================================================================
-{
-       uint8_t crc = 0;
-       uint8_t byteCtr;
-       //calculates 8-Bit checksum with given polynomial
-       for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr)
-       { crc ^= (data[byteCtr]);
-               for (uint8_t bit = 8; bit > 0; --bit)
-               { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
-                       else crc = (crc << 1);
-               }
-       }
-       if (crc != checksum) return CHECKSUM_ERROR;
-       else return 0;
-}
-//===========================================================================
-uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue)
-//===========================================================================
-{
-       uint8_t checksum; //variable for checksum byte
-       uint8_t error=0; //variable for error code
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W);
-       error |= I2c_WriteByte (USER_REG_R);
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_R);
-       *pRegisterValue = I2c_ReadByte(ACK);
-       checksum=I2c_ReadByte(NO_ACK);
-       error |= SHT2x_CheckCrc (pRegisterValue,1,checksum);
-       I2c_StopCondition();
-       return error;
-}
-//===========================================================================
-uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue)
-//===========================================================================
-{
-       uint8_t error=0; //variable for error code
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W);
-       error |= I2c_WriteByte (USER_REG_W);
-       error |= I2c_WriteByte (*pRegisterValue);
-       I2c_StopCondition();
-       return error;
-}
-//===========================================================================
-uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand)
-//===========================================================================
-{
-       uint8_t checksum; //checksum
-       uint8_t data[2]; //data array for checksum verification
-       uint8_t error=0; //error variable
-       uint16_t i; //counting variable
-       //-- write I2C sensor address and command --
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
-       switch(eSHT2xMeasureType)
-       { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break;
-               case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break;
-               //default: assert(0);
-       }
-       //-- wait until hold master is released --
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_R);
-       //SCL=HIGH; // set SCL I/O port as input
-       DDR_USI&=~(1<<PIN_USI_SCL);
-       for(i=0; i<1000; i++) // wait until master hold is released or ;;;;; Son quatsch.... 1000 s *kopfschuettel*
-       { _delay_ms(1); // a timeout (~1s) is reached
-               //if (SCL_CONF==1) break;
-               if (PIN_USI&(1<<PIN_USI_SCL)) break;
-       }
-       //-- check for timeout --
-       //Was wenn der SHT2x die leitung auf 0 laesst? Kurzschluss???
-       if((PIN_USI&(1<<PIN_USI_SCL))==0) error |= TIME_OUT_ERROR; else DDR_USI|=(1<<PIN_USI_SCL);
-       
-       //-- read two data bytes and one checksum byte --
-       *pMeasurand=((data[0] = I2c_ReadByte(ACK))>>8) & 0xFF;
-       *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK));
-//     pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK);
-//     pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK);
-
-       checksum=I2c_ReadByte(NO_ACK);
-       //-- verify checksum --
-       error |= SHT2x_CheckCrc (data,2,checksum);
-       I2c_StopCondition();
-       return error;
-}
-//===========================================================================
-uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand)
-//===========================================================================
-{
-       uint8_t checksum; //checksum
-       uint8_t data[2]; //data array for checksum verification
-       uint8_t error=0; //error variable
-       uint16_t i=0; //counting variable
-       //-- write I2C sensor address and command --
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
-       switch(eSHT2xMeasureType)
-       { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break;
-               case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break;
-               //default: assert(0);
-       }
-       //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)--
-       do
-       { I2c_StartCondition();
-               _delay_ms(200); //delay 10ms
-               if(i++ >= 20) break;
-       } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR);
-       if (i>=20) error |= TIME_OUT_ERROR;
-       //-- read two data bytes and one checksum byte --
-       data[0]=I2c_ReadByte(ACK);
-       data[1]=I2c_ReadByte(ACK);
-       *pMeasurand=(data[0]<<8)|data[1];
-       
-//     pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK);
-//     pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK);
-       checksum=I2c_ReadByte(NO_ACK);
-       //-- verify checksum --
-       error |= SHT2x_CheckCrc (data,2,checksum);
-       I2c_StopCondition();
-       return error;
-}
-//===========================================================================
-uint8_t SHT2x_SoftReset()
-//===========================================================================
-{
-       uint8_t error=0; //error variable
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
-       error |= I2c_WriteByte (SOFT_RESET); // Command
-       I2c_StopCondition();
-       _delay_ms(15); // wait till sensor has restarted
-       return error;
-}
-//==============================================================================
-float SHT2x_CalcRH(uint16_t u16sRH)
-//==============================================================================
-{
-       double humidityRH; // variable for result
-       u16sRH &= ~0x0003; // clear bits [1..0] (status bits)
-       //-- calculate relative humidity [%RH] --
-       humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16
-       return humidityRH;
-}
-//==============================================================================
-float SHT2x_CalcTemperatureC(uint16_t u16sT)
-//==============================================================================
-{
-       double temperatureC; // variable for result
-       u16sT &= ~0x0003; // clear bits [1..0] (status bits)
-       //-- calculate temperature [°C] --
-       temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16
-       return temperatureC;
-}
-//==============================================================================
-uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[])
-//==============================================================================
-{
-       uint8_t error=0; //error variable
-       //Read from memory location 1
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W); //I2C address
-       error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory
-       error |= I2c_WriteByte (0x0F); //on-chip memory address
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_R); //I2C address
-       u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3
-       I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed)
-       u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2
-       I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed)
-       u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1
-       I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed)
-       u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0
-       I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed)
-       I2c_StopCondition();
-       //Read from memory location 2
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_W); //I2C address
-       error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory
-       error |= I2c_WriteByte (0xC9); //on-chip memory address
-       I2c_StartCondition();
-       error |= I2c_WriteByte (I2C_ADR_R); //I2C address
-       u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1
-       u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0
-       I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed)
-       u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1
-       u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0
-       I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed)
-       I2c_StopCondition();
-       return error;
-}
\ No newline at end of file
+//==============================================================================\r
+// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland\r
+//==============================================================================\r
+// Project : SHT2x Sample Code (V1.2)\r
+// File : SHT2x.c\r
+// Author : MST\r
+// Controller: NEC V850/SG3 (uPD70F3740)\r
+// Compiler : IAR compiler for V850 (3.50A)\r
+// Brief : Sensor layer. Functions for sensor access\r
+//==============================================================================\r
+//---------- Includes ----------------------------------------------------------\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include "USI_TWI_Master.h"\r
+#include "SHT2x.h"\r
+\r
+const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001\r
+\r
+\r
+//==============================================================================\r
+uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum)\r
+//==============================================================================\r
+{\r
+       uint8_t crc = 0;\r
+       uint8_t byteCtr;\r
+       //calculates 8-Bit checksum with given polynomial\r
+       for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr)\r
+       { crc ^= (data[byteCtr]);\r
+               for (uint8_t bit = 8; bit > 0; --bit)\r
+               { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;\r
+                       else crc = (crc << 1);\r
+               }\r
+       }\r
+       if (crc != checksum) return CHECKSUM_ERROR;\r
+       else return 0;\r
+}\r
+//===========================================================================\r
+uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue)\r
+//===========================================================================\r
+{\r
+       uint8_t checksum; //variable for checksum byte\r
+       uint8_t error=0; //variable for error code\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W);\r
+       error |= I2c_WriteByte (USER_REG_R);\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_R);\r
+       *pRegisterValue = I2c_ReadByte(ACK);\r
+       checksum=I2c_ReadByte(NO_ACK);\r
+       error |= SHT2x_CheckCrc (pRegisterValue,1,checksum);\r
+       I2c_StopCondition();\r
+       return error;\r
+}\r
+//===========================================================================\r
+uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue)\r
+//===========================================================================\r
+{\r
+       uint8_t error=0; //variable for error code\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W);\r
+       error |= I2c_WriteByte (USER_REG_W);\r
+       error |= I2c_WriteByte (*pRegisterValue);\r
+       I2c_StopCondition();\r
+       return error;\r
+}\r
+//===========================================================================\r
+uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand)\r
+//===========================================================================\r
+{\r
+       uint8_t checksum; //checksum\r
+       uint8_t data[2]; //data array for checksum verification\r
+       uint8_t error=0; //error variable\r
+       uint16_t i; //counting variable\r
+       //-- write I2C sensor address and command --\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+       switch(eSHT2xMeasureType)\r
+       { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break;\r
+               case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break;\r
+               //default: assert(0);\r
+       }\r
+       //-- wait until hold master is released --\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_R);\r
+       //SCL=HIGH; // set SCL I/O port as input\r
+       DDR_USI&=~(1<<PIN_USI_SCL);\r
+       for(i=0; i<1000; i++) // wait until master hold is released or ;;;;; Son quatsch.... 1000 s *kopfschuettel*\r
+       { _delay_ms(1); // a timeout (~1s) is reached\r
+               //if (SCL_CONF==1) break;\r
+               if (PIN_USI&(1<<PIN_USI_SCL)) break;\r
+       }\r
+       //-- check for timeout --\r
+       //Was wenn der SHT2x die leitung auf 0 laesst? Kurzschluss???\r
+       if((PIN_USI&(1<<PIN_USI_SCL))==0) error |= TIME_OUT_ERROR; else DDR_USI|=(1<<PIN_USI_SCL);\r
+       \r
+       //-- read two data bytes and one checksum byte --\r
+       *pMeasurand=((data[0] = I2c_ReadByte(ACK))>>8) & 0xFF;\r
+       *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK));\r
+//     pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK);\r
+//     pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK);\r
+\r
+       checksum=I2c_ReadByte(NO_ACK);\r
+       //-- verify checksum --\r
+       error |= SHT2x_CheckCrc (data,2,checksum);\r
+       I2c_StopCondition();\r
+       return error;\r
+}\r
+//===========================================================================\r
+uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand)\r
+//===========================================================================\r
+{\r
+       uint8_t checksum; //checksum\r
+       uint8_t data[2]; //data array for checksum verification\r
+       uint8_t error=0; //error variable\r
+       uint16_t i=0; //counting variable\r
+       //-- write I2C sensor address and command --\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+       switch(eSHT2xMeasureType)\r
+       { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break;\r
+               case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break;\r
+               //default: assert(0);\r
+       }\r
+       //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)--\r
+       do\r
+       { I2c_StartCondition();\r
+               _delay_ms(200); //delay 10ms\r
+               if(i++ >= 20) break;\r
+       } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR);\r
+       if (i>=20) error |= TIME_OUT_ERROR;\r
+       //-- read two data bytes and one checksum byte --\r
+       data[0]=I2c_ReadByte(ACK);\r
+       data[1]=I2c_ReadByte(ACK);\r
+       *pMeasurand=(data[0]<<8)|data[1];\r
+       \r
+//     pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK);\r
+//     pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK);\r
+       checksum=I2c_ReadByte(NO_ACK);\r
+       //-- verify checksum --\r
+       error |= SHT2x_CheckCrc (data,2,checksum);\r
+       I2c_StopCondition();\r
+       return error;\r
+}\r
+//===========================================================================\r
+uint8_t SHT2x_SoftReset(void)\r
+//===========================================================================\r
+{\r
+       uint8_t error=0; //error variable\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+       error |= I2c_WriteByte (SOFT_RESET); // Command\r
+       I2c_StopCondition();\r
+       _delay_ms(15); // wait till sensor has restarted\r
+       return error;\r
+}\r
+//==============================================================================\r
+float SHT2x_CalcRH(uint16_t u16sRH)\r
+//==============================================================================\r
+{\r
+       double humidityRH; // variable for result\r
+       u16sRH &= ~0x0003; // clear bits [1..0] (status bits)\r
+       //-- calculate relative humidity [%RH] --\r
+       humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16\r
+       return humidityRH;\r
+}\r
+//==============================================================================\r
+float SHT2x_CalcTemperatureC(uint16_t u16sT)\r
+//==============================================================================\r
+{\r
+       double temperatureC; // variable for result\r
+       u16sT &= ~0x0003; // clear bits [1..0] (status bits)\r
+       //-- calculate temperature [°C] --\r
+       temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16\r
+       return temperatureC;\r
+}\r
+//==============================================================================\r
+uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[])\r
+//==============================================================================\r
+{\r
+       uint8_t error=0; //error variable\r
+       //Read from memory location 1\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W); //I2C address\r
+       error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory\r
+       error |= I2c_WriteByte (0x0F); //on-chip memory address\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_R); //I2C address\r
+       u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3\r
+       I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed)\r
+       u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2\r
+       I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed)\r
+       u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1\r
+       I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed)\r
+       u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0\r
+       I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed)\r
+       I2c_StopCondition();\r
+       //Read from memory location 2\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_W); //I2C address\r
+       error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory\r
+       error |= I2c_WriteByte (0xC9); //on-chip memory address\r
+       I2c_StartCondition();\r
+       error |= I2c_WriteByte (I2C_ADR_R); //I2C address\r
+       u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1\r
+       u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0\r
+       I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed)\r
+       u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1\r
+       u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0\r
+       I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed)\r
+       I2c_StopCondition();\r
+       return error;\r
+}\r
index e734a9e..5f97f83 100644 (file)
-#ifndef SHT2x_H
-#define SHT2x_H
-//==============================================================================
-// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland
-//==============================================================================
-// Project : SHT2x Sample Code (V1.2)
-// File : SHT2x.h
-// Author : MST
-// Controller: NEC V850/SG3 (uPD70F3740)
-// Compiler : IAR compiler for V850 (3.50A)
-// Brief : Sensor layer. Definitions of commands and registers,
-// functions for sensor access
-//==============================================================================
-
-
-//---------- Defines -----------------------------------------------------------
-// CRC
-#define CHECKSUM_ERROR 1
-#define TIME_OUT_ERROR 2
-#define ACK_ERROR 4
-
-
-// sensor command
-typedef enum{
-       TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master
-       TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master
-       TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master
-       TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master
-       USER_REG_W = 0xE6, // command writing user register
-       USER_REG_R = 0xE7, // command reading user register
-       SOFT_RESET = 0xFE // command soft reset
-}etSHT2xCommand;
-typedef enum {
-       SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit
-       SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit
-       SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit
-       SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit
-       SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg.
-} etSHT2xResolution;
-typedef enum {
-       SHT2x_EOB_ON = 0x40, // end of battery
-       SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg.
-} etSHT2xEob;
-typedef enum {
-       SHT2x_HEATER_ON = 0x04, // heater on
-       SHT2x_HEATER_OFF = 0x00, // heater off
-       SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg.
-} etSHT2xHeater;
-// measurement signal selection
-typedef enum{
-       HUMIDITY,
-       TEMP
-}etSHT2xMeasureType;
-typedef enum{
-       I2C_ADR_W = 128, // sensor I2C address + write bit
-       I2C_ADR_R = 129 // sensor I2C address + read bit
-}etI2cHeader;
-//==============================================================================
-uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);
-//==============================================================================
-// calculates checksum for n bytes of data and compares it with expected
-// checksum
-// input: data[] checksum is built based on this data
-// nbrOfBytes checksum is built for n bytes of data
-// checksum expected checksum
-// return: error: CHECKSUM_ERROR = checksum does not match
-// 0 = checksum matches
-//==============================================================================
-uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue);
-//==============================================================================
-// reads the SHT2x user register (8bit)
-// input : -
-// output: *pRegisterValue
-// return: error
-//==============================================================================
-uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue);
-//==============================================================================
-//Sample Code SHT21
-//www.sensirion.com Version 1.2 \96 February 2010 4/14
-// writes the SHT2x user register (8bit)
-// input : *pRegisterValue
-// output: -
-// return: error
-//==============================================================================
-uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
-//==============================================================================
-// measures humidity or temperature. This function polls every 10ms until
-// measurement is ready.
-// input: eSHT2xMeasureType
-// output: *pMeasurand: humidity / temperature as raw value
-// return: error
-// note: timing for timeout may be changed
-//==============================================================================
-uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);
-//==============================================================================
-// measures humidity or temperature. This function waits for a hold master until
-// measurement is ready or a timeout occurred.
-// input: eSHT2xMeasureType
-// output: *pMeasurand: humidity / temperature as raw value
-// return: error
-// note: timing for timeout may be changed
-//==============================================================================
-uint8_t SHT2x_SoftReset();
-//==============================================================================
-// performs a reset
-// input: -
-// output: -
-// return: error
-//==============================================================================
-float SHT2x_CalcRH(uint16_t u16sRH);
-//==============================================================================
-// calculates the relative humidity
-// input: sRH: humidity raw value (16bit scaled)
-// return: pHumidity relative humidity [%RH]
-//==============================================================================
-float SHT2x_CalcTemperatureC(uint16_t u16sT);
-//==============================================================================
-// calculates temperature
-// input: sT: temperature raw value (16bit scaled)
-// return: temperature [°C]
-//==============================================================================
-uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]);
-//==============================================================================
-// gets serial number of SHT2x according application note "How To
-// Read-Out the Serial Number"
-// note: readout of this function is not CRC checked
-//
-// input: -
-// output: u8SerialNumber: Array of 8 bytes (64Bits)
-// MSB LSB
-// u8SerialNumber[7] u8SerialNumber[0]
-// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0
-// return: error
-#endif
\ No newline at end of file
+#ifndef SHT2x_H\r
+#define SHT2x_H\r
+//==============================================================================\r
+// S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland\r
+//==============================================================================\r
+// Project : SHT2x Sample Code (V1.2)\r
+// File : SHT2x.h\r
+// Author : MST\r
+// Controller: NEC V850/SG3 (uPD70F3740)\r
+// Compiler : IAR compiler for V850 (3.50A)\r
+// Brief : Sensor layer. Definitions of commands and registers,\r
+// functions for sensor access\r
+//==============================================================================\r
+\r
+\r
+//---------- Defines -----------------------------------------------------------\r
+// CRC\r
+#define CHECKSUM_ERROR 1\r
+#define TIME_OUT_ERROR 2\r
+#define ACK_ERROR 4\r
+\r
+\r
+// sensor command\r
+typedef enum{\r
+       TRIG_T_MEASUREMENT_HM = 0xE3, // command trig. temp meas. hold master\r
+       TRIG_RH_MEASUREMENT_HM = 0xE5, // command trig. humidity meas. hold master\r
+       TRIG_T_MEASUREMENT_POLL = 0xF3, // command trig. temp meas. no hold master\r
+       TRIG_RH_MEASUREMENT_POLL = 0xF5, // command trig. humidity meas. no hold master\r
+       USER_REG_W = 0xE6, // command writing user register\r
+       USER_REG_R = 0xE7, // command reading user register\r
+       SOFT_RESET = 0xFE // command soft reset\r
+}etSHT2xCommand;\r
+typedef enum {\r
+       SHT2x_RES_12_14BIT = 0x00, // RH=12bit, T=14bit\r
+       SHT2x_RES_8_12BIT = 0x01, // RH= 8bit, T=12bit\r
+       SHT2x_RES_10_13BIT = 0x80, // RH=10bit, T=13bit\r
+       SHT2x_RES_11_11BIT = 0x81, // RH=11bit, T=11bit\r
+       SHT2x_RES_MASK = 0x81 // Mask for res. bits (7,0) in user reg.\r
+} etSHT2xResolution;\r
+typedef enum {\r
+       SHT2x_EOB_ON = 0x40, // end of battery\r
+       SHT2x_EOB_MASK = 0x40, // Mask for EOB bit(6) in user reg.\r
+} etSHT2xEob;\r
+typedef enum {\r
+       SHT2x_HEATER_ON = 0x04, // heater on\r
+       SHT2x_HEATER_OFF = 0x00, // heater off\r
+       SHT2x_HEATER_MASK = 0x04, // Mask for Heater bit(2) in user reg.\r
+} etSHT2xHeater;\r
+// measurement signal selection\r
+typedef enum{\r
+       HUMIDITY,\r
+       TEMP\r
+}etSHT2xMeasureType;\r
+typedef enum{\r
+       I2C_ADR_W = 128, // sensor I2C address + write bit\r
+       I2C_ADR_R = 129 // sensor I2C address + read bit\r
+}etI2cHeader;\r
+//==============================================================================\r
+uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);\r
+//==============================================================================\r
+// calculates checksum for n bytes of data and compares it with expected\r
+// checksum\r
+// input: data[] checksum is built based on this data\r
+// nbrOfBytes checksum is built for n bytes of data\r
+// checksum expected checksum\r
+// return: error: CHECKSUM_ERROR = checksum does not match\r
+// 0 = checksum matches\r
+//==============================================================================\r
+uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue);\r
+//==============================================================================\r
+// reads the SHT2x user register (8bit)\r
+// input : -\r
+// output: *pRegisterValue\r
+// return: error\r
+//==============================================================================\r
+uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue);\r
+//==============================================================================\r
+//Sample Code SHT21\r
+//www.sensirion.com Version 1.2 \96 February 2010 4/14\r
+// writes the SHT2x user register (8bit)\r
+// input : *pRegisterValue\r
+// output: -\r
+// return: error\r
+//==============================================================================\r
+uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);\r
+//==============================================================================\r
+// measures humidity or temperature. This function polls every 10ms until\r
+// measurement is ready.\r
+// input: eSHT2xMeasureType\r
+// output: *pMeasurand: humidity / temperature as raw value\r
+// return: error\r
+// note: timing for timeout may be changed\r
+//==============================================================================\r
+uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand);\r
+//==============================================================================\r
+// measures humidity or temperature. This function waits for a hold master until\r
+// measurement is ready or a timeout occurred.\r
+// input: eSHT2xMeasureType\r
+// output: *pMeasurand: humidity / temperature as raw value\r
+// return: error\r
+// note: timing for timeout may be changed\r
+//==============================================================================\r
+uint8_t SHT2x_SoftReset(void);\r
+//==============================================================================\r
+// performs a reset\r
+// input: -\r
+// output: -\r
+// return: error\r
+//==============================================================================\r
+float SHT2x_CalcRH(uint16_t u16sRH);\r
+//==============================================================================\r
+// calculates the relative humidity\r
+// input: sRH: humidity raw value (16bit scaled)\r
+// return: pHumidity relative humidity [%RH]\r
+//==============================================================================\r
+float SHT2x_CalcTemperatureC(uint16_t u16sT);\r
+//==============================================================================\r
+// calculates temperature\r
+// input: sT: temperature raw value (16bit scaled)\r
+// return: temperature [°C]\r
+//==============================================================================\r
+uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]);\r
+//==============================================================================\r
+// gets serial number of SHT2x according application note "How To\r
+// Read-Out the Serial Number"\r
+// note: readout of this function is not CRC checked\r
+//\r
+// input: -\r
+// output: u8SerialNumber: Array of 8 bytes (64Bits)\r
+// MSB LSB\r
+// u8SerialNumber[7] u8SerialNumber[0]\r
+// SNA_1 SNA_0 SNB_3 SNB_2 SNB_1 SNB_0 SNC_1 SNC_0\r
+// return: error\r
+#endif\r
index 140dd86..d32ab0f 100644 (file)
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include "USI_TWI_Master.h"
-
-void TSL256x_init() {
-       I2c_StartCondition();
-       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001
-       I2c_WriteByte(0x80);
-       I2c_WriteByte(0x03);
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001
-       I2c_WriteByte(0x81);
-       I2c_WriteByte(0x12);
-       I2c_StopCondition();
-       _delay_ms(500);
-}
-
-void TSL256x_setup(uint8_t conf) {
-       I2c_StartCondition();
-       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001
-       I2c_WriteByte(0x81);
-       I2c_WriteByte(conf);
-       I2c_StopCondition();
-}
-
-uint16_t TSL256x_Ch(uint8_t ch){
-       uint16_t res;
-       I2c_StartCondition();
-       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001
-       //I2c_WriteByte(0xAD);
-       I2c_WriteByte(0xAC+(ch<<1));
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0b01010011); 
-       res=I2c_ReadByte(ACK);
-       res|=((uint16_t)I2c_ReadByte(NO_ACK))<<8;
-       I2c_StopCondition();
-       return res;
-}
-
-#define LUX_SCALE 14 // scale by 2^14
-#define RATIO_SCALE 9 // scale ratio by 2^9
-//???????????????????????????????????????????????????
-// Integration time scaling factors
-//???????????????????????????????????????????????????
-#define CH_SCALE 10 // scale channel values by 2^10
-#define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE
-#define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE
-
-#define K1T 0x0040 // 0.125 * 2^RATIO_SCALE
-#define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE
-#define M1T 0x01be // 0.0272 * 2^LUX_SCALE
-#define K2T 0x0080 // 0.250 * 2^RATIO_SCALE
-#define B2T 0x0214 // 0.0325 * 2^LUX_SCALE
-#define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE
-#define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE
-#define B3T 0x023f // 0.0351 * 2^LUX_SCALE
-#define M3T 0x037b // 0.0544 * 2^LUX_SCALE
-#define K4T 0x0100 // 0.50 * 2^RATIO_SCALE
-#define B4T 0x0270 // 0.0381 * 2^LUX_SCALE
-#define M4T 0x03fe // 0.0624 * 2^LUX_SCALE
-#define K5T 0x0138 // 0.61 * 2^RATIO_SCALE
-#define B5T 0x016f // 0.0224 * 2^LUX_SCALE
-#define M5T 0x01fc // 0.0310 * 2^LUX_SCALE
-#define K6T 0x019a // 0.80 * 2^RATIO_SCALE
-#define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE
-#define M6T 0x00fb // 0.0153 * 2^LUX_SCALE
-#define K7T 0x029a // 1.3 * 2^RATIO_SCALE
-#define B7T 0x0018 // 0.00146 * 2^LUX_SCALE
-#define M7T 0x0012 // 0.00112 * 2^LUX_SCALE
-#define K8T 0x029a // 1.3 * 2^RATIO_SCALE
-#define B8T 0x0000 // 0.000 * 2^LUX_SCALE
-#define M8T 0x0000 // 0.000 * 2^LUX_SCALE
-
-uint32_t CalculateLux(uint8_t iGain, uint8_t tInt, uint16_t ch0, uint16_t ch1)
-{
-       //????????????????????????????????????????????????????????????????????????
-       // first, scale the channel values depending on the gain and integration time
-       // 16X, 402mS is nominal.
-       // scale if integration time is NOT 402 msec
-       uint32_t chScale;
-       uint32_t channel1;
-       uint32_t channel0;
-       switch (tInt)
-       {
-               case 0: // 13.7 msec
-               chScale = CHSCALE_TINT0;
-               break;
-               case 1: // 101 msec
-               chScale = CHSCALE_TINT1;
-               break;
-               default: // assume no scaling
-               chScale = (1 << CH_SCALE);
-               break;
-       }
-       // scale if gain is NOT 16X
-       if (!iGain) chScale = chScale << 4; // scale 1X to 16X
-       // scale the channel values
-       channel0 = (ch0 * chScale) >> CH_SCALE;
-       channel1 = (ch1 * chScale) >> CH_SCALE;
-       //????????????????????????????????????????????????????????????????????????
-       // find the ratio of the channel values (Channel1/Channel0)
-       // protect against divide by zero
-       uint32_t ratio1 = 0;
-       if (channel0 != 0) ratio1 = (channel1 << (RATIO_SCALE+1)) / channel0;
-       // round the ratio value
-       uint32_t ratio = (ratio1 + 1) >> 1;
-       // is ratio <= eachBreak ?
-       uint16_t b, m;
-               if ((ratio >= 0) && (ratio <= K1T))
-               {b=B1T; m=M1T;}
-               else if (ratio <= K2T)
-               {b=B2T; m=M2T;}
-               else if (ratio <= K3T)
-               {b=B3T; m=M3T;}
-               else if (ratio <= K4T)
-               {b=B4T; m=M4T;}
-               else if (ratio <= K5T)
-               {b=B5T; m=M5T;}
-               else if (ratio <= K6T)
-               {b=B6T; m=M6T;}
-               else if (ratio <= K7T)
-               {b=B7T; m=M7T;}
-               else if (ratio > K8T)
-               {b=B8T; m=M8T;}
-       uint32_t temp;
-       temp = ((channel0 * b) - (channel1 * m));
-       // do not allow negative lux value
-       if (temp < 0) temp = 0;
-       // round lsb (2^(LUX_SCALE?1))
-       temp += (1 << (LUX_SCALE-1));
-       // strip off fractional portion
-       uint32_t lux = temp ;//>> LUX_SCALE;
-       return(lux);
-}
-
-
-
-
-       
-
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include "USI_TWI_Master.h"\r
+\r
+void TSL256x_init() {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001\r
+       I2c_WriteByte(0x80);\r
+       I2c_WriteByte(0x03);\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001\r
+       I2c_WriteByte(0x81);\r
+       I2c_WriteByte(0x12);\r
+       I2c_StopCondition();\r
+       _delay_ms(500);\r
+}\r
+\r
+void TSL256x_setup(uint8_t conf) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001\r
+       I2c_WriteByte(0x81);\r
+       I2c_WriteByte(conf);\r
+       I2c_StopCondition();\r
+}\r
+\r
+uint16_t TSL256x_Ch(uint8_t ch){\r
+       uint16_t res;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b01010010);  // 0x0101001 1001001 0111001\r
+       //I2c_WriteByte(0xAD);\r
+       I2c_WriteByte(0xAC+(ch<<1));\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b01010011); \r
+       res=I2c_ReadByte(ACK);\r
+       res|=((uint16_t)I2c_ReadByte(NO_ACK))<<8;\r
+       I2c_StopCondition();\r
+       return res;\r
+}\r
+\r
+#define LUX_SCALE 14 // scale by 2^14\r
+#define RATIO_SCALE 9 // scale ratio by 2^9\r
+//???????????????????????????????????????????????????\r
+// Integration time scaling factors\r
+//???????????????????????????????????????????????????\r
+#define CH_SCALE 10 // scale channel values by 2^10\r
+#define CHSCALE_TINT0 0x7517 // 322/11 * 2^CH_SCALE\r
+#define CHSCALE_TINT1 0x0fe7 // 322/81 * 2^CH_SCALE\r
+\r
+#define K1T 0x0040 // 0.125 * 2^RATIO_SCALE\r
+#define B1T 0x01f2 // 0.0304 * 2^LUX_SCALE\r
+#define M1T 0x01be // 0.0272 * 2^LUX_SCALE\r
+#define K2T 0x0080 // 0.250 * 2^RATIO_SCALE\r
+#define B2T 0x0214 // 0.0325 * 2^LUX_SCALE\r
+#define M2T 0x02d1 // 0.0440 * 2^LUX_SCALE\r
+#define K3T 0x00c0 // 0.375 * 2^RATIO_SCALE\r
+#define B3T 0x023f // 0.0351 * 2^LUX_SCALE\r
+#define M3T 0x037b // 0.0544 * 2^LUX_SCALE\r
+#define K4T 0x0100 // 0.50 * 2^RATIO_SCALE\r
+#define B4T 0x0270 // 0.0381 * 2^LUX_SCALE\r
+#define M4T 0x03fe // 0.0624 * 2^LUX_SCALE\r
+#define K5T 0x0138 // 0.61 * 2^RATIO_SCALE\r
+#define B5T 0x016f // 0.0224 * 2^LUX_SCALE\r
+#define M5T 0x01fc // 0.0310 * 2^LUX_SCALE\r
+#define K6T 0x019a // 0.80 * 2^RATIO_SCALE\r
+#define B6T 0x00d2 // 0.0128 * 2^LUX_SCALE\r
+#define M6T 0x00fb // 0.0153 * 2^LUX_SCALE\r
+#define K7T 0x029a // 1.3 * 2^RATIO_SCALE\r
+#define B7T 0x0018 // 0.00146 * 2^LUX_SCALE\r
+#define M7T 0x0012 // 0.00112 * 2^LUX_SCALE\r
+#define K8T 0x029a // 1.3 * 2^RATIO_SCALE\r
+#define B8T 0x0000 // 0.000 * 2^LUX_SCALE\r
+#define M8T 0x0000 // 0.000 * 2^LUX_SCALE\r
+\r
+uint32_t CalculateLux(uint8_t iGain, uint8_t tInt, uint16_t ch0, uint16_t ch1)\r
+{\r
+       //????????????????????????????????????????????????????????????????????????\r
+       // first, scale the channel values depending on the gain and integration time\r
+       // 16X, 402mS is nominal.\r
+       // scale if integration time is NOT 402 msec\r
+       uint32_t chScale;\r
+       uint32_t channel1;\r
+       uint32_t channel0;\r
+       switch (tInt)\r
+       {\r
+               case 0: // 13.7 msec\r
+               chScale = CHSCALE_TINT0;\r
+               break;\r
+               case 1: // 101 msec\r
+               chScale = CHSCALE_TINT1;\r
+               break;\r
+               default: // assume no scaling\r
+               chScale = (1 << CH_SCALE);\r
+               break;\r
+       }\r
+       // scale if gain is NOT 16X\r
+       if (!iGain) chScale = chScale << 4; // scale 1X to 16X\r
+       // scale the channel values\r
+       channel0 = (ch0 * chScale) >> CH_SCALE;\r
+       channel1 = (ch1 * chScale) >> CH_SCALE;\r
+       //????????????????????????????????????????????????????????????????????????\r
+       // find the ratio of the channel values (Channel1/Channel0)\r
+       // protect against divide by zero\r
+       uint32_t ratio1 = 0;\r
+       if (channel0 != 0) ratio1 = (channel1 << (RATIO_SCALE+1)) / channel0;\r
+       // round the ratio value\r
+       uint32_t ratio = (ratio1 + 1) >> 1;\r
+       // is ratio <= eachBreak ?\r
+       uint16_t b, m;\r
+               if ((ratio >= 0) && (ratio <= K1T))\r
+               {b=B1T; m=M1T;}\r
+               else if (ratio <= K2T)\r
+               {b=B2T; m=M2T;}\r
+               else if (ratio <= K3T)\r
+               {b=B3T; m=M3T;}\r
+               else if (ratio <= K4T)\r
+               {b=B4T; m=M4T;}\r
+               else if (ratio <= K5T)\r
+               {b=B5T; m=M5T;}\r
+               else if (ratio <= K6T)\r
+               {b=B6T; m=M6T;}\r
+               else if (ratio <= K7T)\r
+               {b=B7T; m=M7T;}\r
+               else if (ratio > K8T)\r
+               {b=B8T; m=M8T;}\r
+       uint32_t temp;\r
+       temp = ((channel0 * b) - (channel1 * m));\r
+       // do not allow negative lux value\r
+       if (temp < 0) temp = 0;\r
+       // round lsb (2^(LUX_SCALE?1))\r
+       temp += (1 << (LUX_SCALE-1));\r
+       // strip off fractional portion\r
+       uint32_t lux = temp ;//>> LUX_SCALE;\r
+       return(lux);\r
+}\r
+\r
+\r
+\r
+\r
+       \r
+\r
index 16f7b06..9f1756e 100644 (file)
@@ -1,17 +1,17 @@
-#ifndef TSL256x_H
-#define TSL256x_H
-
-#define TSL_GAIN16 0x10
-#define TSL_GAIN1 0x00
-#define TSL_INT_TIME1 0x00
-#define TSL_INT_TIME2 0x01
-#define TSL_INT_TIME3 0x02
-
-void TSL256x_init();
-void TSL256x_setup(uint8_t conf);
-uint16_t TSL256x_Ch(uint8_t ch);
- uint32_t CalculateLux(unsigned int iGain, unsigned int tInt, unsigned int ch0, unsigned int ch1);
-
-uint16_t TSL256x_Lux();
-
-#endif
+#ifndef TSL256x_H\r
+#define TSL256x_H\r
+\r
+#define TSL_GAIN16 0x10\r
+#define TSL_GAIN1 0x00\r
+#define TSL_INT_TIME1 0x00\r
+#define TSL_INT_TIME2 0x01\r
+#define TSL_INT_TIME3 0x02\r
+\r
+void TSL256x_init();\r
+void TSL256x_setup(uint8_t conf);\r
+uint16_t TSL256x_Ch(uint8_t ch);\r
+ uint32_t CalculateLux(unsigned int iGain, unsigned int tInt, unsigned int ch0, unsigned int ch1);\r
+\r
+uint16_t TSL256x_Lux();\r
+\r
+#endif\r
index 5e6dea8..d5f2596 100644 (file)
-/*****************************************************************************
-*
-* Atmel Corporation
-*
-* File              : USI_TWI_Master.c
-* Compiler          : AVRGCC Toolchain version 3.4.2
-* Revision          : $Revision: 992 $
-* Date              : $Date: 2013-11-07 $
-* Updated by        : $Author: Atmel $
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : All device with USI module can be used.
-*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313
-*
-* AppNote           : AVR310 - Using the USI module as a TWI Master
-*
-* Description       : This is an implementation of an TWI master using
-*                     the USI module as basis. The implementation assumes the AVR to
-*                     be the only TWI master in the system and can therefore not be
-*                     used in a multi-master system.
-* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() 
-*                     function. Hence messages/data are transceived on the bus using
-*                     the USI_TWI_Transceive() function. The transceive function 
-*                     returns a status byte, which can be used to evaluate the 
-*                     success of the transmission.
-*
-****************************************************************************/
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include "USI_TWI_Master.h"
-#include <util/delay.h>
-
-unsigned char USI_TWI_Master_Transfer( unsigned char );
-unsigned char USI_TWI_Master_Stop( void );
-
-union  USI_TWI_state
-{
-  unsigned char errorState;         // Can reuse the TWI_state for error states due to that it will not be need if there exists an error.
-  struct
-  {
-    unsigned char addressMode         : 1;
-    unsigned char masterWriteDataMode : 1;
-    unsigned char unused              : 6;
-  }; 
-}   USI_TWI_state;
-
-/*---------------------------------------------------------------
- USI TWI single master initialization function
----------------------------------------------------------------*/
-void USI_TWI_Master_Initialise( void )
-{
-  PORT_USI |= (1<<PIN_USI_SDA);           // Enable pullup on SDA, to set high as released state.
-  PORT_USI |= (1<<PIN_USI_SCL);           // Enable pullup on SCL, to set high as released state.
-  
-  DDR_USI  |= (1<<PIN_USI_SCL);           // Enable SCL as output.
-  DDR_USI  |= (1<<PIN_USI_SDA);           // Enable SDA as output.
-  
-  USIDR    =  0xFF;                       // Preload dataregister with "released level" data.
-  USICR    =  (0<<USISIE)|(0<<USIOIE)|                            // Disable Interrupts.
-              (1<<USIWM1)|(0<<USIWM0)|                            // Set USI in Two-wire mode.
-              (1<<USICS1)|(0<<USICS0)|(1<<USICLK)|                // Software stobe as counter clock source
-              (0<<USITC);
-  USISR   =   (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Clear flags,
-              (0x0<<USICNT0);                                     // and reset counter.
-}
-
-/*---------------------------------------------------------------
-Use this function to get hold of the error message from the last transmission
----------------------------------------------------------------*/
-unsigned char USI_TWI_Get_State_Info( void )
-{
-  return ( USI_TWI_state.errorState );                            // Return error state.
-}
-
-/*---------------------------------------------------------------
- USI Transmit and receive function. LSB of first byte in data 
- indicates if a read or write cycles is performed. If set a read
- operation is performed.
-
- Function generates (Repeated) Start Condition, sends address and
- R/W, Reads/Writes Data, and verifies/sends ACK.
- Success or error code is returned. Error codes are defined in 
- USI_TWI_Master.h
----------------------------------------------------------------*/
-unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize)
-{
-  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-                                 (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.
-  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-                                 (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.
-
-  USI_TWI_state.errorState = 0;
-  USI_TWI_state.addressMode = TRUE;
-
-#ifdef PARAM_VERIFICATION
-  if(msg > (unsigned char*)RAMEND)                 // Test if address is outside SRAM space
-  {
-    USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND;
-    return (FALSE);
-  }
-  if(msgSize <= 1)                                 // Test if the transmission buffer is empty
-  {
-    USI_TWI_state.errorState = USI_TWI_NO_DATA;
-    return (FALSE);
-  }
-#endif
-
-#ifdef NOISE_TESTING                                // Test if any unexpected conditions have arrived prior to this execution.
-  if( USISR & (1<<USISIF) )
-  {
-    USI_TWI_state.errorState = USI_TWI_UE_START_CON;
-    return (FALSE);
-  }
-  if( USISR & (1<<USIPF) )
-  {
-    USI_TWI_state.errorState = USI_TWI_UE_STOP_CON;
-    return (FALSE);
-  }
-  if( USISR & (1<<USIDC) )
-  {
-    USI_TWI_state.errorState = USI_TWI_UE_DATA_COL;
-    return (FALSE);
-  }
-#endif
-
-  if ( !(*msg & (1<<TWI_READ_BIT)) )                // The LSB in the address byte determines if is a masterRead or masterWrite operation.
-  {
-    USI_TWI_state.masterWriteDataMode = TRUE;
-  }
-
-/* Release SCL to ensure that (repeated) Start can be performed */
-  PORT_USI |= (1<<PIN_USI_SCL);                     // Release SCL.
-  while( !(PIN_USI & (1<<PIN_USI_SCL)) );          // Verify that SCL becomes high.
-#ifdef TWI_FAST_MODE
-  _delay_us( T4_TWI/4 );                         // Delay for T4TWI if TWI_FAST_MODE
-#else
-  _delay_us( T2_TWI/4 );                         // Delay for T2TWI if TWI_STANDARD_MODE
-#endif
-
-/* Generate Start Condition */
-  PORT_USI &= ~(1<<PIN_USI_SDA);                    // Force SDA LOW.
-  _delay_us( T4_TWI/4 );                         
-  PORT_USI &= ~(1<<PIN_USI_SCL);                    // Pull SCL LOW.
-  PORT_USI |= (1<<PIN_USI_SDA);                     // Release SDA.
-
-#ifdef SIGNAL_VERIFY
-  if( !(USISR & (1<<USISIF)) )
-  {
-    USI_TWI_state.errorState = USI_TWI_MISSING_START_CON;  
-    return (FALSE);
-  }
-#endif
-
-/*Write address and Read/Write data */
-  do
-  {
-    /* If masterWrite cycle (or inital address tranmission)*/
-    if (USI_TWI_state.addressMode || USI_TWI_state.masterWriteDataMode)
-    {
-      /* Write a byte */
-      PORT_USI &= ~(1<<PIN_USI_SCL);                // Pull SCL LOW.
-      USIDR     = *(msg++);                        // Setup data.
-      USI_TWI_Master_Transfer( tempUSISR_8bit );    // Send 8 bits on bus.
-      
-      /* Clock and verify (N)ACK from slave */
-      DDR_USI  &= ~(1<<PIN_USI_SDA);                // Enable SDA as input.
-      if( USI_TWI_Master_Transfer( tempUSISR_1bit ) & (1<<TWI_NACK_BIT) ) 
-      {
-        if ( USI_TWI_state.addressMode )
-          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_ADDRESS;
-        else
-          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_DATA;
-        return (FALSE);
-      }
-      USI_TWI_state.addressMode = FALSE;            // Only perform address transmission once.
-    }
-    /* Else masterRead cycle*/
-    else
-    {
-      /* Read a data byte */
-      DDR_USI   &= ~(1<<PIN_USI_SDA);               // Enable SDA as input.
-      *(msg++)  = USI_TWI_Master_Transfer( tempUSISR_8bit );
-
-      /* Prepare to generate ACK (or NACK in case of End Of Transmission) */
-      if( msgSize == 1)                            // If transmission of last byte was performed.
-      {
-        USIDR = 0xFF;                              // Load NACK to confirm End Of Transmission.
-      }
-      else
-      {
-        USIDR = 0x00;                              // Load ACK. Set data register bit 7 (output for SDA) low.
-      }
-      USI_TWI_Master_Transfer( tempUSISR_1bit );   // Generate ACK/NACK.
-    }
-  }while( --msgSize) ;                             // Until all data sent/received.
-  
-  USI_TWI_Master_Stop();                           // Send a STOP condition on the TWI bus.
-
-/* Transmission successfully completed*/
-  return (TRUE);
-}
-
-/*---------------------------------------------------------------
- Core function for shifting data in and out from the USI.
- Data to be sent has to be placed into the USIDR prior to calling
- this function. Data read, will be return'ed from the function.
----------------------------------------------------------------*/
-unsigned char USI_TWI_Master_Transfer( unsigned char temp )
-{
-  USISR = temp;                                     // Set USISR according to temp.
-                                                    // Prepare clocking.
-  temp  =  (0<<USISIE)|(0<<USIOIE)|                 // Interrupts disabled
-           (1<<USIWM1)|(0<<USIWM0)|                 // Set USI in Two-wire mode.
-           (1<<USICS1)|(0<<USICS0)|(1<<USICLK)|     // Software clock strobe as source.
-           (1<<USITC);                              // Toggle Clock Port.
-  do
-  {
-    _delay_us( T2_TWI/4 );              
-    USICR = temp;                          // Generate positve SCL edge.
-    while( !(PIN_USI & (1<<PIN_USI_SCL)) );// Wait for SCL to go high.
-    _delay_us( T4_TWI/4 );              
-    USICR = temp;                          // Generate negative SCL edge.
-  }while( !(USISR & (1<<USIOIF)) );        // Check for transfer complete.
-  
-  _delay_us( T2_TWI/4 );                
-  temp  = USIDR;                           // Read out data.
-  USIDR = 0xFF;                            // Release SDA.
-  DDR_USI |= (1<<PIN_USI_SDA);             // Enable SDA as output.
-
-  return temp;                             // Return the data from the USIDR
-}
-
-/*---------------------------------------------------------------
- Function for generating a TWI Stop Condition. Used to release 
- the TWI bus.
----------------------------------------------------------------*/
-unsigned char USI_TWI_Master_Stop( void )
-{
-  PORT_USI &= ~(1<<PIN_USI_SDA);           // Pull SDA low.
-  PORT_USI |= (1<<PIN_USI_SCL);            // Release SCL.
-  while( !(PIN_USI & (1<<PIN_USI_SCL)) );  // Wait for SCL to go high.
-  _delay_us( T4_TWI/4 );               
-  PORT_USI |= (1<<PIN_USI_SDA);            // Release SDA.
-  _delay_us( T2_TWI/4 );                
-  
-#ifdef SIGNAL_VERIFY
-  if( !(USISR & (1<<USIPF)) )
-  {
-    USI_TWI_state.errorState = USI_TWI_MISSING_STOP_CON;    
-    return (FALSE);
-  }
-#endif
-
-  return (TRUE);
-}
-
-
-
-unsigned char I2c_WriteByte(unsigned char msg) {
-  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-  (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.
-  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-  (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.
-
-       /* Write a byte */
-       PORT_USI &= ~(1<<PIN_USI_SCL);                // Pull SCL LOW.
-       USIDR     = msg;                        // Setup data.
-       USI_TWI_Master_Transfer( tempUSISR_8bit );    // Send 8 bits on bus.
-       /* Clock and verify (N)ACK from slave */
-       DDR_USI  &= ~(1<<PIN_USI_SDA);                // Enable SDA as input.
-       if( USI_TWI_Master_Transfer( tempUSISR_1bit ) & (1<<TWI_NACK_BIT) ){
-               if ( USI_TWI_state.addressMode )
-                       USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_ADDRESS;
-               else
-                       USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_DATA;
-               return 2;
-       }
-       return 0;
-}
-unsigned char I2c_ReadByte(unsigned char ack_mode) {
-  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-  (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.
-  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and
-  (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.
-       
-       /* Read a data byte */
-       DDR_USI   &= ~(1<<PIN_USI_SDA);               // Enable SDA as input.
-    unsigned char msg = USI_TWI_Master_Transfer( tempUSISR_8bit );
-
-    /* Prepare to generate ACK (or NACK in case of End Of Transmission) */
-    if( ack_mode == NO_ACK) {                           // If transmission of last byte was performed.
-               USIDR = 0xFF;                              // Load NACK to confirm End Of Transmission.
-    } else   {
-               USIDR = 0x00;                              // Load ACK. Set data register bit 7 (output for SDA) low.
-    }
-    USI_TWI_Master_Transfer( tempUSISR_1bit );   // Generate ACK/NACK.
-       return msg;
-}
-
-void I2c_StartCondition() {
-/* Release SCL to ensure that (repeated) Start can be performed */
-PORT_USI |= (1<<PIN_USI_SCL);                     // Release SCL.
-while( !(PIN_USI & (1<<PIN_USI_SCL)) );          // Verify that SCL becomes high.
-#ifdef TWI_FAST_MODE
-_delay_us( T4_TWI/4 );                         // Delay for T4TWI if TWI_FAST_MODE
-#else
-_delay_us( T2_TWI/4 );                         // Delay for T2TWI if TWI_STANDARD_MODE
-#endif
-
-/* Generate Start Condition */
-PORT_USI &= ~(1<<PIN_USI_SDA);                    // Force SDA LOW.
-_delay_us( T4_TWI/4 );
-PORT_USI &= ~(1<<PIN_USI_SCL);                    // Pull SCL LOW.
-PORT_USI |= (1<<PIN_USI_SDA);                     // Release SDA.
-       
-       
-}
-void I2c_StopCondition() {
-       USI_TWI_Master_Stop();
-}
+/*****************************************************************************\r
+*\r
+* Atmel Corporation\r
+*\r
+* File              : USI_TWI_Master.c\r
+* Compiler          : AVRGCC Toolchain version 3.4.2\r
+* Revision          : $Revision: 992 $\r
+* Date              : $Date: 2013-11-07 $\r
+* Updated by        : $Author: Atmel $\r
+*\r
+* Support mail      : avr@atmel.com\r
+*\r
+* Supported devices : All device with USI module can be used.\r
+*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313\r
+*\r
+* AppNote           : AVR310 - Using the USI module as a TWI Master\r
+*\r
+* Description       : This is an implementation of an TWI master using\r
+*                     the USI module as basis. The implementation assumes the AVR to\r
+*                     be the only TWI master in the system and can therefore not be\r
+*                     used in a multi-master system.\r
+* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() \r
+*                     function. Hence messages/data are transceived on the bus using\r
+*                     the USI_TWI_Transceive() function. The transceive function \r
+*                     returns a status byte, which can be used to evaluate the \r
+*                     success of the transmission.\r
+*\r
+****************************************************************************/\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include "USI_TWI_Master.h"\r
+#include <util/delay.h>\r
+\r
+unsigned char USI_TWI_Master_Transfer( unsigned char );\r
+unsigned char USI_TWI_Master_Stop( void );\r
+\r
+union  USI_TWI_state\r
+{\r
+  unsigned char errorState;         // Can reuse the TWI_state for error states due to that it will not be need if there exists an error.\r
+  struct\r
+  {\r
+    unsigned char addressMode         : 1;\r
+    unsigned char masterWriteDataMode : 1;\r
+    unsigned char unused              : 6;\r
+  }; \r
+}   USI_TWI_state;\r
+\r
+/*---------------------------------------------------------------\r
+ USI TWI single master initialization function\r
+---------------------------------------------------------------*/\r
+void USI_TWI_Master_Initialise( void )\r
+{\r
+  PORT_USI |= (1<<PIN_USI_SDA);           // Enable pullup on SDA, to set high as released state.\r
+  PORT_USI |= (1<<PIN_USI_SCL);           // Enable pullup on SCL, to set high as released state.\r
+  \r
+  DDR_USI  |= (1<<PIN_USI_SCL);           // Enable SCL as output.\r
+  DDR_USI  |= (1<<PIN_USI_SDA);           // Enable SDA as output.\r
+  \r
+  USIDR    =  0xFF;                       // Preload dataregister with "released level" data.\r
+  USICR    =  (0<<USISIE)|(0<<USIOIE)|                            // Disable Interrupts.\r
+              (1<<USIWM1)|(0<<USIWM0)|                            // Set USI in Two-wire mode.\r
+              (1<<USICS1)|(0<<USICS0)|(1<<USICLK)|                // Software stobe as counter clock source\r
+              (0<<USITC);\r
+  USISR   =   (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Clear flags,\r
+              (0x0<<USICNT0);                                     // and reset counter.\r
+}\r
+\r
+/*---------------------------------------------------------------\r
+Use this function to get hold of the error message from the last transmission\r
+---------------------------------------------------------------*/\r
+unsigned char USI_TWI_Get_State_Info( void )\r
+{\r
+  return ( USI_TWI_state.errorState );                            // Return error state.\r
+}\r
+\r
+/*---------------------------------------------------------------\r
+ USI Transmit and receive function. LSB of first byte in data \r
+ indicates if a read or write cycles is performed. If set a read\r
+ operation is performed.\r
+\r
+ Function generates (Repeated) Start Condition, sends address and\r
+ R/W, Reads/Writes Data, and verifies/sends ACK.\r
\r
+ Success or error code is returned. Error codes are defined in \r
+ USI_TWI_Master.h\r
+---------------------------------------------------------------*/\r
+unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize)\r
+{\r
+  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+                                 (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.\r
+  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+                                 (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.\r
+\r
+  USI_TWI_state.errorState = 0;\r
+  USI_TWI_state.addressMode = TRUE;\r
+\r
+#ifdef PARAM_VERIFICATION\r
+  if(msg > (unsigned char*)RAMEND)                 // Test if address is outside SRAM space\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND;\r
+    return (FALSE);\r
+  }\r
+  if(msgSize <= 1)                                 // Test if the transmission buffer is empty\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_NO_DATA;\r
+    return (FALSE);\r
+  }\r
+#endif\r
+\r
+#ifdef NOISE_TESTING                                // Test if any unexpected conditions have arrived prior to this execution.\r
+  if( USISR & (1<<USISIF) )\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_UE_START_CON;\r
+    return (FALSE);\r
+  }\r
+  if( USISR & (1<<USIPF) )\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_UE_STOP_CON;\r
+    return (FALSE);\r
+  }\r
+  if( USISR & (1<<USIDC) )\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_UE_DATA_COL;\r
+    return (FALSE);\r
+  }\r
+#endif\r
+\r
+  if ( !(*msg & (1<<TWI_READ_BIT)) )                // The LSB in the address byte determines if is a masterRead or masterWrite operation.\r
+  {\r
+    USI_TWI_state.masterWriteDataMode = TRUE;\r
+  }\r
+\r
+/* Release SCL to ensure that (repeated) Start can be performed */\r
+  PORT_USI |= (1<<PIN_USI_SCL);                     // Release SCL.\r
+  while( !(PIN_USI & (1<<PIN_USI_SCL)) );          // Verify that SCL becomes high.\r
+#ifdef TWI_FAST_MODE\r
+  _delay_us( T4_TWI/4 );                         // Delay for T4TWI if TWI_FAST_MODE\r
+#else\r
+  _delay_us( T2_TWI/4 );                         // Delay for T2TWI if TWI_STANDARD_MODE\r
+#endif\r
+\r
+/* Generate Start Condition */\r
+  PORT_USI &= ~(1<<PIN_USI_SDA);                    // Force SDA LOW.\r
+  _delay_us( T4_TWI/4 );                         \r
+  PORT_USI &= ~(1<<PIN_USI_SCL);                    // Pull SCL LOW.\r
+  PORT_USI |= (1<<PIN_USI_SDA);                     // Release SDA.\r
+\r
+#ifdef SIGNAL_VERIFY\r
+  if( !(USISR & (1<<USISIF)) )\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_MISSING_START_CON;  \r
+    return (FALSE);\r
+  }\r
+#endif\r
+\r
+/*Write address and Read/Write data */\r
+  do\r
+  {\r
+    /* If masterWrite cycle (or inital address tranmission)*/\r
+    if (USI_TWI_state.addressMode || USI_TWI_state.masterWriteDataMode)\r
+    {\r
+      /* Write a byte */\r
+      PORT_USI &= ~(1<<PIN_USI_SCL);                // Pull SCL LOW.\r
+      USIDR     = *(msg++);                        // Setup data.\r
+      USI_TWI_Master_Transfer( tempUSISR_8bit );    // Send 8 bits on bus.\r
+      \r
+      /* Clock and verify (N)ACK from slave */\r
+      DDR_USI  &= ~(1<<PIN_USI_SDA);                // Enable SDA as input.\r
+      if( USI_TWI_Master_Transfer( tempUSISR_1bit ) & (1<<TWI_NACK_BIT) ) \r
+      {\r
+        if ( USI_TWI_state.addressMode )\r
+          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_ADDRESS;\r
+        else\r
+          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_DATA;\r
+        return (FALSE);\r
+      }\r
+      USI_TWI_state.addressMode = FALSE;            // Only perform address transmission once.\r
+    }\r
+    /* Else masterRead cycle*/\r
+    else\r
+    {\r
+      /* Read a data byte */\r
+      DDR_USI   &= ~(1<<PIN_USI_SDA);               // Enable SDA as input.\r
+      *(msg++)  = USI_TWI_Master_Transfer( tempUSISR_8bit );\r
+\r
+      /* Prepare to generate ACK (or NACK in case of End Of Transmission) */\r
+      if( msgSize == 1)                            // If transmission of last byte was performed.\r
+      {\r
+        USIDR = 0xFF;                              // Load NACK to confirm End Of Transmission.\r
+      }\r
+      else\r
+      {\r
+        USIDR = 0x00;                              // Load ACK. Set data register bit 7 (output for SDA) low.\r
+      }\r
+      USI_TWI_Master_Transfer( tempUSISR_1bit );   // Generate ACK/NACK.\r
+    }\r
+  }while( --msgSize) ;                             // Until all data sent/received.\r
+  \r
+  USI_TWI_Master_Stop();                           // Send a STOP condition on the TWI bus.\r
+\r
+/* Transmission successfully completed*/\r
+  return (TRUE);\r
+}\r
+\r
+/*---------------------------------------------------------------\r
+ Core function for shifting data in and out from the USI.\r
+ Data to be sent has to be placed into the USIDR prior to calling\r
+ this function. Data read, will be return'ed from the function.\r
+---------------------------------------------------------------*/\r
+unsigned char USI_TWI_Master_Transfer( unsigned char temp )\r
+{\r
+  USISR = temp;                                     // Set USISR according to temp.\r
+                                                    // Prepare clocking.\r
+  temp  =  (0<<USISIE)|(0<<USIOIE)|                 // Interrupts disabled\r
+           (1<<USIWM1)|(0<<USIWM0)|                 // Set USI in Two-wire mode.\r
+           (1<<USICS1)|(0<<USICS0)|(1<<USICLK)|     // Software clock strobe as source.\r
+           (1<<USITC);                              // Toggle Clock Port.\r
+  do\r
+  {\r
+    _delay_us( T2_TWI/4 );              \r
+    USICR = temp;                          // Generate positve SCL edge.\r
+    while( !(PIN_USI & (1<<PIN_USI_SCL)) );// Wait for SCL to go high.\r
+    _delay_us( T4_TWI/4 );              \r
+    USICR = temp;                          // Generate negative SCL edge.\r
+  }while( !(USISR & (1<<USIOIF)) );        // Check for transfer complete.\r
+  \r
+  _delay_us( T2_TWI/4 );                \r
+  temp  = USIDR;                           // Read out data.\r
+  USIDR = 0xFF;                            // Release SDA.\r
+  DDR_USI |= (1<<PIN_USI_SDA);             // Enable SDA as output.\r
+\r
+  return temp;                             // Return the data from the USIDR\r
+}\r
+\r
+/*---------------------------------------------------------------\r
+ Function for generating a TWI Stop Condition. Used to release \r
+ the TWI bus.\r
+---------------------------------------------------------------*/\r
+unsigned char USI_TWI_Master_Stop( void )\r
+{\r
+  PORT_USI &= ~(1<<PIN_USI_SDA);           // Pull SDA low.\r
+  PORT_USI |= (1<<PIN_USI_SCL);            // Release SCL.\r
+  while( !(PIN_USI & (1<<PIN_USI_SCL)) );  // Wait for SCL to go high.\r
+  _delay_us( T4_TWI/4 );               \r
+  PORT_USI |= (1<<PIN_USI_SDA);            // Release SDA.\r
+  _delay_us( T2_TWI/4 );                \r
+  \r
+#ifdef SIGNAL_VERIFY\r
+  if( !(USISR & (1<<USIPF)) )\r
+  {\r
+    USI_TWI_state.errorState = USI_TWI_MISSING_STOP_CON;    \r
+    return (FALSE);\r
+  }\r
+#endif\r
+\r
+  return (TRUE);\r
+}\r
+\r
+\r
+\r
+unsigned char I2c_WriteByte(unsigned char msg) {\r
+  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+  (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.\r
+  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+  (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.\r
+\r
+       /* Write a byte */\r
+       PORT_USI &= ~(1<<PIN_USI_SCL);                // Pull SCL LOW.\r
+       USIDR     = msg;                        // Setup data.\r
+       USI_TWI_Master_Transfer( tempUSISR_8bit );    // Send 8 bits on bus.\r
+       /* Clock and verify (N)ACK from slave */\r
+       DDR_USI  &= ~(1<<PIN_USI_SDA);                // Enable SDA as input.\r
+       if( USI_TWI_Master_Transfer( tempUSISR_1bit ) & (1<<TWI_NACK_BIT) ){\r
+               if ( USI_TWI_state.addressMode )\r
+                       USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_ADDRESS;\r
+               else\r
+                       USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_DATA;\r
+               return 2;\r
+       }\r
+       return 0;\r
+}\r
+unsigned char I2c_ReadByte(unsigned char ack_mode) {\r
+  unsigned char tempUSISR_8bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+  (0x0<<USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.\r
+  unsigned char tempUSISR_1bit = (1<<USISIF)|(1<<USIOIF)|(1<<USIPF)|(1<<USIDC)|      // Prepare register value to: Clear flags, and\r
+  (0xE<<USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.\r
+       \r
+       /* Read a data byte */\r
+       DDR_USI   &= ~(1<<PIN_USI_SDA);               // Enable SDA as input.\r
+    unsigned char msg = USI_TWI_Master_Transfer( tempUSISR_8bit );\r
+\r
+    /* Prepare to generate ACK (or NACK in case of End Of Transmission) */\r
+    if( ack_mode == NO_ACK) {                           // If transmission of last byte was performed.\r
+               USIDR = 0xFF;                              // Load NACK to confirm End Of Transmission.\r
+    } else   {\r
+               USIDR = 0x00;                              // Load ACK. Set data register bit 7 (output for SDA) low.\r
+    }\r
+    USI_TWI_Master_Transfer( tempUSISR_1bit );   // Generate ACK/NACK.\r
+       return msg;\r
+}\r
+\r
+void I2c_StartCondition(void) {\r
+/* Release SCL to ensure that (repeated) Start can be performed */\r
+PORT_USI |= (1<<PIN_USI_SCL);                     // Release SCL.\r
+while( !(PIN_USI & (1<<PIN_USI_SCL)) );          // Verify that SCL becomes high.\r
+#ifdef TWI_FAST_MODE\r
+_delay_us( T4_TWI/4 );                         // Delay for T4TWI if TWI_FAST_MODE\r
+#else\r
+_delay_us( T2_TWI/4 );                         // Delay for T2TWI if TWI_STANDARD_MODE\r
+#endif\r
+\r
+/* Generate Start Condition */\r
+PORT_USI &= ~(1<<PIN_USI_SDA);                    // Force SDA LOW.\r
+_delay_us( T4_TWI/4 );\r
+PORT_USI &= ~(1<<PIN_USI_SCL);                    // Pull SCL LOW.\r
+PORT_USI |= (1<<PIN_USI_SDA);                     // Release SDA.\r
+       \r
+       \r
+}\r
+void I2c_StopCondition(void) {\r
+       USI_TWI_Master_Stop();\r
+}\r
index dbf9da1..f91c41b 100644 (file)
-/*****************************************************************************
-*
-* Atmel Corporation
-*
-* File              : USI_TWI_Master.h
-* Compiler          : AVRGCC Toolchain version 3.4.2
-* Revision          : $Revision: 992 $
-* Date              : $Date: 2013-11-07 $
-* Updated by        : $Author: Atmel $
-*
-* Support mail      : avr@atmel.com
-*
-* Supported devices : All device with USI module can be used.
-*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313
-*
-* AppNote           : AVR310 - Using the USI module as a TWI Master
-*
-* Description       : This is an implementation of an TWI master using
-*                     the USI module as basis. The implementation assumes the AVR to
-*                     be the only TWI master in the system and can therefore not be
-*                     used in a multi-master system.
-* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() 
-*                     function. Hence messages/data are transceived on the bus using
-*                     the USI_TWI_Start_Transceiver_With_Data() function. If the transceiver
-*                     returns with a fail, then use USI_TWI_Get_Status_Info to evaluate the 
-*                     couse of the failure.
-*
-****************************************************************************/
-    #include<avr/io.h> 
-//********** Defines **********//
-
-// Defines controlling timing limits
-#define TWI_FAST_MODE
-
-#define SYS_CLK   8000.0  // [kHz]
-
-#ifdef TWI_FAST_MODE               // TWI FAST mode timing limits. SCL = 100-400kHz
-  #define T2_TWI    ((SYS_CLK *1300) /1000000) +1 // >1,3us
-  #define T4_TWI    ((SYS_CLK * 600) /1000000) +1 // >0,6us
-  
-#else                              // TWI STANDARD mode timing limits. SCL <= 100kHz
-  #define T2_TWI    ((SYS_CLK *4700) /1000000) +1 // >4,7us
-  #define T4_TWI    ((SYS_CLK *4000) /1000000) +1 // >4,0us
-#endif
-
-// Defines controling code generating
-//#define PARAM_VERIFICATION
-//#define NOISE_TESTING
-//#define SIGNAL_VERIFY
-
-//USI_TWI messages and flags and bit masks
-//#define SUCCESS   7
-//#define MSG       0
-/****************************************************************************
-  Bit and byte definitions
-****************************************************************************/
-#define TWI_READ_BIT  0       // Bit position for R/W bit in "address byte".
-#define TWI_ADR_BITS  1       // Bit position for LSB of the slave address bits in the init byte.
-#define TWI_NACK_BIT  0       // Bit position for (N)ACK bit.
-
-#define USI_TWI_NO_DATA             0x00  // Transmission buffer is empty
-#define USI_TWI_DATA_OUT_OF_BOUND   0x01  // Transmission buffer is outside SRAM space
-#define USI_TWI_UE_START_CON        0x02  // Unexpected Start Condition
-#define USI_TWI_UE_STOP_CON         0x03  // Unexpected Stop Condition
-#define USI_TWI_UE_DATA_COL         0x04  // Unexpected Data Collision (arbitration)
-#define USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data
-#define USI_TWI_NO_ACK_ON_ADDRESS   0x06  // The slave did not acknowledge  the address
-#define USI_TWI_MISSING_START_CON   0x07  // Generated Start Condition not detected on bus
-#define USI_TWI_MISSING_STOP_CON    0x08  // Generated Stop Condition not detected on bus
-
-// Device dependant defines
-
-#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \
-    defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \
-    defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \
-    defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \
-    defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \
-    defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__)
-    #define DDR_USI             DDRE
-    #define PORT_USI            PORTE
-    #define PIN_USI             PINE
-    #define PORT_USI_SDA        PORTE5
-    #define PORT_USI_SCL        PORTE4
-    #define PIN_USI_SDA         PINE5
-    #define PIN_USI_SCL         PINE4
-#endif
-
-#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \
-    defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__)
-    #define DDR_USI             DDRB
-    #define PORT_USI            PORTB
-    #define PIN_USI             PINB
-    #define PORT_USI_SDA        PORTB0
-    #define PORT_USI_SCL        PORTB2
-    #define PIN_USI_SDA         PINB0
-    #define PIN_USI_SCL         PINB2
-#endif
-
-#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__)
-    #define DDR_USI             DDRB
-    #define PORT_USI            PORTB
-    #define PIN_USI             PINB
-    #define PORT_USI_SDA        PORTB5
-    #define PORT_USI_SCL        PORTB7
-    #define PIN_USI_SDA         PINB5
-    #define PIN_USI_SCL         PINB7
-#endif
-
-#if defined(__AVR_ATtiny84__) | defined(__AVR_ATtiny84A__)
-#define DDR_USI             DDRA
-#define PORT_USI            PORTA
-#define PIN_USI             PINA
-#define PORT_USI_SDA        PORTA6
-#define PORT_USI_SCL        PORTA4
-#define PIN_USI_SDA         PINA6
-#define PIN_USI_SCL         PINA4
-#endif
-
-// General defines
-#define TRUE  1
-#define FALSE 0
-
-#define ACK (1<<TWI_NACK_BIT )
-#define NO_ACK 0
-
-
-//********** Prototypes **********//
-
-void USI_TWI_Master_Initialise( void );
-unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char * , unsigned char );
-unsigned char USI_TWI_Get_State_Info( void );
-
-unsigned char I2c_WriteByte(unsigned char msg);
-unsigned char I2c_ReadByte(unsigned char ack_mode);
-void I2c_StartCondition();
-void I2c_StopCondition();
-
+/*****************************************************************************\r
+*\r
+* Atmel Corporation\r
+*\r
+* File              : USI_TWI_Master.h\r
+* Compiler          : AVRGCC Toolchain version 3.4.2\r
+* Revision          : $Revision: 992 $\r
+* Date              : $Date: 2013-11-07 $\r
+* Updated by        : $Author: Atmel $\r
+*\r
+* Support mail      : avr@atmel.com\r
+*\r
+* Supported devices : All device with USI module can be used.\r
+*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313\r
+*\r
+* AppNote           : AVR310 - Using the USI module as a TWI Master\r
+*\r
+* Description       : This is an implementation of an TWI master using\r
+*                     the USI module as basis. The implementation assumes the AVR to\r
+*                     be the only TWI master in the system and can therefore not be\r
+*                     used in a multi-master system.\r
+* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() \r
+*                     function. Hence messages/data are transceived on the bus using\r
+*                     the USI_TWI_Start_Transceiver_With_Data() function. If the transceiver\r
+*                     returns with a fail, then use USI_TWI_Get_Status_Info to evaluate the \r
+*                     couse of the failure.\r
+*\r
+****************************************************************************/\r
+    #include<avr/io.h> \r
+//********** Defines **********//\r
+\r
+// Defines controlling timing limits\r
+#define TWI_FAST_MODE\r
+\r
+#define SYS_CLK   8000.0  // [kHz]\r
+\r
+#ifdef TWI_FAST_MODE               // TWI FAST mode timing limits. SCL = 100-400kHz\r
+  #define T2_TWI    ((SYS_CLK *1300) /1000000) +1 // >1,3us\r
+  #define T4_TWI    ((SYS_CLK * 600) /1000000) +1 // >0,6us\r
+  \r
+#else                              // TWI STANDARD mode timing limits. SCL <= 100kHz\r
+  #define T2_TWI    ((SYS_CLK *4700) /1000000) +1 // >4,7us\r
+  #define T4_TWI    ((SYS_CLK *4000) /1000000) +1 // >4,0us\r
+#endif\r
+\r
+// Defines controling code generating\r
+//#define PARAM_VERIFICATION\r
+//#define NOISE_TESTING\r
+//#define SIGNAL_VERIFY\r
+\r
+//USI_TWI messages and flags and bit masks\r
+//#define SUCCESS   7\r
+//#define MSG       0\r
+/****************************************************************************\r
+  Bit and byte definitions\r
+****************************************************************************/\r
+#define TWI_READ_BIT  0       // Bit position for R/W bit in "address byte".\r
+#define TWI_ADR_BITS  1       // Bit position for LSB of the slave address bits in the init byte.\r
+#define TWI_NACK_BIT  0       // Bit position for (N)ACK bit.\r
+\r
+#define USI_TWI_NO_DATA             0x00  // Transmission buffer is empty\r
+#define USI_TWI_DATA_OUT_OF_BOUND   0x01  // Transmission buffer is outside SRAM space\r
+#define USI_TWI_UE_START_CON        0x02  // Unexpected Start Condition\r
+#define USI_TWI_UE_STOP_CON         0x03  // Unexpected Stop Condition\r
+#define USI_TWI_UE_DATA_COL         0x04  // Unexpected Data Collision (arbitration)\r
+#define USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data\r
+#define USI_TWI_NO_ACK_ON_ADDRESS   0x06  // The slave did not acknowledge  the address\r
+#define USI_TWI_MISSING_START_CON   0x07  // Generated Start Condition not detected on bus\r
+#define USI_TWI_MISSING_STOP_CON    0x08  // Generated Stop Condition not detected on bus\r
+\r
+// Device dependant defines\r
+\r
+#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \\r
+    defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \\r
+    defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \\r
+    defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \\r
+    defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \\r
+    defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__)\r
+    #define DDR_USI             DDRE\r
+    #define PORT_USI            PORTE\r
+    #define PIN_USI             PINE\r
+    #define PORT_USI_SDA        PORTE5\r
+    #define PORT_USI_SCL        PORTE4\r
+    #define PIN_USI_SDA         PINE5\r
+    #define PIN_USI_SCL         PINE4\r
+#endif\r
+\r
+#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \\r
+    defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__)\r
+    #define DDR_USI             DDRB\r
+    #define PORT_USI            PORTB\r
+    #define PIN_USI             PINB\r
+    #define PORT_USI_SDA        PORTB0\r
+    #define PORT_USI_SCL        PORTB2\r
+    #define PIN_USI_SDA         PINB0\r
+    #define PIN_USI_SCL         PINB2\r
+#endif\r
+\r
+#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__)\r
+    #define DDR_USI             DDRB\r
+    #define PORT_USI            PORTB\r
+    #define PIN_USI             PINB\r
+    #define PORT_USI_SDA        PORTB5\r
+    #define PORT_USI_SCL        PORTB7\r
+    #define PIN_USI_SDA         PINB5\r
+    #define PIN_USI_SCL         PINB7\r
+#endif\r
+\r
+#if defined(__AVR_ATtiny84__) | defined(__AVR_ATtiny84A__)\r
+#define DDR_USI             DDRA\r
+#define PORT_USI            PORTA\r
+#define PIN_USI             PINA\r
+#define PORT_USI_SDA        PORTA6\r
+#define PORT_USI_SCL        PORTA4\r
+#define PIN_USI_SDA         PINA6\r
+#define PIN_USI_SCL         PINA4\r
+#endif\r
+\r
+// General defines\r
+#define TRUE  1\r
+#define FALSE 0\r
+\r
+#define ACK (1<<TWI_NACK_BIT )\r
+#define NO_ACK 0\r
+\r
+\r
+//********** Prototypes **********//\r
+\r
+void USI_TWI_Master_Initialise( void );\r
+unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char * , unsigned char );\r
+unsigned char USI_TWI_Get_State_Info( void );\r
+\r
+unsigned char I2c_WriteByte(unsigned char msg);\r
+unsigned char I2c_ReadByte(unsigned char ack_mode);\r
+void I2c_StartCondition(void);\r
+void I2c_StopCondition(void);\r
+\r
index a26690a..c3cff91 100644 (file)
@@ -1,82 +1,82 @@
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-.comm crc,2
-#define _CRC16_
-
-CRC16_alg:
-       ;crc
-       push r_crc
-       lds r_crc,crc;lade low byte fuer vergleich mit bit
-       mov r_temp,r_crc
-       andi r_temp,0x01 ;nur bit 0
-       cp r_temp2,r_temp  ;r_temp2 wird in interruptroutine gesetzt
-       brne crc2 ;nur schieben
-       ;schieben und XOR
-       lds r_temp2,crc+1
-       lsr     r_temp2
-       ror     r_crc
-       ldi     r_temp, 0x01    
-       eor     r_crc, r_temp
-       ldi     r_temp, 0xA0    ;
-       eor     r_temp2, r_temp
-       rjmp crce
-crc2:
-       lds r_temp2,crc+1
-       lsr     r_temp2
-       ror     r_crc
-crce:
-       sts crc,r_crc
-       sts crc+1,r_temp2
-       pop r_crc
-       ret
-
-.macro CRCS ; CRC beim Senden
-       rcall CRC16_alg
-.endm
-
-.macro CRCR; CRC beim Empfangen
-       ;clr r_temp2
-       ;sbrc r_rwbyte,7
-       ;ldi r_temp2,1
-       rcall CRC16_alg
-.endm
-
-.macro CRCInit1; CRC initialisierung bei READ_COMMAND
-       ldi r_temp,0
-       sts crc,r_temp
-       sts crc+1,r_temp
-.endm
-
-.macro CRCInit2; CRC initialisierung bei READ_DATA
-.endm
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+.comm crc,2\r
+#define _CRC16_\r
+\r
+CRC16_alg:\r
+       ;crc\r
+       push r_crc\r
+       lds r_crc,crc;lade low byte fuer vergleich mit bit\r
+       mov r_temp,r_crc\r
+       andi r_temp,0x01 ;nur bit 0\r
+       cp r_temp2,r_temp  ;r_temp2 wird in interruptroutine gesetzt\r
+       brne crc2 ;nur schieben\r
+       ;schieben und XOR\r
+       lds r_temp2,crc+1\r
+       lsr     r_temp2\r
+       ror     r_crc\r
+       ldi     r_temp, 0x01    \r
+       eor     r_crc, r_temp\r
+       ldi     r_temp, 0xA0    ;\r
+       eor     r_temp2, r_temp\r
+       rjmp crce\r
+crc2:\r
+       lds r_temp2,crc+1\r
+       lsr     r_temp2\r
+       ror     r_crc\r
+crce:\r
+       sts crc,r_crc\r
+       sts crc+1,r_temp2\r
+       pop r_crc\r
+       ret\r
+\r
+.macro CRCS ; CRC beim Senden\r
+       rcall CRC16_alg\r
+.endm\r
+\r
+.macro CRCR; CRC beim Empfangen\r
+       ;clr r_temp2\r
+       ;sbrc r_rwbyte,7\r
+       ;ldi r_temp2,1\r
+       rcall CRC16_alg\r
+.endm\r
+\r
+.macro CRCInit1; CRC initialisierung bei READ_COMMAND\r
+       ldi r_temp,0\r
+       sts crc,r_temp\r
+       sts crc+1,r_temp\r
+.endm\r
+\r
+.macro CRCInit2; CRC initialisierung bei READ_DATA\r
+.endm\r
index dad7480..7b4131f 100644 (file)
@@ -1,67 +1,67 @@
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-.comm crc,1
-
-#define _CRC8_
-
-.macro CRCS ; CRC beim Senden
-       ;crc
-       push r_crc
-       lds r_crc,crc
-       mov r_temp,r_crc
-       andi r_temp,0x01
-       cp r_temp2,r_temp
-       brne crc2
-       lsr r_crc
-       ldi r_temp,0x8c
-       eor r_crc,r_temp
-       rjmp crce
-crc2:
-       lsr r_crc
-crce:
-       sts crc,r_crc
-       pop r_crc
-
-.endm
-
-.macro CRCR; CRC beim Empfangen
-.endm
-
-.macro CRCInit1; CRC initialisierung bei READ_COMMAND
-.endm
-
-.macro CRCInit2; CRC initialisierung bei READ_DATA
-       ldi r_temp,0
-       sts crc,r_temp
-.endm
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+.comm crc,1\r
+\r
+#define _CRC8_\r
+\r
+.macro CRCS ; CRC beim Senden\r
+       ;crc\r
+       push r_crc\r
+       lds r_crc,crc\r
+       mov r_temp,r_crc\r
+       andi r_temp,0x01\r
+       cp r_temp2,r_temp\r
+       brne crc2\r
+       lsr r_crc\r
+       ldi r_temp,0x8c\r
+       eor r_crc,r_temp\r
+       rjmp crce\r
+crc2:\r
+       lsr r_crc\r
+crce:\r
+       sts crc,r_crc\r
+       pop r_crc\r
+\r
+.endm\r
+\r
+.macro CRCR; CRC beim Empfangen\r
+.endm\r
+\r
+.macro CRCInit1; CRC initialisierung bei READ_COMMAND\r
+.endm\r
+\r
+.macro CRCInit2; CRC initialisierung bei READ_DATA\r
+       ldi r_temp,0\r
+       sts crc,r_temp\r
+.endm\r
index 8d82561..c41ce6c 100644 (file)
@@ -1,97 +1,97 @@
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-
-#include <avr/io.h>
-
-#define r_temp  16
-#define r_rwbyte  17
-#define r_temp2  18
-#define r_bcount  19
-#define r_mode  20
-#define r_sendflag 21
-#define r_bytep 22
-#define r_crc 23
-
-#define r_idm1 25  
-#define r_idm2 24
-#define r_idn1 15  
-#define r_idn2 14
-
-#define xl 26
-#define xh 27
-#define yl 28
-#define yh 29
-#define zl 30
-#define zh 31
-
-.extern owid,8
-.extern config_info,16
-
-.comm mode,1  ; Aktueller Zustand nach dem die Unterprogramme aufgerufen werden
-.comm srbyte,1 ; aktuelles Byte fuer Searchrom
-.comm bytep,1 ; pointer fuer Zugriffe auf owid usw
-.comm bcount,1 ;bit counter, bit wird durchgeschoben 
-.comm rwbyte,1 ; alktuelles byte beim Senden oder Empfangen
-.comm sendflag,1; sendfalg= 1 -> Senden sonst Empfangen
-.comm gcontrol,1  ;im Test
-.comm reset_indicator,1  ; zeigt an wenn ein Reset empfangen wurde (Fuer das C Programm)
-.comm alarmflag,1
-#ifndef _DIS_FLASH_
-.comm flashmarker,1
-#endif
-
-.macro configZ m,offs
-       ldi  zl,lo8(\m)       
-       ; daten im gleichen 256 Segment
-//#if (((handle_stable>>1)&0xFF00)!= (m&0xFF00)) 
-    ldi  zh,hi8(\m)
-//#endif
-       add  zl,\offs
-//#if ((pack&0x00FF)>(0xC0))
-       clr r_temp      
-       adc zh,r_temp
-//#endif
-       
-.endm
-
-
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__)||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-#include "../common/OWSet_ATTINYX4.s"
-#endif
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-#include "../common/OWSet_ATTINYX5.s"
-#endif
-
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+\r
+#include <avr/io.h>\r
+\r
+#define r_temp  16\r
+#define r_rwbyte  17\r
+#define r_temp2  18\r
+#define r_bcount  19\r
+#define r_mode  20\r
+#define r_sendflag 21\r
+#define r_bytep 22\r
+#define r_crc 23\r
+\r
+#define r_idm1 25  \r
+#define r_idm2 24\r
+#define r_idn1 15  \r
+#define r_idn2 14\r
+\r
+#define xl 26\r
+#define xh 27\r
+#define yl 28\r
+#define yh 29\r
+#define zl 30\r
+#define zh 31\r
+\r
+.extern owid,8\r
+.extern config_info,16\r
+\r
+.comm mode,1  ; Aktueller Zustand nach dem die Unterprogramme aufgerufen werden\r
+.comm srbyte,1 ; aktuelles Byte fuer Searchrom\r
+.comm bytep,1 ; pointer fuer Zugriffe auf owid usw\r
+.comm bcount,1 ;bit counter, bit wird durchgeschoben \r
+.comm rwbyte,1 ; alktuelles byte beim Senden oder Empfangen\r
+.comm sendflag,1; sendfalg= 1 -> Senden sonst Empfangen\r
+.comm gcontrol,1  ;im Test\r
+.comm reset_indicator,1  ; zeigt an wenn ein Reset empfangen wurde (Fuer das C Programm)\r
+.comm alarmflag,1\r
+#ifndef _DIS_FLASH_\r
+.comm flashmarker,1\r
+#endif\r
+\r
+.macro configZ m,offs\r
+       ldi  zl,lo8(\m)       \r
+       ; daten im gleichen 256 Segment\r
+//#if (((handle_stable>>1)&0xFF00)!= (m&0xFF00)) \r
+    ldi  zh,hi8(\m)\r
+//#endif\r
+       add  zl,\offs\r
+//#if ((pack&0x00FF)>(0xC0))\r
+       clr r_temp      \r
+       adc zh,r_temp\r
+//#endif\r
+       \r
+.endm\r
+\r
+\r
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__)||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
+#include "../common/OWSet_ATTINYX4.s"\r
+#endif\r
\r
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
+#include "../common/OWSet_ATTINYX5.s"\r
+#endif\r
+\r
index 07e4980..e9ef6d3 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-#define _ZERO_POLLING_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC8.s"
-
-.extern pack,8
-
-//.extern  am2302_temp,2
-
-
-
-.macro CHIP_INIT       
-Init_EEPROM_read:
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp Init_EEPROM_read
-       ldi r_temp,0
-       out _SFR_IO_ADDR(EEARH), r_temp
-       ldi r_temp,2
-       out _SFR_IO_ADDR(EEARL), r_temp
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_temp,_SFR_IO_ADDR(EEDR)
-       sbrs r_temp,7
-       rcall hrc_recall_eeprom_func
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_readscratchpad
-               rjmp h_writescratchpad
-               rjmp h_convert_run
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+0
-#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+1
-#define OW_CONVERT_RUN  OW_FIRST_COMMAND+2
-
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cjmp 0xBE,hrc_set_readscratchpad
-       cjmp 0x4E,hrc_set_writescratchpad
-       cjmp 0x44,hrc_set_convertT
-       cjmp 0x48,hrc_copy_scratchpad
-       cjmp 0xB8,hrc_recall_eeprom
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       //ldi r_mode,OW_SLEEP
-       rjmp handle_end_sleep
-
-hrc_set_readscratchpad:
-       ldi r_mode,OW_READ_SCRATCHPAD
-       ldi r_sendflag,1
-       CRCInit2
-       rjmp h_readscratchpad
-
-hrc_set_writescratchpad:
-       ldi r_mode,OW_WRITE_SCRATCHPAD
-       ldi r_bytep,2 ;start to write in 2
-       rjmp handle_end
-
-hrc_recall_eeprom:
-       rcall hrc_recall_eeprom_func
-       rjmp handle_end
-
-
-
-hrc_set_convertT:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-       ldi r_mode,OW_CONVERT_RUN
-       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
-h_convert_run:
-       ldi r_bcount,0
-       ldi r_rwbyte,0
-       rjmp handle_end_no_bcount       
-
-hrc_copy_scratchpad:
-       ldi r_bytep,2
-       configZ pack,r_bytep
-       clr r_bytep
-hrc_copy_scratchpad_EEPROM_write:
-       sbic _SFR_IO_ADDR(EECR), EEPE   
-       rjmp hrc_copy_scratchpad_EEPROM_write
-       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
-       out _SFR_IO_ADDR(EECR), r_temp
-       ldi r_temp,0
-       out _SFR_IO_ADDR(EEARH),r_temp
-       out _SFR_IO_ADDR(EEARL), r_bytep
-       ld  r_rwbyte,Z+
-       out _SFR_IO_ADDR(EEDR), r_rwbyte
-       sbi _SFR_IO_ADDR(EECR), EEMPE
-       sbi _SFR_IO_ADDR(EECR), EEPE
-       inc r_bytep
-       cpi r_bytep,3
-       brne hrc_copy_scratchpad_EEPROM_write
-       rjmp handle_end
-
-
-hrc_recall_eeprom_func:
-       ldi r_bytep,2
-       configZ pack,r_bytep
-       clr r_bytep
-       clr r_temp
-hrc_recall_eeprom_EEPROM_read:
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp hrc_recall_eeprom_EEPROM_read
-       out _SFR_IO_ADDR(EEARH), r_temp
-       out _SFR_IO_ADDR(EEARL), r_bytep
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_rwbyte,_SFR_IO_ADDR(EEDR)
-       st Z+,r_rwbyte
-       inc r_bytep
-       cpi r_bytep,3
-       brne hrc_recall_eeprom_EEPROM_read
-       ret
-
-
-
-
-
-
-;---------------------------------------------------
-;   READ SCRATCHPAD
-;---------------------------------------------------
-
-h_readscratchpad:
-       cpi  r_bytep,8
-       breq h_readscratchpad_crc
-       cpi  r_bytep,9
-       breq h_readscratchpad_all
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       rjmp h_readscratchpad_endc
-h_readscratchpad_crc:
-       lds  r_rwbyte,crc
-h_readscratchpad_endc:
-       inc  r_bytep
-       ldi  r_bcount,1 
-       rjmp handle_end
-h_readscratchpad_all:
-       rjmp handle_end_sleep
-
-
-
-
-
-;---------------------------------------------------
-;   WRITE SCRATCHPAD
-;---------------------------------------------------
-
-h_writescratchpad:
-       configZ pack,r_bytep
-       inc  r_bytep
-       cpi  r_bytep,5
-       breq h_writescratchpad_all
-       st   Z,r_rwbyte
-       rjmp handle_end
-h_writescratchpad_all:
-       ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
-       st   Z,r_rwbyte
-       rjmp handle_end_sleep
-
-
-
-
-
-#include "../common/OWPinInterrupt.s"
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+#define _ZERO_POLLING_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC8.s"\r
+\r
+.extern pack,8\r
+\r
+//.extern  am2302_temp,2\r
+\r
+\r
+\r
+.macro CHIP_INIT       \r
+Init_EEPROM_read:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp Init_EEPROM_read\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(EEARH), r_temp\r
+       ldi r_temp,2\r
+       out _SFR_IO_ADDR(EEARL), r_temp\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_temp,_SFR_IO_ADDR(EEDR)\r
+       sbrs r_temp,7\r
+       rcall hrc_recall_eeprom_func\r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readscratchpad\r
+               rjmp h_writescratchpad\r
+               rjmp h_convert_run\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+0\r
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+1\r
+#define OW_CONVERT_RUN  OW_FIRST_COMMAND+2\r
+\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cjmp 0xBE,hrc_set_readscratchpad\r
+       cjmp 0x4E,hrc_set_writescratchpad\r
+       cjmp 0x44,hrc_set_convertT\r
+       cjmp 0x48,hrc_copy_scratchpad\r
+       cjmp 0xB8,hrc_recall_eeprom\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       //ldi r_mode,OW_SLEEP\r
+       rjmp handle_end_sleep\r
+\r
+hrc_set_readscratchpad:\r
+       ldi r_mode,OW_READ_SCRATCHPAD\r
+       ldi r_sendflag,1\r
+       CRCInit2\r
+       rjmp h_readscratchpad\r
+\r
+hrc_set_writescratchpad:\r
+       ldi r_mode,OW_WRITE_SCRATCHPAD\r
+       ldi r_bytep,2 ;start to write in 2\r
+       rjmp handle_end\r
+\r
+hrc_recall_eeprom:\r
+       rcall hrc_recall_eeprom_func\r
+       rjmp handle_end\r
+\r
+\r
+\r
+hrc_set_convertT:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+       ldi r_mode,OW_CONVERT_RUN\r
+       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling\r
+h_convert_run:\r
+       ldi r_bcount,0\r
+       ldi r_rwbyte,0\r
+       rjmp handle_end_no_bcount       \r
+\r
+hrc_copy_scratchpad:\r
+       ldi r_bytep,2\r
+       configZ pack,r_bytep\r
+       clr r_bytep\r
+hrc_copy_scratchpad_EEPROM_write:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE   \r
+       rjmp hrc_copy_scratchpad_EEPROM_write\r
+       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)\r
+       out _SFR_IO_ADDR(EECR), r_temp\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(EEARH),r_temp\r
+       out _SFR_IO_ADDR(EEARL), r_bytep\r
+       ld  r_rwbyte,Z+\r
+       out _SFR_IO_ADDR(EEDR), r_rwbyte\r
+       sbi _SFR_IO_ADDR(EECR), EEMPE\r
+       sbi _SFR_IO_ADDR(EECR), EEPE\r
+       inc r_bytep\r
+       cpi r_bytep,3\r
+       brne hrc_copy_scratchpad_EEPROM_write\r
+       rjmp handle_end\r
+\r
+\r
+hrc_recall_eeprom_func:\r
+       ldi r_bytep,2\r
+       configZ pack,r_bytep\r
+       clr r_bytep\r
+       clr r_temp\r
+hrc_recall_eeprom_EEPROM_read:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp hrc_recall_eeprom_EEPROM_read\r
+       out _SFR_IO_ADDR(EEARH), r_temp\r
+       out _SFR_IO_ADDR(EEARL), r_bytep\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_rwbyte,_SFR_IO_ADDR(EEDR)\r
+       st Z+,r_rwbyte\r
+       inc r_bytep\r
+       cpi r_bytep,3\r
+       brne hrc_recall_eeprom_EEPROM_read\r
+       ret\r
+\r
+\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_readscratchpad:\r
+       cpi  r_bytep,8\r
+       breq h_readscratchpad_crc\r
+       cpi  r_bytep,9\r
+       breq h_readscratchpad_all\r
+       configZ pack,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp h_readscratchpad_endc\r
+h_readscratchpad_crc:\r
+       lds  r_rwbyte,crc\r
+h_readscratchpad_endc:\r
+       inc  r_bytep\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end\r
+h_readscratchpad_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   WRITE SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_writescratchpad:\r
+       configZ pack,r_bytep\r
+       inc  r_bytep\r
+       cpi  r_bytep,5\r
+       breq h_writescratchpad_all\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end\r
+h_writescratchpad_all:\r
+       ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 8ce61d0..4ad7394 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-#define _ZERO_POLLING_
-//#define _DB_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC8.s"
-
-.extern pack1,8
-
-//.extern  am2302_temp,2
-
-#if  defined(__AVR_ATtiny25__)
-.extern pack2,16
-#else
-.extern pack2,64
-#endif
-.extern  am2302_temp,2
-.extern  am2302_hum,2
-.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
-
-
-.macro CHIP_INIT       ;r_temp is pushed other Registers should be saved
-Init_EEPROM_read:
-       push r_bytep
-       push r_rwbyte
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp Init_EEPROM_read
-       ldi r_temp,0
-       out _SFR_IO_ADDR(EEARH), r_temp
-       ldi r_temp,2
-       out _SFR_IO_ADDR(EEARL), r_temp
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_temp,_SFR_IO_ADDR(EEDR)
-       sbrs r_temp,7
-       rcall hrc_recall_eeprom_func1
-       pop r_rwbyte
-       pop r_bytep
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_readscratchpad1
-               rjmp h_writescratchpad1
-               rjmp h_convert_run1
-               rjmp h_readscratchpad_adr2
-               rjmp h_readscratchpad2
-               rjmp h_writescratchpad_adr2
-               rjmp h_writescratchpad2
-.endm
-
-#include "../common/OWRomFunctionsDual.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_SCRATCHPAD1 OW_FIRST_COMMAND+0
-#define OW_WRITE_SCRATCHPAD1 OW_FIRST_COMMAND+1
-#define OW_CONVERT_RUN1  OW_FIRST_COMMAND+2
-#define OW_READ_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+3
-#define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+4
-#define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+5
-#define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+6
-
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand1:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cjmp 0xBE,hrc_set_readscratchpad1
-       cjmp 0x4E,hrc_set_writescratchpad1
-       cjmp 0x44,hrc_set_convertT1
-       cjmp 0x48,hrc_copy_scratchpad1
-       cjmp 0xB8,hrc_recall_eeprom1
-       FW_CONFIG_INFO1
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-hrc_set_readscratchpad1:
-       ldi r_mode,OW_READ_SCRATCHPAD1
-       ldi r_sendflag,1
-       CRCInit2
-       rjmp h_readscratchpad1
-
-hrc_set_writescratchpad1:
-       ldi r_mode,OW_WRITE_SCRATCHPAD1
-       ldi r_bytep,2 ;start to write in 2
-       rjmp handle_end
-
-hrc_recall_eeprom1:
-       rcall hrc_recall_eeprom_func1
-       rjmp handle_end
-
-
-
-hrc_set_convertT1:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-
-       ldi r_mode,OW_CONVERT_RUN1
-       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling
-h_convert_run1:
-       ldi r_bcount,0
-       ldi r_rwbyte,0
-       rjmp handle_end_no_bcount       
-
-
-hrc_copy_scratchpad1:
-       ldi r_bytep,2
-       configZ pack1,r_bytep
-       clr r_bytep
-hrc_copy_scratchpad_EEPROM_write1:
-       sbic _SFR_IO_ADDR(EECR), EEPE   
-       rjmp hrc_copy_scratchpad_EEPROM_write1
-       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
-       out _SFR_IO_ADDR(EECR), r_temp
-       ldi r_temp,0
-       out _SFR_IO_ADDR(EEARH),r_temp
-       out _SFR_IO_ADDR(EEARL), r_bytep
-       ld  r_rwbyte,Z+
-       out _SFR_IO_ADDR(EEDR), r_rwbyte
-       sbi _SFR_IO_ADDR(EECR), EEMPE
-       sbi _SFR_IO_ADDR(EECR), EEPE
-       inc r_bytep
-       cpi r_bytep,3
-       brne hrc_copy_scratchpad_EEPROM_write1
-       rjmp handle_end
-
-
-hrc_recall_eeprom_func1:
-       ldi r_bytep,2
-       configZ pack1,r_bytep
-       clr r_bytep
-       clr r_temp
-hrc_recall_eeprom_EEPROM_read1:
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp hrc_recall_eeprom_EEPROM_read1
-       out _SFR_IO_ADDR(EEARH), r_temp
-       out _SFR_IO_ADDR(EEARL), r_bytep
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_rwbyte,_SFR_IO_ADDR(EEDR)
-       st Z+,r_rwbyte
-       inc r_bytep
-       cpi r_bytep,3
-       brne hrc_recall_eeprom_EEPROM_read1
-       ret
-
-
-
-
-
-
-;---------------------------------------------------
-;   READ SCRATCHPAD
-;---------------------------------------------------
-
-h_readscratchpad1:
-       cpi  r_bytep,8
-       breq h_readscratchpad_crc1
-       cpi  r_bytep,9
-       breq h_readscratchpad_all1
-       configZ pack1,r_bytep
-       ld   r_rwbyte,Z
-       rjmp h_readscratchpad_endc1
-h_readscratchpad_crc1:
-       lds  r_rwbyte,crc
-h_readscratchpad_endc1:
-       inc  r_bytep
-       ldi  r_bcount,1 
-       rjmp handle_end
-h_readscratchpad_all1:
-       rjmp handle_end_sleep
-
-
-
-
-
-;---------------------------------------------------
-;   WRITE SCRATCHPAD
-;---------------------------------------------------
-
-h_writescratchpad1:
-       configZ pack1,r_bytep
-       inc  r_bytep
-       cpi  r_bytep,5
-       breq h_writescratchpad_all1
-       st   Z,r_rwbyte
-       rjmp handle_end
-h_writescratchpad_all1:
-       ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1
-       st   Z,r_rwbyte
-       rjmp handle_end_sleep
-
-;*****************************************************************************************************************************************************************************************
-;*****************************************************************************************************************************************************************************************
-;*****************************************************************************************************************************************************************************************
-;*****************************************************************************************************************************************************************************************
-;*****************************************************************************************************************************************************************************************
-
-
-
-
-
-h_readcommand2:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0xBE,OW_READ_SCRATCHPAD_ADR2
-       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2
-       cjmp 0x44,hrc_set_convertT2
-       cjmp 0xB4,hrc_set_convertV2
-       FW_CONFIG_INFO2
-       //cljmp 0x85,hrc_fw_configinfo2
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       rjmp handle_end_sleep
-
-
-hrc_set_convertT2:
-       ldi r_temp,2
-       sts gcontrol,r_temp
-       lds r_temp,am2302_temp
-       sts pack2+1,r_temp
-       lds r_temp,am2302_temp+1
-       sts pack2+2,r_temp
-       rjmp handle_end_sleep
-hrc_set_convertV2:
-       lds r_temp,pack2
-       sbrs r_temp,3
-       rjmp hrc_set_convertVV2
-       ldi r_temp,0xF4
-       sts pack2+3,r_temp
-       ldi r_temp,0x01
-       sts pack2+4,r_temp
-       rjmp hrc_set_convertend2
-hrc_set_convertVV2:
-       ldi r_temp,3
-       sts gcontrol,r_temp
-       lds r_temp,am2302_hum
-       sts pack2+3,r_temp
-       lds r_temp,am2302_hum+1
-       sts pack2+4,r_temp
-hrc_set_convertend2:
-       rjmp handle_end_sleep
-
-
-
-;---------------------------------------------------
-;   READ SCRATCHPAD
-;---------------------------------------------------
-
-h_readscratchpad_adr2:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_sendflag,1
-       ldi r_mode,OW_READ_SCRATCHPAD2
-       CRCInit2
-h_readscratchpad2:
-       cpi  r_bytep,8
-       breq h_readscratchpad_crc2
-       cpi  r_bytep,9
-       breq h_readscratchpad_all2
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack2,r_temp
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_crc2:
-       lds  r_rwbyte,crc
-       rjmp handle_end_inc
-h_readscratchpad_all2:
-       rjmp handle_end_sleep
-
-
-
-
-;---------------------------------------------------
-;   WRITE SCRATCHPAD
-;---------------------------------------------------
-h_writescratchpad_adr2:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_mode,OW_WRITE_SCRATCHPAD2
-       ldi  r_bcount,1 
-       rjmp handle_end 
-h_writescratchpad2:
-       cpi  r_bytep,8
-       breq h_writescratchpad_all2
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack2,r_temp
-       st   Z,r_rwbyte
-       rjmp handle_end_inc
-h_writescratchpad_all2:
-       rjmp handle_end_sleep
-
-
-
-
-
-
-
-
-
-#include "../common/OWPinInterrupt.s"
-.end
\ No newline at end of file
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+#define _ZERO_POLLING_\r
+//#define _DB_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC8.s"\r
+\r
+.extern pack1,8\r
+\r
+//.extern  am2302_temp,2\r
+\r
+#if  defined(__AVR_ATtiny25__)\r
+.extern pack2,16\r
+#else\r
+.extern pack2,64\r
+#endif\r
+.extern  am2302_temp,2\r
+.extern  am2302_hum,2\r
+.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)\r
+\r
+\r
+.macro CHIP_INIT       ;r_temp is pushed other Registers should be saved\r
+Init_EEPROM_read:\r
+       push r_bytep\r
+       push r_rwbyte\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp Init_EEPROM_read\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(EEARH), r_temp\r
+       ldi r_temp,2\r
+       out _SFR_IO_ADDR(EEARL), r_temp\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_temp,_SFR_IO_ADDR(EEDR)\r
+       sbrs r_temp,7\r
+       rcall hrc_recall_eeprom_func1\r
+       pop r_rwbyte\r
+       pop r_bytep\r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readscratchpad1\r
+               rjmp h_writescratchpad1\r
+               rjmp h_convert_run1\r
+               rjmp h_readscratchpad_adr2\r
+               rjmp h_readscratchpad2\r
+               rjmp h_writescratchpad_adr2\r
+               rjmp h_writescratchpad2\r
+.endm\r
+\r
+#include "../common/OWRomFunctionsDual.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_SCRATCHPAD1 OW_FIRST_COMMAND+0\r
+#define OW_WRITE_SCRATCHPAD1 OW_FIRST_COMMAND+1\r
+#define OW_CONVERT_RUN1  OW_FIRST_COMMAND+2\r
+#define OW_READ_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+3\r
+#define OW_READ_SCRATCHPAD2 OW_FIRST_COMMAND+4\r
+#define OW_WRITE_SCRATCHPAD_ADR2 OW_FIRST_COMMAND+5\r
+#define OW_WRITE_SCRATCHPAD2 OW_FIRST_COMMAND+6\r
+\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand1:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cjmp 0xBE,hrc_set_readscratchpad1\r
+       cjmp 0x4E,hrc_set_writescratchpad1\r
+       cjmp 0x44,hrc_set_convertT1\r
+       cjmp 0x48,hrc_copy_scratchpad1\r
+       cjmp 0xB8,hrc_recall_eeprom1\r
+       FW_CONFIG_INFO1\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       ldi r_mode,OW_SLEEP\r
+       rjmp handle_end\r
+\r
+hrc_set_readscratchpad1:\r
+       ldi r_mode,OW_READ_SCRATCHPAD1\r
+       ldi r_sendflag,1\r
+       CRCInit2\r
+       rjmp h_readscratchpad1\r
+\r
+hrc_set_writescratchpad1:\r
+       ldi r_mode,OW_WRITE_SCRATCHPAD1\r
+       ldi r_bytep,2 ;start to write in 2\r
+       rjmp handle_end\r
+\r
+hrc_recall_eeprom1:\r
+       rcall hrc_recall_eeprom_func1\r
+       rjmp handle_end\r
+\r
+\r
+\r
+hrc_set_convertT1:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+\r
+       ldi r_mode,OW_CONVERT_RUN1\r
+       ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling\r
+h_convert_run1:\r
+       ldi r_bcount,0\r
+       ldi r_rwbyte,0\r
+       rjmp handle_end_no_bcount       \r
+\r
+\r
+hrc_copy_scratchpad1:\r
+       ldi r_bytep,2\r
+       configZ pack1,r_bytep\r
+       clr r_bytep\r
+hrc_copy_scratchpad_EEPROM_write1:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE   \r
+       rjmp hrc_copy_scratchpad_EEPROM_write1\r
+       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)\r
+       out _SFR_IO_ADDR(EECR), r_temp\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(EEARH),r_temp\r
+       out _SFR_IO_ADDR(EEARL), r_bytep\r
+       ld  r_rwbyte,Z+\r
+       out _SFR_IO_ADDR(EEDR), r_rwbyte\r
+       sbi _SFR_IO_ADDR(EECR), EEMPE\r
+       sbi _SFR_IO_ADDR(EECR), EEPE\r
+       inc r_bytep\r
+       cpi r_bytep,3\r
+       brne hrc_copy_scratchpad_EEPROM_write1\r
+       rjmp handle_end\r
+\r
+\r
+hrc_recall_eeprom_func1:\r
+       ldi r_bytep,2\r
+       configZ pack1,r_bytep\r
+       clr r_bytep\r
+       clr r_temp\r
+hrc_recall_eeprom_EEPROM_read1:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp hrc_recall_eeprom_EEPROM_read1\r
+       out _SFR_IO_ADDR(EEARH), r_temp\r
+       out _SFR_IO_ADDR(EEARL), r_bytep\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_rwbyte,_SFR_IO_ADDR(EEDR)\r
+       st Z+,r_rwbyte\r
+       inc r_bytep\r
+       cpi r_bytep,3\r
+       brne hrc_recall_eeprom_EEPROM_read1\r
+       ret\r
+\r
+\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_readscratchpad1:\r
+       cpi  r_bytep,8\r
+       breq h_readscratchpad_crc1\r
+       cpi  r_bytep,9\r
+       breq h_readscratchpad_all1\r
+       configZ pack1,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp h_readscratchpad_endc1\r
+h_readscratchpad_crc1:\r
+       lds  r_rwbyte,crc\r
+h_readscratchpad_endc1:\r
+       inc  r_bytep\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end\r
+h_readscratchpad_all1:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   WRITE SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_writescratchpad1:\r
+       configZ pack1,r_bytep\r
+       inc  r_bytep\r
+       cpi  r_bytep,5\r
+       breq h_writescratchpad_all1\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end\r
+h_writescratchpad_all1:\r
+       ;ori r_rwbyte,0x1F ; Alle unteren Bits sind immer 1 -->VOC use different\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end_sleep\r
+\r
+;*****************************************************************************************************************************************************************************************\r
+;*****************************************************************************************************************************************************************************************\r
+;*****************************************************************************************************************************************************************************************\r
+;*****************************************************************************************************************************************************************************************\r
+;*****************************************************************************************************************************************************************************************\r
+\r
+\r
+\r
+\r
+\r
+h_readcommand2:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0xBE,OW_READ_SCRATCHPAD_ADR2\r
+       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR2\r
+       cjmp 0x44,hrc_set_convertT2\r
+       cjmp 0xB4,hrc_set_convertV2\r
+       FW_CONFIG_INFO2\r
+       //cljmp 0x85,hrc_fw_configinfo2\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_set_convertT2:\r
+       ldi r_temp,2\r
+       sts gcontrol,r_temp\r
+       lds r_temp,am2302_temp\r
+       sts pack2+1,r_temp\r
+       lds r_temp,am2302_temp+1\r
+       sts pack2+2,r_temp\r
+       rjmp handle_end_sleep\r
+hrc_set_convertV2:\r
+       lds r_temp,pack2\r
+       sbrs r_temp,3\r
+       rjmp hrc_set_convertVV2\r
+       ldi r_temp,0xF4\r
+       sts pack2+3,r_temp\r
+       ldi r_temp,0x01\r
+       sts pack2+4,r_temp\r
+       rjmp hrc_set_convertend2\r
+hrc_set_convertVV2:\r
+       ldi r_temp,3\r
+       sts gcontrol,r_temp\r
+       lds r_temp,am2302_hum\r
+       sts pack2+3,r_temp\r
+       lds r_temp,am2302_hum+1\r
+       sts pack2+4,r_temp\r
+hrc_set_convertend2:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_readscratchpad_adr2:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_sendflag,1\r
+       ldi r_mode,OW_READ_SCRATCHPAD2\r
+       CRCInit2\r
+h_readscratchpad2:\r
+       cpi  r_bytep,8\r
+       breq h_readscratchpad_crc2\r
+       cpi  r_bytep,9\r
+       breq h_readscratchpad_all2\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack2,r_temp\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readscratchpad_crc2:\r
+       lds  r_rwbyte,crc\r
+       rjmp handle_end_inc\r
+h_readscratchpad_all2:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   WRITE SCRATCHPAD\r
+;---------------------------------------------------\r
+h_writescratchpad_adr2:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_mode,OW_WRITE_SCRATCHPAD2\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end \r
+h_writescratchpad2:\r
+       cpi  r_bytep,8\r
+       breq h_writescratchpad_all2\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack2,r_temp\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end_inc\r
+h_writescratchpad_all2:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
+.end\r
index 05df87d..0fb23d8 100644 (file)
-
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-#define _CHANGEABLE_ID_
-#define _ZERO_POLLING_
-#include "../common/OWConfig.s"
-#include "../common/OWCRC16.s"
-
-.extern pack,45
-.extern counters,8
-
-.macro CHIP_INIT       
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_writescratchpad
-               rjmp h_writescratchpad_crc
-               rjmp h_readscratchpad
-               rjmp h_copyscratchpad
-               rjmp h_readmemory_addr
-               rjmp h_readmemory
-               rjmp h_readmemorycounter_addr
-               rjmp h_readmemorycounter
-               rjmp h_readmemorycounter_ex
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0
-#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1
-#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2
-#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3
-#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4
-#define OW_READ_MEMORY OW_FIRST_COMMAND+5
-#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6
-#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7
-#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0x0F,OW_WRITE_SCRATCHPAD
-       cjmp 0xAA,hrc_set_readscratchpad
-       cset 0x5A,OW_COPY_SCRATCHPAD
-       cset 0xF0,OW_READ_MEMORY_ADDR
-       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-hrc_set_readscratchpad:
-       ldi r_mode,OW_READ_SCRATCHPAD
-       ldi r_sendflag,1
-       rjmp h_readscratchpad
-
-h_writescratchpad:
-       configZ pack,r_bytep
-       inc  r_bytep
-       st   Z,r_rwbyte
-       cpi  r_bytep,2
-       breq h_writescratchpad_block
-       brsh h_writescratchpad_set_eoffset ;;33
-       rjmp handle_end  ;handle_end zu weit entfernt fuer br...
-h_writescratchpad_set_eoffset:
-       cpi  r_bytep,35
-       breq h_writescratchpad_setcrc
-       mov r_temp,r_bytep
-       subi r_temp,4
-       sts pack+2,r_temp ;AA und PF cleared
-       rjmp handle_end
-;Start writeing to 32 Byte Block ; skip status byte    
-h_writescratchpad_block:
-       lds r_temp,pack ; Adresse low byte
-       andi r_temp,0x1F ;32 byte
-       add r_bytep,r_temp ;Zur angegebenen Startadresse springen
-       ;ori r_temp,0x20 ; Set PF flag
-       sts pack+2,r_temp  ;E4:E0 vorher setzen
-       ; Byte 3 ueberspringen
-       rjmp handle_end_inc
-
-h_writescratchpad_setcrc:
-       ;copy crc to pack
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp ; invertieren , komischer name.....
-       sts pack+44,r_temp
-       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC
-       ldi r_sendflag,1
-       ldi r_bytep,43
-h_writescratchpad_crc:
-       cpi r_bytep,45
-       breq h_writescratchpad_crc_end
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_writescratchpad_crc_end:
-       rjmp handle_end_sleep
-       
-       
-h_readscratchpad:
-       cpi r_bytep,35
-       breq h_readscratchpad_end
-       cpi r_bytep,3
-       brne h_readscratchpad_read_byte
-h_readscratchpad_set_offset:
-       lds r_temp,pack
-       andi r_temp,0x1F
-       ldi r_temp2,3
-       add r_temp,r_temp2
-       mov r_bytep,r_temp
-h_readscratchpad_read_byte:
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_end:
-       rjmp handle_end_sleep
-
-
-
-h_copyscratchpad:
-       cpi  r_bytep,3
-       brsh h_copyscratchpad_ok
-       configZ pack,r_bytep
-       inc  r_bytep
-       ld   r_temp,Z
-       cp r_temp,r_rwbyte
-       brne h_copyscratchpad_nok
-       cpi  r_bytep,3
-       breq h_copyscratchpad_ok
-       ldi  r_bcount,1 
-       rjmp handle_end
-h_copyscratchpad_ok:
-       ldi r_rwbyte,0xAA
-       ldi r_sendflag,1
-       rjmp handle_end
-h_copyscratchpad_nok:
-       lds r_temp,pack+3
-       andi r_temp,~0x80
-       sts pack+3,r_temp
-       rjmp handle_end_sleep
-
-
-h_readmemory_addr:
-       cpi r_bytep,0
-       brne h_readmrmory_addr_byte1
-       sts pack,r_rwbyte
-       rjmp handle_end_inc
-h_readmrmory_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORY
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemory2
-h_readmemory:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       inc r_bytep
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1
-       rjmp h_readmemory_end
-       sts pack+1,r_temp
-       sts pack,r_bytep
-h_readmemory2:
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemory_end:
-       rjmp handle_end_sleep
-
-
-
-
-
-
-
-
-h_readmemorycounter_addr:
-       cpi r_bytep,0
-       brne h_readmrmorycounter_addr_byte1
-       sts pack,r_rwbyte
-       inc r_bytep
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_readmrmorycounter_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORYCOUNTER
-       ;ldi r_bcount,1 
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       mov r_temp,r_bytep
-       andi r_temp,0x1F
-       breq h_readmemorycounter_next
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       ;ldi r_bcount,1
-       rjmp handle_end
-//h_readmemorycounter_end:
-//     ldi  r_mode,OW_SLEEP
-//     clr r_sendflag
-//     rjmp handle_end
-h_readmemorycounter_next:  ; rest lesen
-       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX
-       ldi r_bytep,34
-       lds r_temp2,pack
-       lds r_temp,pack+1
-       //lsr r_temp
-       //ror r_temp2
-
-       lsl r_temp2
-       rol r_temp
-       cpi r_temp,3
-       brne h_readmemorycounter_cFF
-       andi r_temp2,0xC0
-       swap r_temp2
-
-       ;cpi r_temp,0xE0
-
-       configZ counters,r_temp2
-       ld r_temp,Z+
-       sts pack+35,r_temp      
-       ld r_temp,Z+
-       sts pack+36,r_temp      
-       ld r_temp,Z+
-       sts pack+37,r_temp      
-       ld r_temp,Z+
-       sts pack+38,r_temp      
-       rjmp h_readmemorycounter_ex
-h_readmemorycounter_cFF:
-       ldi r_temp,0xFF
-       sts pack+35,r_temp      
-       sts pack+36,r_temp      
-       sts pack+37,r_temp      
-       sts pack+38,r_temp      
-
-h_readmemorycounter_ex:
-       inc r_bytep
-       cpi r_bytep,45
-       breq h_readmemorycounter_ex_end
-       cpi r_bytep,43
-       brne h_readmemorycounter_ex2
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp
-       sts pack+44,r_temp
-h_readmemorycounter_ex2:
-       ;ldi r_bcount,1
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemorycounter_ex_end:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1 ;am ene von allem 
-       rjmp h_readmemorycounter_ex_sleep
-       CRCInit1
-       ldi  r_mode,OW_READ_MEMORYCOUNTER
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter_ex_sleep:
-       ldi r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end
-
-
-
-       
-
-#include "../common/OWPinInterrupt.s"
+\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+#define _CHANGEABLE_ID_\r
+#define _ZERO_POLLING_\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC16.s"\r
+\r
+.extern pack,45\r
+.extern counters,8\r
+\r
+.macro CHIP_INIT       \r
+.endm\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_writescratchpad\r
+               rjmp h_writescratchpad_crc\r
+               rjmp h_readscratchpad\r
+               rjmp h_copyscratchpad\r
+               rjmp h_readmemory_addr\r
+               rjmp h_readmemory\r
+               rjmp h_readmemorycounter_addr\r
+               rjmp h_readmemorycounter\r
+               rjmp h_readmemorycounter_ex\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0\r
+#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1\r
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2\r
+#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3\r
+#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4\r
+#define OW_READ_MEMORY OW_FIRST_COMMAND+5\r
+#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6\r
+#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7\r
+#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0x0F,OW_WRITE_SCRATCHPAD\r
+       cjmp 0xAA,hrc_set_readscratchpad\r
+       cset 0x5A,OW_COPY_SCRATCHPAD\r
+       cset 0xF0,OW_READ_MEMORY_ADDR\r
+       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       ldi r_mode,OW_SLEEP\r
+       rjmp handle_end\r
+\r
+hrc_set_readscratchpad:\r
+       ldi r_mode,OW_READ_SCRATCHPAD\r
+       ldi r_sendflag,1\r
+       rjmp h_readscratchpad\r
+\r
+h_writescratchpad:\r
+       configZ pack,r_bytep\r
+       inc  r_bytep\r
+       st   Z,r_rwbyte\r
+       cpi  r_bytep,2\r
+       breq h_writescratchpad_block\r
+       brsh h_writescratchpad_set_eoffset ;;33\r
+       rjmp handle_end  ;handle_end zu weit entfernt fuer br...\r
+h_writescratchpad_set_eoffset:\r
+       cpi  r_bytep,35\r
+       breq h_writescratchpad_setcrc\r
+       mov r_temp,r_bytep\r
+       subi r_temp,4\r
+       sts pack+2,r_temp ;AA und PF cleared\r
+       rjmp handle_end\r
+;Start writeing to 32 Byte Block ; skip status byte    \r
+h_writescratchpad_block:\r
+       lds r_temp,pack ; Adresse low byte\r
+       andi r_temp,0x1F ;32 byte\r
+       add r_bytep,r_temp ;Zur angegebenen Startadresse springen\r
+       ;ori r_temp,0x20 ; Set PF flag\r
+       sts pack+2,r_temp  ;E4:E0 vorher setzen\r
+       ; Byte 3 ueberspringen\r
+       rjmp handle_end_inc\r
+\r
+h_writescratchpad_setcrc:\r
+       ;copy crc to pack\r
+       lds r_temp,crc\r
+       com r_temp\r
+       sts pack+43,r_temp\r
+       lds r_temp,crc+1\r
+       com r_temp ; invertieren , komischer name.....\r
+       sts pack+44,r_temp\r
+       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC\r
+       ldi r_sendflag,1\r
+       ldi r_bytep,43\r
+h_writescratchpad_crc:\r
+       cpi r_bytep,45\r
+       breq h_writescratchpad_crc_end\r
+       configZ pack,r_bytep\r
+       ld r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_writescratchpad_crc_end:\r
+       rjmp handle_end_sleep\r
+       \r
+       \r
+h_readscratchpad:\r
+       cpi r_bytep,35\r
+       breq h_readscratchpad_end\r
+       cpi r_bytep,3\r
+       brne h_readscratchpad_read_byte\r
+h_readscratchpad_set_offset:\r
+       lds r_temp,pack\r
+       andi r_temp,0x1F\r
+       ldi r_temp2,3\r
+       add r_temp,r_temp2\r
+       mov r_bytep,r_temp\r
+h_readscratchpad_read_byte:\r
+       configZ pack,r_bytep\r
+       ld r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readscratchpad_end:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+h_copyscratchpad:\r
+       cpi  r_bytep,3\r
+       brsh h_copyscratchpad_ok\r
+       configZ pack,r_bytep\r
+       inc  r_bytep\r
+       ld   r_temp,Z\r
+       cp r_temp,r_rwbyte\r
+       brne h_copyscratchpad_nok\r
+       cpi  r_bytep,3\r
+       breq h_copyscratchpad_ok\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end\r
+h_copyscratchpad_ok:\r
+       ldi r_rwbyte,0xAA\r
+       ldi r_sendflag,1\r
+       rjmp handle_end\r
+h_copyscratchpad_nok:\r
+       lds r_temp,pack+3\r
+       andi r_temp,~0x80\r
+       sts pack+3,r_temp\r
+       rjmp handle_end_sleep\r
+\r
+\r
+h_readmemory_addr:\r
+       cpi r_bytep,0\r
+       brne h_readmrmory_addr_byte1\r
+       sts pack,r_rwbyte\r
+       rjmp handle_end_inc\r
+h_readmrmory_addr_byte1:\r
+       sts pack+1,r_rwbyte\r
+       ldi r_mode,OW_READ_MEMORY\r
+       ldi r_sendflag,1\r
+       clr r_bytep\r
+       rjmp h_readmemory2\r
+h_readmemory:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       inc r_bytep\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       sbrc r_temp2,1\r
+       rjmp h_readmemory_end\r
+       sts pack+1,r_temp\r
+       sts pack,r_bytep\r
+h_readmemory2:\r
+       lds r_bytep,pack\r
+       andi r_bytep,0x1F\r
+       configZ pack+3,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end\r
+h_readmemory_end:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+h_readmemorycounter_addr:\r
+       cpi r_bytep,0\r
+       brne h_readmrmorycounter_addr_byte1\r
+       sts pack,r_rwbyte\r
+       inc r_bytep\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+h_readmrmorycounter_addr_byte1:\r
+       sts pack+1,r_rwbyte\r
+       ldi r_mode,OW_READ_MEMORYCOUNTER\r
+       ;ldi r_bcount,1 \r
+       ldi r_sendflag,1\r
+       clr r_bytep\r
+       rjmp h_readmemorycounter2\r
+h_readmemorycounter:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       ldi r_temp,1  ;inc leider kein c flag\r
+       add r_bytep,r_temp\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       mov r_temp,r_bytep\r
+       andi r_temp,0x1F\r
+       breq h_readmemorycounter_next\r
+       sts pack+1,r_temp2\r
+       sts pack,r_bytep\r
+h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen\r
+       lds r_bytep,pack\r
+       andi r_bytep,0x1F\r
+       configZ pack+3,r_bytep\r
+       ld   r_rwbyte,Z\r
+       ;ldi r_bcount,1\r
+       rjmp handle_end\r
+//h_readmemorycounter_end:\r
+//     ldi  r_mode,OW_SLEEP\r
+//     clr r_sendflag\r
+//     rjmp handle_end\r
+h_readmemorycounter_next:  ; rest lesen\r
+       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX\r
+       ldi r_bytep,34\r
+       lds r_temp2,pack\r
+       lds r_temp,pack+1\r
+       //lsr r_temp\r
+       //ror r_temp2\r
+\r
+       lsl r_temp2\r
+       rol r_temp\r
+       cpi r_temp,3\r
+       brne h_readmemorycounter_cFF\r
+       andi r_temp2,0xC0\r
+       swap r_temp2\r
+\r
+       ;cpi r_temp,0xE0\r
+\r
+       configZ counters,r_temp2\r
+       ld r_temp,Z+\r
+       sts pack+35,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+36,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+37,r_temp      \r
+       ld r_temp,Z+\r
+       sts pack+38,r_temp      \r
+       rjmp h_readmemorycounter_ex\r
+h_readmemorycounter_cFF:\r
+       ldi r_temp,0xFF\r
+       sts pack+35,r_temp      \r
+       sts pack+36,r_temp      \r
+       sts pack+37,r_temp      \r
+       sts pack+38,r_temp      \r
+\r
+h_readmemorycounter_ex:\r
+       inc r_bytep\r
+       cpi r_bytep,45\r
+       breq h_readmemorycounter_ex_end\r
+       cpi r_bytep,43\r
+       brne h_readmemorycounter_ex2\r
+       lds r_temp,crc\r
+       com r_temp\r
+       sts pack+43,r_temp\r
+       lds r_temp,crc+1\r
+       com r_temp\r
+       sts pack+44,r_temp\r
+h_readmemorycounter_ex2:\r
+       ;ldi r_bcount,1\r
+       configZ pack,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end\r
+h_readmemorycounter_ex_end:\r
+       lds r_bytep,pack\r
+       lds r_temp2,pack+1\r
+       ldi r_temp,1  ;inc leider kein c flag\r
+       add r_bytep,r_temp\r
+       clr r_temp\r
+       adc r_temp2,r_temp\r
+       sbrc r_temp2,1 ;am ene von allem \r
+       rjmp h_readmemorycounter_ex_sleep\r
+       CRCInit1\r
+       ldi  r_mode,OW_READ_MEMORYCOUNTER\r
+       sts pack+1,r_temp2\r
+       sts pack,r_bytep\r
+       rjmp h_readmemorycounter2\r
+h_readmemorycounter_ex_sleep:\r
+       ldi r_mode,OW_SLEEP\r
+       clr r_sendflag\r
+       rjmp handle_end\r
+\r
+\r
+\r
+       \r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 35bc463..a7d92fa 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-#define _CHANGEABLE_ID_
-//#define _DIS_FLASH_
-#define _ZERO_POLLING_
-//#define _DB_
-
-#include "../common/OWConfig.s"
-#include "../common/OWCRC8.s"
-
-#if  defined(__AVR_ATtiny25__)
-.extern pack,16
-#else
-.extern pack,64
-#endif
-.extern  am2302_temp,2
-.extern  am2302_hum,2
-.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
-
-
-.macro CHIP_INIT
-.endm
-
-; Ab hier Geraeteabhaenging
-#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0
-#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1
-#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2
-#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3
-
-
-
-.macro COMMAND_TABLE
-               rjmp h_readscratchpad_adr
-               rjmp h_readscratchpad
-               rjmp h_writescratchpad_adr
-               rjmp h_writescratchpad
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0xBE,OW_READ_SCRATCHPAD_ADR
-       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR
-       cjmp 0x44,hrc_set_convertT
-       cjmp 0xB4,hrc_set_convertV
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       rjmp handle_end_sleep
-
-
-hrc_set_convertT:
-       ldi r_temp,1
-       sts gcontrol,r_temp
-       lds r_temp,am2302_temp
-       sts pack+1,r_temp
-       lds r_temp,am2302_temp+1
-       sts pack+2,r_temp
-       rjmp handle_end_sleep
-hrc_set_convertV:
-       ldi r_temp,2
-       sts gcontrol,r_temp
-       lds r_temp,pack
-       sbrs r_temp,3
-       rjmp hrc_set_convertVV
-       ldi r_temp,0xF4
-       sts pack+3,r_temp
-       ldi r_temp,0x01
-       sts pack+4,r_temp
-       rjmp hrc_set_convertend
-hrc_set_convertVV:
-       lds r_temp,am2302_hum
-       sts pack+3,r_temp
-       lds r_temp,am2302_hum+1
-       sts pack+4,r_temp
-hrc_set_convertend:
-       rjmp handle_end_sleep
-
-
-
-;---------------------------------------------------
-;   READ SCRATCHPAD
-;---------------------------------------------------
-
-h_readscratchpad_adr:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_sendflag,1
-       ldi r_mode,OW_READ_SCRATCHPAD
-       CRCInit2
-h_readscratchpad:
-       cpi  r_bytep,8
-       breq h_readscratchpad_crc
-       cpi  r_bytep,9
-       breq h_readscratchpad_all
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack,r_temp
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_crc:
-       lds  r_rwbyte,crc
-       rjmp handle_end_inc
-h_readscratchpad_all:
-       rjmp handle_end_sleep
-
-
-
-
-;---------------------------------------------------
-;   WRITE SCRATCHPAD
-;---------------------------------------------------
-h_writescratchpad_adr:
-       lsl r_rwbyte
-       lsl r_rwbyte
-       lsl r_rwbyte
-#if  defined(__AVR_ATtiny25__)
-       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen
-#endif
-       sts block,r_rwbyte
-       ldi r_mode,OW_WRITE_SCRATCHPAD
-       ldi  r_bcount,1 
-       rjmp handle_end 
-h_writescratchpad:
-       cpi  r_bytep,8
-       breq h_writescratchpad_all
-       lds  r_temp,block
-       add  r_temp,r_bytep
-       configZ pack,r_temp
-       st   Z,r_rwbyte
-       rjmp handle_end_inc
-h_writescratchpad_all:
-       rjmp handle_end_sleep
-
-
-
-
-
-#include "../common/OWPinInterrupt.s"
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+#define _CHANGEABLE_ID_\r
+//#define _DIS_FLASH_\r
+#define _ZERO_POLLING_\r
+//#define _DB_\r
+\r
+#include "../common/OWConfig.s"\r
+#include "../common/OWCRC8.s"\r
+\r
+#if  defined(__AVR_ATtiny25__)\r
+.extern pack,16\r
+#else\r
+.extern pack,64\r
+#endif\r
+.extern  am2302_temp,2\r
+.extern  am2302_hum,2\r
+.comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)\r
+\r
+\r
+.macro CHIP_INIT\r
+.endm\r
+\r
+; Ab hier Geraeteabhaenging\r
+#define OW_READ_SCRATCHPAD_ADR OW_FIRST_COMMAND+0\r
+#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+1\r
+#define OW_WRITE_SCRATCHPAD_ADR OW_FIRST_COMMAND+2\r
+#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+3\r
+\r
+\r
+\r
+.macro COMMAND_TABLE\r
+               rjmp h_readscratchpad_adr\r
+               rjmp h_readscratchpad\r
+               rjmp h_writescratchpad_adr\r
+               rjmp h_writescratchpad\r
+.endm\r
+\r
+#include "../common/OWRomFunctions.s"\r
+#include "../common/OWTimerInterrupt.s"\r
+\r
+\r
+;---------------------------------------------------\r
+;      READ COMMAND and start operation\r
+;---------------------------------------------------\r
+\r
+\r
+h_readcommand:\r
+       clr r_bytep\r
+#ifndef _DIS_FLASH_\r
+       FLASH_COMMANDS ; muss zu erst sein....\r
+#endif\r
+       cset 0xBE,OW_READ_SCRATCHPAD_ADR\r
+       cset 0x4E,OW_WRITE_SCRATCHPAD_ADR\r
+       cjmp 0x44,hrc_set_convertT\r
+       cjmp 0xB4,hrc_set_convertV\r
+       FW_CONFIG_INFO\r
+#ifdef _CHANGEABLE_ID_\r
+       CHANGE_ID_COMMANDS\r
+#endif\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_set_convertT:\r
+       ldi r_temp,1\r
+       sts gcontrol,r_temp\r
+       lds r_temp,am2302_temp\r
+       sts pack+1,r_temp\r
+       lds r_temp,am2302_temp+1\r
+       sts pack+2,r_temp\r
+       rjmp handle_end_sleep\r
+hrc_set_convertV:\r
+       ldi r_temp,2\r
+       sts gcontrol,r_temp\r
+       lds r_temp,pack\r
+       sbrs r_temp,3\r
+       rjmp hrc_set_convertVV\r
+       ldi r_temp,0xF4\r
+       sts pack+3,r_temp\r
+       ldi r_temp,0x01\r
+       sts pack+4,r_temp\r
+       rjmp hrc_set_convertend\r
+hrc_set_convertVV:\r
+       lds r_temp,am2302_hum\r
+       sts pack+3,r_temp\r
+       lds r_temp,am2302_hum+1\r
+       sts pack+4,r_temp\r
+hrc_set_convertend:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ SCRATCHPAD\r
+;---------------------------------------------------\r
+\r
+h_readscratchpad_adr:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_sendflag,1\r
+       ldi r_mode,OW_READ_SCRATCHPAD\r
+       CRCInit2\r
+h_readscratchpad:\r
+       cpi  r_bytep,8\r
+       breq h_readscratchpad_crc\r
+       cpi  r_bytep,9\r
+       breq h_readscratchpad_all\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack,r_temp\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readscratchpad_crc:\r
+       lds  r_rwbyte,crc\r
+       rjmp handle_end_inc\r
+h_readscratchpad_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   WRITE SCRATCHPAD\r
+;---------------------------------------------------\r
+h_writescratchpad_adr:\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+       lsl r_rwbyte\r
+#if  defined(__AVR_ATtiny25__)\r
+       andi r_rwbyte,0x01 ;nur Page 0 und 1 und das immer wiederholen\r
+#endif\r
+       sts block,r_rwbyte\r
+       ldi r_mode,OW_WRITE_SCRATCHPAD\r
+       ldi  r_bcount,1 \r
+       rjmp handle_end \r
+h_writescratchpad:\r
+       cpi  r_bytep,8\r
+       breq h_writescratchpad_all\r
+       lds  r_temp,block\r
+       add  r_temp,r_bytep\r
+       configZ pack,r_temp\r
+       st   Z,r_rwbyte\r
+       rjmp handle_end_inc\r
+h_writescratchpad_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+\r
+\r
+#include "../common/OWPinInterrupt.s"\r
 .end
\ No newline at end of file
index 72aef80..df8952d 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-       
-.global PIN_INTERRIPT  
-PIN_INTERRIPT:
-       ;leitung auf Low ziehen
-       TESTZEROMARKER ; ueberspringe wenn zeromarker=0   ;sbic und cbi/sbi andern SREG nicht
-       sbi OW_DDR,OW_PINN  
-       push r_temp2                //; wichtig: Benutzte Register und das
-    in r_temp2,_SFR_IO_ADDR(SREG)     //; Status-Register (SREG) sichern!
-       ;Zeromarker loeschen
-       RESETZEROMARKER 
-       ;Weitere Register sichern
-    push r_temp2 
-       push r_temp
-       sdb
-       ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW 
-       SET_FALLING_RESET_SLEEP
-       push r_bcount
-       push r_rwbyte
-       push r_sendflag
-       ;schauen ob noch ein Bit in der Pipeline 
-       lds r_bcount,bcount
-       lds r_rwbyte,rwbyte
-       lds r_sendflag,sendflag
-int_internal_start:
-       ;Timer zuruecksetzen
-       ldi r_temp,~OWT_MIN_RESET
-       out TCNT_REG,r_temp
-       EN_TIM_INT
-       tst r_sendflag
-       breq receive_bit ; sendflag=0 Slave empfaengt
-
-send_bit: ; bit senden
-       ;nachstes bit vorbereiten
-       tst r_bcount
-       brne send_bit_no_handle ;noch bits da 
-       rcall handle_byte ; neues Byte muss bearbeitet werden
-       tst r_sendflag  
-       breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....
-send_bit_no_handle:  ;noch bits da
-       ldi r_temp2,0   ; fuer die CRC berechnung in CRCS
-       ror r_rwbyte
-       brcs send_bit_no_low
-       SETZEROMARKER
-       ldi r_temp2,1 ;WICHTIG fuer CRC berechnung
-send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird
-       CRCS
-       ;naechstes byte ....
-       lsl r_bcount
-       sbis OW_DDR,OW_PINN
-       rjmp iend ;abkuerzung wenn leitung nicht low
-send_bit_low_loop:
-       in r_temp,TCNT_REG
-       cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer
-       brlo send_bit_low_loop ;wenn kleiner 
-       cbi OW_DDR,OW_PINN  ;Leitung auf hochohmig 
-       rjmp iend
-
-receive_bit: ;or reset 
-       ;beim lesen zuerst zeit bis zum lesen abwarten 
-       ;(9us nach den 6 us vom low impuls) 
-       in r_temp,TCNT_REG
-       cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer
-       brlo receive_bit ;wenn kleiner 
-       lsr r_rwbyte 
-       ldi r_temp2,1  ;fuer CRC Berechnung
-       sbis OW_PIN,OW_PINN
-       rjmp receive_bit_crc
-       ori r_rwbyte,0x80
-       ldi r_temp2,0 ;fuer CRC Berechnung
-receive_bit_crc:
-       CRCR
-       lsl r_bcount
-       brne recive_bit_no_handle ;bcount nicht 0
-       ;naechstes byte ....
-       rcall handle_byte
-       tst r_sendflag  
-       brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....
-recive_bit_no_handle:  
-iend:
-#ifdef _ZERO_POLLING_
-       ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490
-       TESTZEROMARKER ; ueberspringe wenn zeromarker=0  
-       rjmp zeropolling
-       rjmp no_zerromaker
-zeropolling:
-       sbrc r_sendflag,1  ; sendflag bit 1 -> switch off zeropolling in software eg for asking convert is donne (DS2450, DS18B20 and others)
-       rjmp no_zerromaker
-zeropolling_h_loop:
-       sbic OW_PIN,OW_PINN ;warten bis leitung wieder h 
-       rjmp zeropolling_wait  ;leitung ist low ->Schleie
-       in r_temp,TCNT_REG
-       cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer
-       brsh  zeropolling_timeout ;Timeout Reset?
-       rjmp zeropolling_h_loop
-zeropolling_wait:
-       sbis OW_PIN,OW_PINN ;warten bis leitung wieder l
-       rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
-       in r_temp,TCNT_REG
-       cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer
-       sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags)
-       rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe
-       brlo zeropolling_wait
-       rjmp zeropolling_timeout 
-zeropolling_low_imp:
-       sbi OW_DDR,OW_PINN 
-       RESETZEROMARKER 
-       rjmp int_internal_start
-
-zeropolling_timeout:
-       //in r_temp,TCNT_REG
-       //clr r_sendflag
-       //RESETZEROMARKER 
-
-no_zerromaker: 
-#endif
-       CLEAR_INTERRUPT_FLAG  ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist
-       sts sendflag,r_sendflag
-       sts bcount,r_bcount
-       sts rwbyte,r_rwbyte
-       pop r_sendflag
-       pop r_rwbyte
-       pop r_bcount
-       pop r_temp
-       cdb
-       cbi OW_DDR,OW_PINN  ;vorsichtsmassname Nicht dauerhaft auf low
-       pop r_temp2                       //; die benutzten Register wiederherstellen
-    out _SFR_IO_ADDR(SREG),r_temp2
-    pop r_temp2
-    reti
-
-
-
-
-handle_byte:
-       push zl
-       push zh
-       push r_mode
-       push r_bytep
-       //cdb
-       lds r_mode,mode
-       lds r_bytep,bytep
-
-
-       ldi zl,lo8(pm(handle_stable)) 
-       ldi zh,hi8(pm(handle_stable)) 
-       add zl,r_mode
-#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))
-       ldi r_temp,0 
-       adc zh,r_temp
-#endif
-       ijmp 
-handle_end_sleep:
-       clr r_bcount
-       ldi r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end_no_bcount
-handle_end_inc:
-       inc r_bytep
-handle_end:
-       ldi r_bcount,1
-handle_end_no_bcount:
-       sts mode,r_mode
-       sts bytep,r_bytep
-       //sdb
-       pop r_bytep
-       pop r_mode
-       pop zh
-       pop zl
-       ret
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+       \r
+.global PIN_INTERRIPT  \r
+PIN_INTERRIPT:\r
+       ;leitung auf Low ziehen\r
+       TESTZEROMARKER ; ueberspringe wenn zeromarker=0   ;sbic und cbi/sbi andern SREG nicht\r
+       sbi OW_DDR,OW_PINN  \r
+       push r_temp2                //; wichtig: Benutzte Register und das\r
+    in r_temp2,_SFR_IO_ADDR(SREG)     //; Status-Register (SREG) sichern!\r
+       ;Zeromarker loeschen\r
+       RESETZEROMARKER \r
+       ;Weitere Register sichern\r
+    push r_temp2 \r
+       push r_temp\r
+       sdb\r
+       ; Wegen Power Down Mode Widerherstellen der fallenden Flanke und disable von POWER DONW \r
+       SET_FALLING_RESET_SLEEP\r
+       push r_bcount\r
+       push r_rwbyte\r
+       push r_sendflag\r
+       ;schauen ob noch ein Bit in der Pipeline \r
+       lds r_bcount,bcount\r
+       lds r_rwbyte,rwbyte\r
+       lds r_sendflag,sendflag\r
+int_internal_start:\r
+       ;Timer zuruecksetzen\r
+       ldi r_temp,~OWT_MIN_RESET\r
+       out TCNT_REG,r_temp\r
+       EN_TIM_INT\r
+       tst r_sendflag\r
+       breq receive_bit ; sendflag=0 Slave empfaengt\r
+\r
+send_bit: ; bit senden\r
+       ;nachstes bit vorbereiten\r
+       tst r_bcount\r
+       brne send_bit_no_handle ;noch bits da \r
+       rcall handle_byte ; neues Byte muss bearbeitet werden\r
+       tst r_sendflag  \r
+       breq send_bit_low_loop ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+send_bit_no_handle:  ;noch bits da\r
+       ldi r_temp2,0   ; fuer die CRC berechnung in CRCS\r
+       ror r_rwbyte\r
+       brcs send_bit_no_low\r
+       SETZEROMARKER\r
+       ldi r_temp2,1 ;WICHTIG fuer CRC berechnung\r
+send_bit_no_low: ;ueberspringen von r_wzero=1 wenn leitung nicht auf 0 gezogen wird\r
+       CRCS\r
+       ;naechstes byte ....\r
+       lsl r_bcount\r
+       sbis OW_DDR,OW_PINN\r
+       rjmp iend ;abkuerzung wenn leitung nicht low\r
+send_bit_low_loop:\r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,(~OWT_MIN_RESET)+OWT_WRITE ;aller zwei us zaehlt der timer\r
+       brlo send_bit_low_loop ;wenn kleiner \r
+       cbi OW_DDR,OW_PINN  ;Leitung auf hochohmig \r
+       rjmp iend\r
+\r
+receive_bit: ;or reset \r
+       ;beim lesen zuerst zeit bis zum lesen abwarten \r
+       ;(9us nach den 6 us vom low impuls) \r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,(~OWT_MIN_RESET)+OWT_READ ;aller zwei us zaehlt der timer\r
+       brlo receive_bit ;wenn kleiner \r
+       lsr r_rwbyte \r
+       ldi r_temp2,1  ;fuer CRC Berechnung\r
+       sbis OW_PIN,OW_PINN\r
+       rjmp receive_bit_crc\r
+       ori r_rwbyte,0x80\r
+       ldi r_temp2,0 ;fuer CRC Berechnung\r
+receive_bit_crc:\r
+       CRCR\r
+       lsl r_bcount\r
+       brne recive_bit_no_handle ;bcount nicht 0\r
+       ;naechstes byte ....\r
+       rcall handle_byte\r
+       tst r_sendflag  \r
+       brne send_bit ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+recive_bit_no_handle:  \r
+iend:\r
+#ifdef _ZERO_POLLING_\r
+       ;--------------------------------------- Polling for set low... for 4us low impuls of DS2490\r
+       TESTZEROMARKER ; ueberspringe wenn zeromarker=0  \r
+       rjmp zeropolling\r
+       rjmp no_zerromaker\r
+zeropolling:\r
+       sbrc r_sendflag,1  ; sendflag bit 1 -> switch off zeropolling in software eg for asking convert is donne (DS2450, DS18B20 and others)\r
+       rjmp no_zerromaker\r
+zeropolling_h_loop:\r
+       sbic OW_PIN,OW_PINN ;warten bis leitung wieder h \r
+       rjmp zeropolling_wait  ;leitung ist low ->Schleie\r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_LOW_TO;aller zwei us zaehlt der timer\r
+       brsh  zeropolling_timeout ;Timeout Reset?\r
+       rjmp zeropolling_h_loop\r
+zeropolling_wait:\r
+       sbis OW_PIN,OW_PINN ;warten bis leitung wieder l\r
+       rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe\r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,(~OWT_MIN_RESET)+OWT_ZP_WAIT_HIGH_TO ;aller zwei us zaehlt der timer\r
+       sbis OW_PIN,OW_PINN ;noch eine Abfrage, da sonst schleife zu lang (sbis aendert keine flags)\r
+       rjmp zeropolling_low_imp ;Leitung ist low raus aus schleufe\r
+       brlo zeropolling_wait\r
+       rjmp zeropolling_timeout \r
+zeropolling_low_imp:\r
+       sbi OW_DDR,OW_PINN \r
+       RESETZEROMARKER \r
+       rjmp int_internal_start\r
+\r
+zeropolling_timeout:\r
+       //in r_temp,TCNT_REG\r
+       //clr r_sendflag\r
+       //RESETZEROMARKER \r
+\r
+no_zerromaker: \r
+#endif\r
+       CLEAR_INTERRUPT_FLAG  ; wichtig falls inzwischen wider ein Interrupt aufgelaufen ist\r
+       sts sendflag,r_sendflag\r
+       sts bcount,r_bcount\r
+       sts rwbyte,r_rwbyte\r
+       pop r_sendflag\r
+       pop r_rwbyte\r
+       pop r_bcount\r
+       pop r_temp\r
+       cdb\r
+       cbi OW_DDR,OW_PINN  ;vorsichtsmassname Nicht dauerhaft auf low\r
+       pop r_temp2                       //; die benutzten Register wiederherstellen\r
+    out _SFR_IO_ADDR(SREG),r_temp2\r
+    pop r_temp2\r
+    reti\r
+\r
+\r
+\r
+\r
+handle_byte:\r
+       push zl\r
+       push zh\r
+       push r_mode\r
+       push r_bytep\r
+       //cdb\r
+       lds r_mode,mode\r
+       lds r_bytep,bytep\r
+\r
+\r
+       ldi zl,lo8(pm(handle_stable)) \r
+       ldi zh,hi8(pm(handle_stable)) \r
+       add zl,r_mode\r
+#if ((handle_stable&0xFE00)!=(handle_stable_end&0xFE00))\r
+       ldi r_temp,0 \r
+       adc zh,r_temp\r
+#endif\r
+       ijmp \r
+handle_end_sleep:\r
+       clr r_bcount\r
+       ldi r_mode,OW_SLEEP\r
+       clr r_sendflag\r
+       rjmp handle_end_no_bcount\r
+handle_end_inc:\r
+       inc r_bytep\r
+handle_end:\r
+       ldi r_bcount,1\r
+handle_end_no_bcount:\r
+       sts mode,r_mode\r
+       sts bytep,r_bytep\r
+       //sdb\r
+       pop r_bytep\r
+       pop r_mode\r
+       pop zh\r
+       pop zl\r
+       ret\r
index e889416..e5c007b 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-
-.macro cjmp val,addr
-       cpi r_rwbyte,\val
-       breq \addr
-.endm
-.macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx
-       cpi r_rwbyte,\val
-       brne 1f
-       rjmp \addr
-1:
-.endm
-
-.macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt
-       cpi r_rwbyte,\val
-       brne 1f
-       ldi r_mode,\mod
-       rjmp handle_end
-1:
-.endm
-
-
-
-
-#define OW_SLEEP 0
-#define OW_READ_ROM_COMMAND 1
-#define OW_MATCHROM 2
-#define OW_SEARCHROMS 3  ;next send two bit
-#define OW_SEARCHROMR 4  ; next resive master answer
-#define OW_READROM 5
-#define OW_READ_COMMAND 6
-#define OW_FWCONFIGINFO 7
-
-
-#ifdef _CHANGEABLE_ID_
-#define OW_WRITE_NEWID 8
-#define OW_READ_NEWID 9
-#define OW_SET_NEWID 10
-#define OW_FIRST_COMMAND 11
-.comm newid,8
-
-       
-.macro CHANGE_ID_COMMANDS
-       cset 0x75,OW_WRITE_NEWID
-       cljmp 0xA7,hrc_set_readid
-       cljmp 0x79,hrc_set_setid
-.endm
-
-
-#else
-#define OW_FIRST_COMMAND 8
-#endif
-
-#ifndef _DIS_FLASH_
-; test auf run flasher command 0x88 in h_readcommand
-.macro FLASH_COMMANDS
-       cpi r_rwbyte,0x88
-       brne 1f
-       rjmp hrc_jmp_flasher
-1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen...
-       sts flashmarker,r_temp
-.endm
-#endif
-
-.macro FW_CONFIG_INFO
-       cljmp 0x85,hrc_fw_configinfo
-.endm
-
-
-#ifdef _CHANGEABLE_ID_
-; lesen der ID aus dem EEPROM beim Start
-read_EEPROM_ID:  
-       push r_bytep
-       push r_rwbyte//r_temp2 and Z is not in gnu C save area
-       ldi r_temp2,lo8(E2END)
-       ldi zh,hi8(E2END)
-       subi r_temp2,7
-       out _SFR_IO_ADDR(EEARH), zh
-       ldi r_bytep,0
-       ldi  zl,lo8(owid)       
-    ldi  zh,hi8(owid)
-read_EEPROM_ID_loop:
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp read_EEPROM_ID_loop
-       out _SFR_IO_ADDR(EEARL),r_temp2
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_rwbyte,_SFR_IO_ADDR(EEDR)
-       cpi r_rwbyte,0xFF
-       breq read_EEPROM_ID_end
-       st Z+,r_rwbyte
-       inc r_bytep
-       inc r_temp2
-       cpi r_bytep,8
-       brne read_EEPROM_ID_loop
-read_EEPROM_ID_end:
-       pop r_rwbyte
-       pop r_bytep
-       ret
-#endif
-
-
-
-
-
-
-handle_stable: 
-               rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten
-               rjmp h_readromcommand 
-               rjmp h_matchrom 
-               rjmp h_searchroms 
-               rjmp h_searchromr
-               rjmp h_readrom
-               rjmp h_readcommand 
-               rjmp h_fwconfiginfo
-#ifdef _CHANGEABLE_ID_
-               rjmp h_writeid
-               rjmp h_readid
-               rjmp h_setid
-#endif
-               COMMAND_TABLE
-
-
-
-h_readromcommand:
-       clr r_bytep
-       cset 0x55,OW_MATCHROM 
-       cjmp 0xF0,hrc_set_searchrom
-       cjmp 0xCC,hrc_start_read_command ;skip rom
-       cjmp 0x33,hrc_set_read_rom
-       cjmp 0xEC,hrc_set_alarm_search
-       
-       rjmp handle_end_sleep
-
-#ifndef _DIS_FLASH_
-;sprung zum flasher
-hrc_jmp_flasher:
-       lds r_temp,flashmarker
-       cpi r_temp,2
-       brne hrc_jmp_flasher_inc
-       ldi r_temp,0xC0
-       push r_temp
-       ldi r_temp,0x0E
-       push r_temp
-       ret ; Direkter Sprung zum Bootloader
-hrc_jmp_flasher_inc:
-       inc r_temp
-       sts flashmarker,r_temp
-       rjmp handle_end_sleep
-#endif
-
-
-hrc_set_searchrom:     
-       lds r_rwbyte,owid ;erstes Byte lesen
-       rjmp h_searchrom_next_bit
-
-hrc_start_read_command: ;Skip rom und Matchrom ok...
-       ldi r_mode,OW_READ_COMMAND
-       CRCInit1
-       rjmp handle_end
-
-hrc_set_read_rom:
-       ldi r_mode,OW_READROM
-       ldi r_sendflag,1
-       rjmp h_readrom
-
-hrc_set_alarm_search:
-       lds r_temp,alarmflag
-       tst r_temp
-       brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom
-       ; sonst tue nichts
-       rjmp handle_end_sleep
-
-
-hrc_fw_configinfo:
-       ldi r_mode,OW_FWCONFIGINFO
-       ldi r_sendflag,1
-       CRCInit2
-       rjmp h_fwconfiginfo
-
-
-;---------------------------------------------------
-;   MATCH ROM
-;---------------------------------------------------
-       
-
-h_matchrom:
-       configZ owid,r_bytep
-       ld r_temp,Z
-       cp r_temp,r_rwbyte
-       breq hmr_next_byte
-       rjmp handle_end_sleep
-
-hmr_next_byte:
-       cpi r_bytep,7
-       breq hrc_start_read_command ;Starten von Read Command
-       rjmp handle_end_inc
-
-
-
-;---------------------------------------------------
-;   SEARCH ROM
-;---------------------------------------------------
-
-
-h_searchrom_next_bit:  ;Setup next Bit of ID
-       sts srbyte,r_rwbyte ;erstes Byte speichern von der Aufrufenden Ebene
-       mov r_temp2,r_rwbyte
-       com r_rwbyte ; negieren
-       ror r_temp2 ; erstes unnegiertes bit in Carry
-       rol r_rwbyte ;und dann als erstes bit in r_rwbyte
-       ldi r_sendflag,1
-       ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr 
-       ldi r_mode,OW_SEARCHROMR
-       rjmp handle_end_no_bcount
-
-
-
-h_searchroms:  ; Modus Send zwei bit
-       clr r_temp
-       sbrc r_rwbyte,7 ; bit gesetz (1 empfangen)
-       ldi r_temp,1
-       lds r_bcount,srbyte ;r_bcount wird am ende gesetzt
-       eor r_temp,r_bcount
-       sbrs r_temp,0
-       rjmp h_searchroms_next ; Vergleich des letzen gelesenen bits mit der id
-       ;Ungleich....
-       ;goto sleep
-       ;clr r_sendflag
-       ; ist ja auf lesen
-       rjmp handle_end_sleep
-h_searchroms_next: ; Setup next bit
-       inc r_bytep  ; zaehler der Bits erhoehen
-       sbrc r_bytep,6 ; 64 bit erreicht 
-       rjmp h_searchrom_end_ok ;alles ok auf Command warten
-       mov r_temp,r_bytep 
-       andi r_temp,0x07
-       brne h_searchroms_next_bit  ; bit zwischen 0 und 8
-       mov r_bcount,r_bytep  ; next Byte lesen
-       lsr r_bcount    
-       lsr r_bcount
-       lsr r_bcount
-
-       configZ owid,r_bcount
-       ld r_rwbyte,Z
-       sts srbyte,r_rwbyte
-       rjmp h_searchrom_next_bit
-               
-h_searchroms_next_bit: ;next Bit lesen
-       ;sts srbytep,r_bcount
-       lds r_rwbyte,srbyte
-       lsr r_rwbyte ;aktuelles byte weiterschieben r_rwbyte hier zweckefrei verwendet
-       rjmp h_searchrom_next_bit  ;algemeine routine zum vorbereiten
-h_searchrom_end_ok:
-       clr r_sendflag
-       rjmp hrc_start_read_command
-
-h_searchromr:
-       clr r_sendflag
-       ldi r_mode,OW_SEARCHROMS
-       ldi r_bcount,0
-       rjmp handle_end_no_bcount
-
-
-;---------------------------------------------------
-;   READ ROM
-;---------------------------------------------------
-
-h_readrom:
-       cpi  r_bytep,8
-       breq h_readrom_all
-       configZ owid,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readrom_all:
-       rjmp handle_end_sleep
-
-
-;---------------------------------------------------
-;   FW_CONFIG_INFO
-;---------------------------------------------------
-
-h_fwconfiginfo:
-       cpi  r_bytep,16
-       breq h_fwconfiginfo_crc
-#ifdef _CRC8_
-       cpi  r_bytep,17
-       breq h_fwconfiginfo_all
-#elif defined _CRC16_
-       cpi  r_bytep,17
-       breq h_fwconfiginfo_crc2
-       cpi  r_bytep,18
-       breq h_fwconfiginfo_all
-#else
-       cpi  r_bytep,16
-       breq h_fwconfiginfo_all
-#warning No CRC known code implemented
-#endif
-       configZ config_info,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_fwconfiginfo_crc:
-       lds r_rwbyte,crc
-       rjmp handle_end_inc
-h_fwconfiginfo_crc2:
-       lds r_rwbyte,crc+1
-       rjmp handle_end_inc
-h_fwconfiginfo_all:
-       rjmp handle_end_sleep
-
-
-;---------------------------------------------------
-;   CHANGE ROM FUNCTIONS
-;---------------------------------------------------
-
-
-#ifdef _CHANGEABLE_ID_
-
-h_writeid:
-       configZ newid,r_bytep
-       st   Z,r_rwbyte
-       cpi  r_bytep,7
-       breq h_writeid_all
-       rjmp handle_end_inc
-h_writeid_all:
-       rjmp handle_end_sleep
-
-
-hrc_set_readid:
-       ldi r_mode,OW_READ_NEWID
-       ldi r_sendflag,1
-h_readid:
-       cpi  r_bytep,8
-       breq h_readid_all
-       configZ newid,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readid_all:
-       clr  r_sendflag
-       rjmp handle_end_sleep
-
-hrc_set_setid:
-       ldi r_mode,OW_SET_NEWID
-       ;ldi r_bytep,1 ;start to write in 2
-       rjmp handle_end_inc ;set r_bytep to 1!!!
-
-h_setid:
-       configZ owid,r_bytep
-       ld r_temp,Z
-       cp r_rwbyte,r_temp
-       brne h_setid_bad_code_all
-       cpi r_bytep,1
-       breq h_setid_set2
-       cpi r_bytep,5 
-       breq h_setid_set3
-       cpi r_bytep,6
-       breq h_setid_copy_id
-       rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren
-h_setid_set2:
-       ldi r_temp,3
-       add r_bytep,r_temp
-h_setid_set3:
-       inc r_bytep
-       rjmp handle_end
-h_setid_copy_id:
-       ldi r_temp2,lo8(E2END)
-       ldi zh,hi8(E2END)
-       ldi r_temp,7
-       sub r_temp2,r_temp
-       ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist
-       ;sbc zh
-       out _SFR_IO_ADDR(EEARH),zh
-       ldi zl,lo8(newid)
-       ldi zh,hi8(newid)
-       ldi r_bytep,0
-h_setid_EEPROM_write:
-       sbic _SFR_IO_ADDR(EECR), EEPE   
-       rjmp h_setid_EEPROM_write
-       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
-       out _SFR_IO_ADDR(EECR), r_temp
-       ;nur adresse L schreiben H bleibt aus oben genannten grund gleich.
-       out _SFR_IO_ADDR(EEARL),r_temp2
-       ld  r_rwbyte,Z+
-       out _SFR_IO_ADDR(EEDR), r_rwbyte
-       sbi _SFR_IO_ADDR(EECR), EEMPE
-       sbi _SFR_IO_ADDR(EECR), EEPE
-       inc r_bytep
-       inc r_temp2
-       cpi r_bytep,8
-       brne h_setid_EEPROM_write
-       rcall read_EEPROM_ID
-h_setid_bad_code_all:
-       rjmp handle_end_sleep
-
-
-
-#endif
-
-
-spause:
-       nop
-       nop
-       nop
-       nop
-       ret
-
-
-.global OWINIT
-OWINIT:
-#ifndef _DIS_FLASH_
-; check for bootloader jumper
-       ;vor allen anderen Registerconfigs
-       push r_temp
-       ldi r_temp,(1<<PUD) ;enable pullup 
-       out _SFR_IO_ADDR(MCUCR) ,r_temp
-       sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
-       sbi _SFR_IO_ADDR(PORTA),PINA4 ;internal pullup on PINA4
-       rcall spause
-       sbis _SFR_IO_ADDR(PINA),PINA5
-       rjmp owinit_botest_end  ;PinA5 nicht auf 1
-       sbis _SFR_IO_ADDR(PINA),PINA4
-       rjmp owinit_botest_end ;PinA4 nicht auf 1
-       cbi _SFR_IO_ADDR(PORTA),PINA4 
-       sbi _SFR_IO_ADDR(DDRA),PINA4  ;PINA4 AUSGANG und 0
-       rcall spause
-       sbic _SFR_IO_ADDR(PINA),PINA5 
-       rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden
-       cbi _SFR_IO_ADDR(DDRA),PINA4
-       ldi r_temp,0xC0
-       push r_temp
-       ldi r_temp,0x0E
-       push r_temp
-       ret ; Direkter Sprung zum Bootloader*/
-owinit_botest_end:
-#endif
-       HW_INIT  //Microcontroller specific
-       CHIP_INIT //1-Wire device specific
-#ifdef _CHANGEABLE_ID_
-       rcall read_EEPROM_ID
-#endif
-       ldi r_temp,0
-       sts mode,r_temp
-       sts bcount,r_temp
-       sts alarmflag,r_temp
-       RESETZEROMARKER
-       pop r_temp
-       ret
-
-
-.global EXTERN_SLEEP
-EXTERN_SLEEP:
-       cli
-       push r_temp
-       ldi r_temp,0
-       sts mode,r_temp ;SLEEP
-       sts gcontrol,r_temp
-       sts sendflag,r_temp
-       sts bcount,r_temp
-       RESETZEROMARKER
-       pop r_temp
-       sei
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+\r
+.macro cjmp val,addr\r
+       cpi r_rwbyte,\val\r
+       breq \addr\r
+.endm\r
+.macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx\r
+       cpi r_rwbyte,\val\r
+       brne 1f\r
+       rjmp \addr\r
+1:\r
+.endm\r
+\r
+.macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt\r
+       cpi r_rwbyte,\val\r
+       brne 1f\r
+       ldi r_mode,\mod\r
+       rjmp handle_end\r
+1:\r
+.endm\r
+\r
+\r
+\r
+\r
+#define OW_SLEEP 0\r
+#define OW_READ_ROM_COMMAND 1\r
+#define OW_MATCHROM 2\r
+#define OW_SEARCHROMS 3  ;next send two bit\r
+#define OW_SEARCHROMR 4  ; next resive master answer\r
+#define OW_READROM 5\r
+#define OW_READ_COMMAND 6\r
+#define OW_FWCONFIGINFO 7\r
+\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+#define OW_WRITE_NEWID 8\r
+#define OW_READ_NEWID 9\r
+#define OW_SET_NEWID 10\r
+#define OW_FIRST_COMMAND 11\r
+.comm newid,8\r
+\r
+       \r
+.macro CHANGE_ID_COMMANDS\r
+       cset 0x75,OW_WRITE_NEWID\r
+       cljmp 0xA7,hrc_set_readid\r
+       cljmp 0x79,hrc_set_setid\r
+.endm\r
+\r
+\r
+#else\r
+#define OW_FIRST_COMMAND 8\r
+#endif\r
+\r
+#ifndef _DIS_FLASH_\r
+; test auf run flasher command 0x88 in h_readcommand\r
+.macro FLASH_COMMANDS\r
+       cpi r_rwbyte,0x88\r
+       brne 1f\r
+       rjmp hrc_jmp_flasher\r
+1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen...\r
+       sts flashmarker,r_temp\r
+.endm\r
+#endif\r
+\r
+.macro FW_CONFIG_INFO\r
+       cljmp 0x85,hrc_fw_configinfo\r
+.endm\r
+\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+; lesen der ID aus dem EEPROM beim Start\r
+read_EEPROM_ID:  \r
+       push r_bytep\r
+       push r_rwbyte//r_temp2 and Z is not in gnu C save area\r
+       ldi r_temp2,lo8(E2END)\r
+       ldi zh,hi8(E2END)\r
+       subi r_temp2,7\r
+       out _SFR_IO_ADDR(EEARH), zh\r
+       ldi r_bytep,0\r
+       ldi  zl,lo8(owid)       \r
+    ldi  zh,hi8(owid)\r
+read_EEPROM_ID_loop:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp read_EEPROM_ID_loop\r
+       out _SFR_IO_ADDR(EEARL),r_temp2\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_rwbyte,_SFR_IO_ADDR(EEDR)\r
+       cpi r_rwbyte,0xFF\r
+       breq read_EEPROM_ID_end\r
+       st Z+,r_rwbyte\r
+       inc r_bytep\r
+       inc r_temp2\r
+       cpi r_bytep,8\r
+       brne read_EEPROM_ID_loop\r
+read_EEPROM_ID_end:\r
+       pop r_rwbyte\r
+       pop r_bytep\r
+       ret\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+\r
+handle_stable: \r
+               rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten\r
+               rjmp h_readromcommand \r
+               rjmp h_matchrom \r
+               rjmp h_searchroms \r
+               rjmp h_searchromr\r
+               rjmp h_readrom\r
+               rjmp h_readcommand \r
+               rjmp h_fwconfiginfo\r
+#ifdef _CHANGEABLE_ID_\r
+               rjmp h_writeid\r
+               rjmp h_readid\r
+               rjmp h_setid\r
+#endif\r
+               COMMAND_TABLE\r
+\r
+\r
+\r
+h_readromcommand:\r
+       clr r_bytep\r
+       cset 0x55,OW_MATCHROM \r
+       cjmp 0xF0,hrc_set_searchrom\r
+       cjmp 0xCC,hrc_start_read_command ;skip rom\r
+       cjmp 0x33,hrc_set_read_rom\r
+       cjmp 0xEC,hrc_set_alarm_search\r
+       \r
+       rjmp handle_end_sleep\r
+\r
+#ifndef _DIS_FLASH_\r
+;sprung zum flasher\r
+hrc_jmp_flasher:\r
+       lds r_temp,flashmarker\r
+       cpi r_temp,2\r
+       brne hrc_jmp_flasher_inc\r
+       ldi r_temp,0xC0\r
+       push r_temp\r
+       ldi r_temp,0x0E\r
+       push r_temp\r
+       ret ; Direkter Sprung zum Bootloader\r
+hrc_jmp_flasher_inc:\r
+       inc r_temp\r
+       sts flashmarker,r_temp\r
+       rjmp handle_end_sleep\r
+#endif\r
+\r
+\r
+hrc_set_searchrom:     \r
+       lds r_rwbyte,owid ;erstes Byte lesen\r
+       rjmp h_searchrom_next_bit\r
+\r
+hrc_start_read_command: ;Skip rom und Matchrom ok...\r
+       ldi r_mode,OW_READ_COMMAND\r
+       CRCInit1\r
+       rjmp handle_end\r
+\r
+hrc_set_read_rom:\r
+       ldi r_mode,OW_READROM\r
+       ldi r_sendflag,1\r
+       rjmp h_readrom\r
+\r
+hrc_set_alarm_search:\r
+       lds r_temp,alarmflag\r
+       tst r_temp\r
+       brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom\r
+       ; sonst tue nichts\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_fw_configinfo:\r
+       ldi r_mode,OW_FWCONFIGINFO\r
+       ldi r_sendflag,1\r
+       CRCInit2\r
+       rjmp h_fwconfiginfo\r
+\r
+\r
+;---------------------------------------------------\r
+;   MATCH ROM\r
+;---------------------------------------------------\r
+       \r
+\r
+h_matchrom:\r
+       configZ owid,r_bytep\r
+       ld r_temp,Z\r
+       cp r_temp,r_rwbyte\r
+       breq hmr_next_byte\r
+       rjmp handle_end_sleep\r
+\r
+hmr_next_byte:\r
+       cpi r_bytep,7\r
+       breq hrc_start_read_command ;Starten von Read Command\r
+       rjmp handle_end_inc\r
+\r
+\r
+\r
+;---------------------------------------------------\r
+;   SEARCH ROM\r
+;---------------------------------------------------\r
+\r
+\r
+h_searchrom_next_bit:  ;Setup next Bit of ID\r
+       sts srbyte,r_rwbyte ;erstes Byte speichern von der Aufrufenden Ebene\r
+       mov r_temp2,r_rwbyte\r
+       com r_rwbyte ; negieren\r
+       ror r_temp2 ; erstes unnegiertes bit in Carry\r
+       rol r_rwbyte ;und dann als erstes bit in r_rwbyte\r
+       ldi r_sendflag,1\r
+       ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr \r
+       ldi r_mode,OW_SEARCHROMR\r
+       rjmp handle_end_no_bcount\r
+\r
+\r
+\r
+h_searchroms:  ; Modus Send zwei bit\r
+       clr r_temp\r
+       sbrc r_rwbyte,7 ; bit gesetz (1 empfangen)\r
+       ldi r_temp,1\r
+       lds r_bcount,srbyte ;r_bcount wird am ende gesetzt\r
+       eor r_temp,r_bcount\r
+       sbrs r_temp,0\r
+       rjmp h_searchroms_next ; Vergleich des letzen gelesenen bits mit der id\r
+       ;Ungleich....\r
+       ;goto sleep\r
+       ;clr r_sendflag\r
+       ; ist ja auf lesen\r
+       rjmp handle_end_sleep\r
+h_searchroms_next: ; Setup next bit\r
+       inc r_bytep  ; zaehler der Bits erhoehen\r
+       sbrc r_bytep,6 ; 64 bit erreicht \r
+       rjmp h_searchrom_end_ok ;alles ok auf Command warten\r
+       mov r_temp,r_bytep \r
+       andi r_temp,0x07\r
+       brne h_searchroms_next_bit  ; bit zwischen 0 und 8\r
+       mov r_bcount,r_bytep  ; next Byte lesen\r
+       lsr r_bcount    \r
+       lsr r_bcount\r
+       lsr r_bcount\r
+\r
+       configZ owid,r_bcount\r
+       ld r_rwbyte,Z\r
+       sts srbyte,r_rwbyte\r
+       rjmp h_searchrom_next_bit\r
+               \r
+h_searchroms_next_bit: ;next Bit lesen\r
+       ;sts srbytep,r_bcount\r
+       lds r_rwbyte,srbyte\r
+       lsr r_rwbyte ;aktuelles byte weiterschieben r_rwbyte hier zweckefrei verwendet\r
+       rjmp h_searchrom_next_bit  ;algemeine routine zum vorbereiten\r
+h_searchrom_end_ok:\r
+       clr r_sendflag\r
+       rjmp hrc_start_read_command\r
+\r
+h_searchromr:\r
+       clr r_sendflag\r
+       ldi r_mode,OW_SEARCHROMS\r
+       ldi r_bcount,0\r
+       rjmp handle_end_no_bcount\r
+\r
+\r
+;---------------------------------------------------\r
+;   READ ROM\r
+;---------------------------------------------------\r
+\r
+h_readrom:\r
+       cpi  r_bytep,8\r
+       breq h_readrom_all\r
+       configZ owid,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readrom_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+;---------------------------------------------------\r
+;   FW_CONFIG_INFO\r
+;---------------------------------------------------\r
+\r
+h_fwconfiginfo:\r
+       cpi  r_bytep,16\r
+       breq h_fwconfiginfo_crc\r
+#ifdef _CRC8_\r
+       cpi  r_bytep,17\r
+       breq h_fwconfiginfo_all\r
+#elif defined _CRC16_\r
+       cpi  r_bytep,17\r
+       breq h_fwconfiginfo_crc2\r
+       cpi  r_bytep,18\r
+       breq h_fwconfiginfo_all\r
+#else\r
+       cpi  r_bytep,16\r
+       breq h_fwconfiginfo_all\r
+#warning No CRC known code implemented\r
+#endif\r
+       configZ config_info,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_crc:\r
+       lds r_rwbyte,crc\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_crc2:\r
+       lds r_rwbyte,crc+1\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+;---------------------------------------------------\r
+;   CHANGE ROM FUNCTIONS\r
+;---------------------------------------------------\r
+\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+\r
+h_writeid:\r
+       configZ newid,r_bytep\r
+       st   Z,r_rwbyte\r
+       cpi  r_bytep,7\r
+       breq h_writeid_all\r
+       rjmp handle_end_inc\r
+h_writeid_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_set_readid:\r
+       ldi r_mode,OW_READ_NEWID\r
+       ldi r_sendflag,1\r
+h_readid:\r
+       cpi  r_bytep,8\r
+       breq h_readid_all\r
+       configZ newid,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readid_all:\r
+       clr  r_sendflag\r
+       rjmp handle_end_sleep\r
+\r
+hrc_set_setid:\r
+       ldi r_mode,OW_SET_NEWID\r
+       ;ldi r_bytep,1 ;start to write in 2\r
+       rjmp handle_end_inc ;set r_bytep to 1!!!\r
+\r
+h_setid:\r
+       configZ owid,r_bytep\r
+       ld r_temp,Z\r
+       cp r_rwbyte,r_temp\r
+       brne h_setid_bad_code_all\r
+       cpi r_bytep,1\r
+       breq h_setid_set2\r
+       cpi r_bytep,5 \r
+       breq h_setid_set3\r
+       cpi r_bytep,6\r
+       breq h_setid_copy_id\r
+       rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren\r
+h_setid_set2:\r
+       ldi r_temp,3\r
+       add r_bytep,r_temp\r
+h_setid_set3:\r
+       inc r_bytep\r
+       rjmp handle_end\r
+h_setid_copy_id:\r
+       ldi r_temp2,lo8(E2END)\r
+       ldi zh,hi8(E2END)\r
+       ldi r_temp,7\r
+       sub r_temp2,r_temp\r
+       ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist\r
+       ;sbc zh\r
+       out _SFR_IO_ADDR(EEARH),zh\r
+       ldi zl,lo8(newid)\r
+       ldi zh,hi8(newid)\r
+       ldi r_bytep,0\r
+h_setid_EEPROM_write:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE   \r
+       rjmp h_setid_EEPROM_write\r
+       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)\r
+       out _SFR_IO_ADDR(EECR), r_temp\r
+       ;nur adresse L schreiben H bleibt aus oben genannten grund gleich.\r
+       out _SFR_IO_ADDR(EEARL),r_temp2\r
+       ld  r_rwbyte,Z+\r
+       out _SFR_IO_ADDR(EEDR), r_rwbyte\r
+       sbi _SFR_IO_ADDR(EECR), EEMPE\r
+       sbi _SFR_IO_ADDR(EECR), EEPE\r
+       inc r_bytep\r
+       inc r_temp2\r
+       cpi r_bytep,8\r
+       brne h_setid_EEPROM_write\r
+       rcall read_EEPROM_ID\r
+h_setid_bad_code_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+#endif\r
+\r
+\r
+spause:\r
+       nop\r
+       nop\r
+       nop\r
+       nop\r
+       ret\r
+\r
+\r
+.global OWINIT\r
+OWINIT:\r
+#ifndef _DIS_FLASH_\r
+; check for bootloader jumper\r
+       ;vor allen anderen Registerconfigs\r
+       push r_temp\r
+       ldi r_temp,(1<<PUD) ;enable pullup \r
+       out _SFR_IO_ADDR(MCUCR) ,r_temp\r
+       sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5\r
+       sbi _SFR_IO_ADDR(PORTA),PINA4 ;internal pullup on PINA4\r
+       rcall spause\r
+       sbis _SFR_IO_ADDR(PINA),PINA5\r
+       rjmp owinit_botest_end  ;PinA5 nicht auf 1\r
+       sbis _SFR_IO_ADDR(PINA),PINA4\r
+       rjmp owinit_botest_end ;PinA4 nicht auf 1\r
+       cbi _SFR_IO_ADDR(PORTA),PINA4 \r
+       sbi _SFR_IO_ADDR(DDRA),PINA4  ;PINA4 AUSGANG und 0\r
+       rcall spause\r
+       sbic _SFR_IO_ADDR(PINA),PINA5 \r
+       rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden\r
+       cbi _SFR_IO_ADDR(DDRA),PINA4\r
+       ldi r_temp,0xC0\r
+       push r_temp\r
+       ldi r_temp,0x0E\r
+       push r_temp\r
+       ret ; Direkter Sprung zum Bootloader*/\r
+owinit_botest_end:\r
+#endif\r
+       HW_INIT  //Microcontroller specific\r
+       CHIP_INIT //1-Wire device specific\r
+#ifdef _CHANGEABLE_ID_\r
+       rcall read_EEPROM_ID\r
+#endif\r
+       ldi r_temp,0\r
+       sts mode,r_temp\r
+       sts bcount,r_temp\r
+       sts alarmflag,r_temp\r
+       RESETZEROMARKER\r
+       pop r_temp\r
+       ret\r
+\r
+\r
+.global EXTERN_SLEEP\r
+EXTERN_SLEEP:\r
+       cli\r
+       push r_temp\r
+       ldi r_temp,0\r
+       sts mode,r_temp ;SLEEP\r
+       sts gcontrol,r_temp\r
+       sts sendflag,r_temp\r
+       sts bcount,r_temp\r
+       RESETZEROMARKER\r
+       pop r_temp\r
+       sei\r
        ret
\ No newline at end of file
index 1a9b0d4..9bbf71d 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-
-.macro cjmp val,addr
-       cpi r_rwbyte,\val
-       breq \addr
-.endm
-.macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx
-       cpi r_rwbyte,\val
-       brne 1f
-       rjmp \addr
-1:
-.endm
-
-.macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt
-       cpi r_rwbyte,\val
-       brne 1f
-       ldi r_mode,\mod
-       rjmp handle_end
-1:
-.endm
-
-
-
-
-#define OW_SLEEP 0
-#define OW_READ_ROM_COMMAND 1
-#define OW_MATCHROM 2
-#define OW_SEARCHROMS 3  ;next send two bit
-#define OW_SEARCHROMR 4  ; next resive master answer
-#define OW_READ_COMMAND1 5
-#define OW_READ_COMMAND2 6
-#define OW_FWCONFIGINFO1 7
-#define OW_FWCONFIGINFO2 8
-
-.comm idtable,64
-
-#ifdef _CHANGEABLE_ID_
-#define OW_WRITE_NEWID 9
-#define OW_READ_NEWID 10
-#define OW_SET_NEWID 11
-#define OW_FIRST_COMMAND 12
-.comm newid,8
-       
-.macro CHANGE_ID_COMMANDS
-       cset 0x75,OW_WRITE_NEWID
-       cljmp 0xA7,hrc_set_readid
-       cljmp 0x79,hrc_set_setid
-.endm
-
-
-#else
-#define OW_FIRST_COMMAND 9
-#endif
-
-#ifndef _DIS_FLASH_
-; test auf run flasher command 0x88 in h_readcommand
-.macro FLASH_COMMANDS
-       cpi r_rwbyte,0x88
-       brne 1f
-       rjmp hrc_jmp_flasher
-1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen...
-       sts flashmarker,r_temp
-.endm
-#endif
-
-
-.macro FW_CONFIG_INFO1
-       cljmp 0x85,hrc_fw_configinfo1
-.endm
-.macro FW_CONFIG_INFO2
-       cljmp 0x85,hrc_fw_configinfo2
-.endm
-
-#ifdef _CHANGEABLE_ID_
-; lesen der ID aus dem EEPROM beim Start
-read_EEPROM_ID1:  
-       ldi r_temp2,lo8(E2END)
-       ldi zh,hi8(E2END)
-       subi r_temp2,7
-       out _SFR_IO_ADDR(EEARH), zh
-       ldi r_bytep,0
-       ldi  zl,lo8(owid1)       
-    ldi  zh,hi8(owid1)
-       rjmp read_EEPROM_ID_loop
-read_EEPROM_ID2:  
-       ldi r_temp2,lo8(E2END)
-       ldi zh,hi8(E2END)
-       subi r_temp2,15
-       out _SFR_IO_ADDR(EEARH), zh
-       ldi r_bytep,0
-       ldi  zl,lo8(owid2)       
-    ldi  zh,hi8(owid2)
-read_EEPROM_ID_loop:
-       sbic _SFR_IO_ADDR(EECR), EEPE
-       rjmp read_EEPROM_ID_loop
-       out _SFR_IO_ADDR(EEARL),r_temp2
-       sbi _SFR_IO_ADDR(EECR), EERE
-       in r_rwbyte,_SFR_IO_ADDR(EEDR)
-       cpi r_rwbyte,0xFF
-       breq read_EEPROM_ID_end
-       st Z+,r_rwbyte
-       inc r_bytep
-       inc r_temp2
-       cpi r_bytep,8
-       brne read_EEPROM_ID_loop
-read_EEPROM_ID_end:
-       ret
-#endif
-
-
-
-
-
-
-
-handle_stable: 
-               rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten
-               rjmp h_readromcommand 
-               rjmp h_matchrom 
-               rjmp h_searchroms 
-               rjmp h_searchromr
-               rjmp h_readcommand1 
-               rjmp h_readcommand2
-               rjmp h_fwconfiginfo1
-               rjmp h_fwconfiginfo2
-#ifdef _CHANGEABLE_ID_
-               rjmp h_writeid
-               rjmp h_readid
-               rjmp h_setid
-#endif
-               COMMAND_TABLE
-
-
-
-h_readromcommand:
-       clr r_bytep
-       cjmp 0x55,hrc_set_matchrom
-       cjmp 0xF0,hrc_set_searchrom
-       cjmp 0xEC,hrc_set_alarm_search
-       
-       rjmp handle_end_sleep
-
-#ifndef _DIS_FLASH_
-;sprung zum flasher
-hrc_jmp_flasher:
-       lds r_temp,flashmarker
-       cpi r_temp,2
-       brne hrc_jmp_flasher_inc
-       ldi r_temp,0xC0
-       push r_temp
-       ldi r_temp,0x0E
-       push r_temp
-       ret ; Direkter Sprung zum Bootloader
-hrc_jmp_flasher_inc:
-       inc r_temp
-       sts flashmarker,r_temp
-       rjmp handle_end_sleep
-#endif
-
-hrc_set_matchrom:
-       ldi r_temp,3
-       sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil
-       ldi r_mode,OW_MATCHROM
-       rjmp handle_end
-
-
-
-hrc_set_searchrom:     
-       ldi r_temp,3
-       sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil
-       configZ idtable,r_bytep
-       rjmp h_searchrom_next_bit
-
-hrc_start_read_command: ;Skip rom und Matchrom ok...
-       lds r_temp,srbyte
-       cpi r_temp,1
-       breq hrc_start_read_command1
-       cpi r_temp,2
-       breq hrc_start_read_command2
-       rjmp handle_end_sleep
-       CRCInit1
-hrc_start_read_command1:
-       ldi r_mode,OW_READ_COMMAND1
-       rjmp handle_end
-hrc_start_read_command2:
-       ldi r_mode,OW_READ_COMMAND2
-       rjmp handle_end
-
-
-hrc_set_alarm_search:
-       lds r_temp,alarmflag
-       tst r_temp
-       brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom
-       ; sonst tue nichts
-       rjmp handle_end_sleep
-
-hrc_fw_configinfo1:
-       ldi r_mode,OW_FWCONFIGINFO1
-       ldi r_sendflag,1
-       CRCInit2
-       rjmp h_fwconfiginfo1
-
-hrc_fw_configinfo2:
-       ldi r_mode,OW_FWCONFIGINFO2
-       ldi r_sendflag,1
-       CRCInit2
-       rjmp h_fwconfiginfo2
-
-
-;---------------------------------------------------
-;   MATCH ROM
-;---------------------------------------------------
-       
-
-h_matchrom:
-       lds r_bcount,srbyte
-       sbrs r_bcount,0 ;ueberspringe wenn bit 1 =0 also geraet 1 nich mehr im rennen
-       rjmp h_matchrom_id2
-       configZ owid1,r_bytep
-       ld r_temp2,Z
-       cp r_temp2,r_rwbyte
-       breq h_matchrom_id2
-       cbr r_bcount,1 ; loesche geraet
-       breq h_matchrom_sleep
-h_matchrom_id2:
-       configZ owid2,r_bytep
-       ld r_temp2,Z
-       cp r_temp2,r_rwbyte
-       breq hmr_next_byte
-       cbr r_bcount,2 ; loesche geraet
-       breq h_matchrom_sleep
-
-hmr_next_byte:
-       sts srbyte,r_bcount
-       cpi r_bytep,7
-       breq hrc_start_read_command ;Starten von Read Command
-       rjmp handle_end_inc
-
-h_matchrom_sleep:
-       sts srbyte,r_bcount
-       rjmp handle_end_sleep
-
-
-;---------------------------------------------------
-;   SEARCH ROM
-;---------------------------------------------------
-
-
-h_searchrom_next_bit:  ;Setup next Bit of ID
-       ld r_temp2,Z
-       lds r_temp,srbyte  ;srbyte ist ein zeiger auf die bits fuer ein bit im Table
-h_searchrom_next_bit_l2:
-       cpi r_temp,3
-       breq h_searchrom_next_bit_l1
-       lsr r_temp2
-       lsr r_temp2
-       inc r_temp
-       rjmp h_searchrom_next_bit_l2
-h_searchrom_next_bit_l1:
-       lsr r_temp2
-       rol r_rwbyte  ; negiertes bit in rwbyte
-       lsr r_temp2
-       rol r_rwbyte  ; bit in rwbyte
-       ldi r_sendflag,1
-       ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr 
-       ldi r_mode,OW_SEARCHROMR
-       rjmp handle_end_no_bcount
-
-
-
-h_searchroms:  ; Modus Send zwei bit
-       configZ idtable,r_bytep
-       ld r_temp2,Z+
-       lds r_temp,srbyte
-       cpi r_temp,3
-       breq h_searchroms_idd
-       cpi r_temp,1
-       breq h_searchroms_id1
-       cpi r_temp,2
-       breq h_searchroms_id2
-       rjmp handle_end_sleep ; zur Sicherheit.....
-h_searchroms_idd:
-       andi r_rwbyte,0x80
-       breq h_searchroms_idd_zero
-       ; Master send 1
-       sbrc r_temp2,0 ;springe wenn nicht beide bits 0 (id 1 negiert und id 2 negiert)
-       rjmp handle_end_sleep ;
-       sbrc r_temp2,4  ;id1 set? then skip
-       cbr r_temp,1  ; loesche bit 1 in srbyte
-       sbrc r_temp2,2 ; springe wenn id 2 gesetzt ist
-       cbr r_temp,2 ;  loesche bit 2 in srbyte 
-       sts srbyte,r_temp
-       rjmp h_searchroms_idX_end
-h_searchroms_idd_zero:
-       sbrc r_temp2,1 ;springe wenn nicht beide 1 (id 1  und id 2 )
-       rjmp handle_end_sleep ;beide 1 gehe schlafen
-       sbrs r_temp2,4  ;id1 0? then skip
-       cbr r_temp,1  ; loesche bit 1 in srbyte
-       sbrs r_temp2,2 ; springe wenn id 2  null ist
-       cbr r_temp,2  ; loesche bit 2 in srbyte
-       sts srbyte,r_temp
-       rjmp h_searchroms_idX_end
-h_searchroms_id1:
-       andi r_rwbyte,0x80
-       breq h_searchroms_id1_zero
-       ; Master send 1
-       sbrs r_temp2,5  ;id1 set? then skip
-       rjmp handle_end_sleep ;
-       rjmp h_searchroms_idX_end
-h_searchroms_id1_zero:         
-       sbrs r_temp2,4  ;id1 set? then skip
-       rjmp handle_end_sleep ;
-       rjmp h_searchroms_idX_end
-h_searchroms_id2:
-       andi r_rwbyte,0x80
-       breq h_searchroms_id2_zero
-       ; Master send 1
-       sbrs r_temp2,3  ;id1 set? then skip
-       rjmp handle_end_sleep ;
-       rjmp h_searchroms_idX_end
-h_searchroms_id2_zero:         
-       sbrs r_temp2,2  ;id1 set? then skip
-       rjmp handle_end_sleep ;
-       rjmp h_searchroms_idX_end
-h_searchroms_idX_end:
-       lds r_temp,srbyte
-       tst r_temp
-       brne h_searchroms_idX_end1
-       rjmp handle_end_sleep
-h_searchroms_idX_end1:
-       inc r_bytep
-       cpi r_bytep,64
-       breq h_searchrom_end_ok  ;unterschied nur das letzt bit wird wohl nie vorkommen
-       rjmp h_searchrom_next_bit
-
-h_searchrom_end_ok:
-       clr r_sendflag
-       rjmp hrc_start_read_command
-
-h_searchromr:  ; stelle um auf empfangen
-       clr r_sendflag
-       ldi r_mode,OW_SEARCHROMS
-       ldi r_bcount,0  ;gehe nach einem bit zu SEARCHROMS
-       rjmp handle_end_no_bcount
-
-
-;---------------------------------------------------
-;   FW_CONFIG_INFO
-;---------------------------------------------------
-
-h_fwconfiginfo1:
-       configZ config_info1,r_bytep
-       rjmp h_fwconfiginfo_go
-h_fwconfiginfo2:
-       configZ config_info2,r_bytep
-
-h_fwconfiginfo_go:
-       cpi  r_bytep,16
-       breq h_fwconfiginfo_crc
-#ifdef _CRC8_
-       cpi  r_bytep,17
-       breq h_fwconfiginfo_all
-#elif defined _CRC16_
-       cpi  r_bytep,17
-       breq h_fwconfiginfo_crc2
-       cpi  r_bytep,18
-       breq h_fwconfiginfo_all
-#else
-       cpi  r_bytep,16
-       breq h_fwconfiginfo_all
-#warning No CRC known code implemented
-#endif
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_fwconfiginfo_crc:
-       lds r_rwbyte,crc
-       rjmp handle_end_inc
-h_fwconfiginfo_crc2:
-       lds r_rwbyte,crc+1
-       rjmp handle_end_inc
-h_fwconfiginfo_all:
-       rjmp handle_end_sleep
-
-
-;---------------------------------------------------
-;   CHANGE ROM FUNCTIONS
-;---------------------------------------------------
-
-
-#ifdef _CHANGEABLE_ID_
-
-h_writeid:
-       configZ newid,r_bytep
-       st   Z,r_rwbyte
-       cpi  r_bytep,7
-       breq h_writeid_all
-       rjmp handle_end_inc
-h_writeid_all:
-       rjmp handle_end_sleep
-
-
-hrc_set_readid:
-       ldi r_mode,OW_READ_NEWID
-       ldi r_sendflag,1
-h_readid:
-       cpi  r_bytep,8
-       breq h_readid_all
-       configZ newid,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end_inc
-h_readid_all:
-       clr  r_sendflag
-       rjmp handle_end_sleep
-
-hrc_set_setid:
-       ldi r_mode,OW_SET_NEWID
-       ;ldi r_bytep,1 ;start to write in 2
-       rjmp handle_end_inc ;set r_bytep to 1!!!
-
-h_setid:
-       lds r_bcount,srbyte
-       cpi r_bcount,2
-       breq h_setid2
-h_setid1:
-       configZ owid1,r_bytep
-       rjmp h_setido
-h_setid2:
-       configZ owid2,r_bytep
-h_setido:
-       ld r_temp,Z
-       cp r_rwbyte,r_temp
-       brne h_setid_bad_code_all
-       cpi r_bytep,1
-       breq h_setid_set2
-       cpi r_bytep,5 
-       breq h_setid_set3
-       cpi r_bytep,6
-       breq h_setid_copy_id
-       rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren
-h_setid_set2:
-       ldi r_temp,3
-       add r_bytep,r_temp
-h_setid_set3:
-       inc r_bytep
-       rjmp handle_end
-h_setid_copy_id:
-       ldi r_temp2,lo8(E2END)
-       ldi zh,hi8(E2END)
-       ldi r_temp,7
-       sbrc r_bcount,1
-       ldi r_temp,15
-       sub r_temp2,r_temp
-       ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist
-       ;sbc zh
-       out _SFR_IO_ADDR(EEARH),zh
-       ldi zl,lo8(newid)
-       ldi zh,hi8(newid)
-       ldi r_bytep,0
-h_setid_EEPROM_write:
-       sbic _SFR_IO_ADDR(EECR), EEPE   
-       rjmp h_setid_EEPROM_write
-       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)
-       out _SFR_IO_ADDR(EECR), r_temp
-       ;nur adresse L schreiben H bleibt aus oben genannten grund gleich.
-       out _SFR_IO_ADDR(EEARL),r_temp2
-       ld  r_rwbyte,Z+
-       out _SFR_IO_ADDR(EEDR), r_rwbyte
-       sbi _SFR_IO_ADDR(EECR), EEMPE
-       sbi _SFR_IO_ADDR(EECR), EEPE
-       inc r_bytep
-       inc r_temp2
-       cpi r_bytep,8
-       brne h_setid_EEPROM_write
-       //rcall read_EEPROM_ID1
-       //rcall read_EEPROM_ID2
-       push r_idm1
-       push r_idm2
-       push xl
-       push xh
-       rcall init_idtable
-       pop xh
-       pop xl
-       pop r_idm2
-       pop r_idm1
-h_setid_bad_code_all:
-       rjmp handle_end_sleep
-
-
-
-#endif
-
-
-spause:
-       nop
-       nop
-       nop
-       nop
-       ret
-
-
-.global OWINIT
-OWINIT:
-       
-#ifndef _DIS_FLASH_
-; check for bootloader jumper
-       ;vor allen anderen Registerconfigs
-       push r_temp
-
-       ldi r_temp,(1<<PUD) ;enable pullup 
-       out _SFR_IO_ADDR(MCUCR) ,r_temp
-       sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
-       sbi _SFR_IO_ADDR(PORTA),PINA4 ;internal pullup on PINA4
-       rcall spause
-       sbis _SFR_IO_ADDR(PINA),PINA5
-       rjmp owinit_botest_end  ;PinA5 nicht auf 1
-       sbis _SFR_IO_ADDR(PINA),PINA4
-       rjmp owinit_botest_end ;PinA4 nicht auf 1
-       cbi _SFR_IO_ADDR(PORTA),PINA4 
-       sbi _SFR_IO_ADDR(DDRA),PINA4  ;PINA4 AUSGANG und 0
-       rcall spause
-       sbic _SFR_IO_ADDR(PINA),PINA5 
-       rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden
-       cbi _SFR_IO_ADDR(DDRA),PINA4
-       ldi r_temp,0xC0
-       push r_temp
-       ldi r_temp,0x0E
-       push r_temp
-       ret ; Direkter Sprung zum Bootloader*/
-owinit_botest_end:
-#endif
-       HW_INIT  //Microcontroller specific
-       CHIP_INIT //1-Wire device specific
-       pop r_temp
-init_idtable:
-       push yl
-       push yh
-       push r_temp
-       push r_rwbyte
-       push r_idn1
-       push r_idn2
-#ifdef _CHANGEABLE_ID_
-       rcall read_EEPROM_ID1
-       rcall read_EEPROM_ID2
-#endif
-       ldi r_bytep,8
-       ldi r_temp,0
-       ldi  zl,lo8(idtable)
-    ldi  zh,hi8(idtable)
-       ldi  xl,lo8(owid1)
-       ldi  xh,hi8(owid1)
-       ldi      yl,lo8(owid2)
-       ldi  yh,hi8(owid2)
-owinit_odgen1:
-       ld r_idm1,X+
-       ld r_idm2,Y+
-       mov r_idn1,r_idm1
-       com r_idn1
-       mov r_idn2,r_idm2
-       com r_idn2
-       ldi r_bcount,8
-       mov r_temp,r_idm1
-       and r_temp,r_idm2
-       mov r_temp2,r_idn1
-       and r_temp2,r_idn2
-owinit_odgen2:
-       ldi r_mode,0
-       lsr r_idm1
-       rol r_mode  ;6. Bit id1 
-       lsr r_idn1  
-       rol r_mode ; 5. Bit id1negiert
-       lsr r_idm2
-       rol r_mode  ;;4. Bit id2 
-       lsr r_idn2  
-       rol r_mode  ;3. Bit id2 negiert
-       lsr r_temp 
-       rol r_mode ;zweites bit  id1 und id2
-       lsr r_temp2
-       rol r_mode   ;erstes bit id1 negiert und id2  negiert
-       st  Z+,r_mode
-       dec r_bcount
-       brne owinit_odgen2
-       dec r_bytep
-       brne owinit_odgen1
-       ;copy ids in config bytes
-       ldi  xl,lo8(owid1)
-       ldi  xh,hi8(owid1)
-       ldi      yl,lo8(config_info2+9)
-       ldi  yh,hi8(config_info2+9)
-       ldi r_temp,7
-owinit_cpconfig1:
-       ld r_rwbyte,X+
-       st Y+,r_rwbyte
-       dec r_temp
-       brne owinit_cpconfig1
-       ldi  xl,lo8(owid2)
-       ldi  xh,hi8(owid2)
-       ldi      yl,lo8(config_info1+9)
-       ldi  yh,hi8(config_info1+9)
-       ldi r_temp,7
-owinit_cpconfig2:
-       ld r_rwbyte,X+
-       st Y+,r_rwbyte
-       dec r_temp
-       brne owinit_cpconfig2
-
-
-       ldi r_temp,0
-       sts mode,r_temp
-       sts bcount,r_temp
-       sts alarmflag,r_temp
-       RESETZEROMARKER
-       pop r_idn2
-       pop r_idn1
-       pop r_rwbyte
-       pop r_temp
-       pop yh
-       pop yl
-       
-       ret
-
-.global EXTERN_SLEEP
-EXTERN_SLEEP:
-       cli
-       push r_temp
-       ldi r_temp,0
-       sts mode,r_temp ;SLEEP
-       sts gcontrol,r_temp
-       sts sendflag,r_temp
-       sts bcount,r_temp
-       RESETZEROMARKER
-       pop r_temp
-       sei
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+\r
+.macro cjmp val,addr\r
+       cpi r_rwbyte,\val\r
+       breq \addr\r
+.endm\r
+.macro cljmp val,addr; Weiter sprung, wenn das ziel zu weit entfernt fuer brxx\r
+       cpi r_rwbyte,\val\r
+       brne 1f\r
+       rjmp \addr\r
+1:\r
+.endm\r
+\r
+.macro cset val,mod ;Nur der Mode wird gesetzt. Abkuerzung da oft nur das noch bleibt\r
+       cpi r_rwbyte,\val\r
+       brne 1f\r
+       ldi r_mode,\mod\r
+       rjmp handle_end\r
+1:\r
+.endm\r
+\r
+\r
+\r
+\r
+#define OW_SLEEP 0\r
+#define OW_READ_ROM_COMMAND 1\r
+#define OW_MATCHROM 2\r
+#define OW_SEARCHROMS 3  ;next send two bit\r
+#define OW_SEARCHROMR 4  ; next resive master answer\r
+#define OW_READ_COMMAND1 5\r
+#define OW_READ_COMMAND2 6\r
+#define OW_FWCONFIGINFO1 7\r
+#define OW_FWCONFIGINFO2 8\r
+\r
+.comm idtable,64\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+#define OW_WRITE_NEWID 9\r
+#define OW_READ_NEWID 10\r
+#define OW_SET_NEWID 11\r
+#define OW_FIRST_COMMAND 12\r
+.comm newid,8\r
+       \r
+.macro CHANGE_ID_COMMANDS\r
+       cset 0x75,OW_WRITE_NEWID\r
+       cljmp 0xA7,hrc_set_readid\r
+       cljmp 0x79,hrc_set_setid\r
+.endm\r
+\r
+\r
+#else\r
+#define OW_FIRST_COMMAND 9\r
+#endif\r
+\r
+#ifndef _DIS_FLASH_\r
+; test auf run flasher command 0x88 in h_readcommand\r
+.macro FLASH_COMMANDS\r
+       cpi r_rwbyte,0x88\r
+       brne 1f\r
+       rjmp hrc_jmp_flasher\r
+1: ldi r_temp,0 ;Anderes Kommando flashmarker zuruecksetzen...\r
+       sts flashmarker,r_temp\r
+.endm\r
+#endif\r
+\r
+\r
+.macro FW_CONFIG_INFO1\r
+       cljmp 0x85,hrc_fw_configinfo1\r
+.endm\r
+.macro FW_CONFIG_INFO2\r
+       cljmp 0x85,hrc_fw_configinfo2\r
+.endm\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+; lesen der ID aus dem EEPROM beim Start\r
+read_EEPROM_ID1:  \r
+       ldi r_temp2,lo8(E2END)\r
+       ldi zh,hi8(E2END)\r
+       subi r_temp2,7\r
+       out _SFR_IO_ADDR(EEARH), zh\r
+       ldi r_bytep,0\r
+       ldi  zl,lo8(owid1)       \r
+    ldi  zh,hi8(owid1)\r
+       rjmp read_EEPROM_ID_loop\r
+read_EEPROM_ID2:  \r
+       ldi r_temp2,lo8(E2END)\r
+       ldi zh,hi8(E2END)\r
+       subi r_temp2,15\r
+       out _SFR_IO_ADDR(EEARH), zh\r
+       ldi r_bytep,0\r
+       ldi  zl,lo8(owid2)       \r
+    ldi  zh,hi8(owid2)\r
+read_EEPROM_ID_loop:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE\r
+       rjmp read_EEPROM_ID_loop\r
+       out _SFR_IO_ADDR(EEARL),r_temp2\r
+       sbi _SFR_IO_ADDR(EECR), EERE\r
+       in r_rwbyte,_SFR_IO_ADDR(EEDR)\r
+       cpi r_rwbyte,0xFF\r
+       breq read_EEPROM_ID_end\r
+       st Z+,r_rwbyte\r
+       inc r_bytep\r
+       inc r_temp2\r
+       cpi r_bytep,8\r
+       brne read_EEPROM_ID_loop\r
+read_EEPROM_ID_end:\r
+       ret\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+handle_stable: \r
+               rjmp handle_end_no_bcount // sleep eventuell reset, nichts tun und auf Timeout warten\r
+               rjmp h_readromcommand \r
+               rjmp h_matchrom \r
+               rjmp h_searchroms \r
+               rjmp h_searchromr\r
+               rjmp h_readcommand1 \r
+               rjmp h_readcommand2\r
+               rjmp h_fwconfiginfo1\r
+               rjmp h_fwconfiginfo2\r
+#ifdef _CHANGEABLE_ID_\r
+               rjmp h_writeid\r
+               rjmp h_readid\r
+               rjmp h_setid\r
+#endif\r
+               COMMAND_TABLE\r
+\r
+\r
+\r
+h_readromcommand:\r
+       clr r_bytep\r
+       cjmp 0x55,hrc_set_matchrom\r
+       cjmp 0xF0,hrc_set_searchrom\r
+       cjmp 0xEC,hrc_set_alarm_search\r
+       \r
+       rjmp handle_end_sleep\r
+\r
+#ifndef _DIS_FLASH_\r
+;sprung zum flasher\r
+hrc_jmp_flasher:\r
+       lds r_temp,flashmarker\r
+       cpi r_temp,2\r
+       brne hrc_jmp_flasher_inc\r
+       ldi r_temp,0xC0\r
+       push r_temp\r
+       ldi r_temp,0x0E\r
+       push r_temp\r
+       ret ; Direkter Sprung zum Bootloader\r
+hrc_jmp_flasher_inc:\r
+       inc r_temp\r
+       sts flashmarker,r_temp\r
+       rjmp handle_end_sleep\r
+#endif\r
+\r
+hrc_set_matchrom:\r
+       ldi r_temp,3\r
+       sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil\r
+       ldi r_mode,OW_MATCHROM\r
+       rjmp handle_end\r
+\r
+\r
+\r
+hrc_set_searchrom:     \r
+       ldi r_temp,3\r
+       sts srbyte,r_temp ; Beide geraete nehmen an searchrom teil\r
+       configZ idtable,r_bytep\r
+       rjmp h_searchrom_next_bit\r
+\r
+hrc_start_read_command: ;Skip rom und Matchrom ok...\r
+       lds r_temp,srbyte\r
+       cpi r_temp,1\r
+       breq hrc_start_read_command1\r
+       cpi r_temp,2\r
+       breq hrc_start_read_command2\r
+       rjmp handle_end_sleep\r
+       CRCInit1\r
+hrc_start_read_command1:\r
+       ldi r_mode,OW_READ_COMMAND1\r
+       rjmp handle_end\r
+hrc_start_read_command2:\r
+       ldi r_mode,OW_READ_COMMAND2\r
+       rjmp handle_end\r
+\r
+\r
+hrc_set_alarm_search:\r
+       lds r_temp,alarmflag\r
+       tst r_temp\r
+       brne hrc_set_searchrom ;alarm flag nicht 0 also gehe zu searchrom\r
+       ; sonst tue nichts\r
+       rjmp handle_end_sleep\r
+\r
+hrc_fw_configinfo1:\r
+       ldi r_mode,OW_FWCONFIGINFO1\r
+       ldi r_sendflag,1\r
+       CRCInit2\r
+       rjmp h_fwconfiginfo1\r
+\r
+hrc_fw_configinfo2:\r
+       ldi r_mode,OW_FWCONFIGINFO2\r
+       ldi r_sendflag,1\r
+       CRCInit2\r
+       rjmp h_fwconfiginfo2\r
+\r
+\r
+;---------------------------------------------------\r
+;   MATCH ROM\r
+;---------------------------------------------------\r
+       \r
+\r
+h_matchrom:\r
+       lds r_bcount,srbyte\r
+       sbrs r_bcount,0 ;ueberspringe wenn bit 1 =0 also geraet 1 nich mehr im rennen\r
+       rjmp h_matchrom_id2\r
+       configZ owid1,r_bytep\r
+       ld r_temp2,Z\r
+       cp r_temp2,r_rwbyte\r
+       breq h_matchrom_id2\r
+       cbr r_bcount,1 ; loesche geraet\r
+       breq h_matchrom_sleep\r
+h_matchrom_id2:\r
+       configZ owid2,r_bytep\r
+       ld r_temp2,Z\r
+       cp r_temp2,r_rwbyte\r
+       breq hmr_next_byte\r
+       cbr r_bcount,2 ; loesche geraet\r
+       breq h_matchrom_sleep\r
+\r
+hmr_next_byte:\r
+       sts srbyte,r_bcount\r
+       cpi r_bytep,7\r
+       breq hrc_start_read_command ;Starten von Read Command\r
+       rjmp handle_end_inc\r
+\r
+h_matchrom_sleep:\r
+       sts srbyte,r_bcount\r
+       rjmp handle_end_sleep\r
+\r
+\r
+;---------------------------------------------------\r
+;   SEARCH ROM\r
+;---------------------------------------------------\r
+\r
+\r
+h_searchrom_next_bit:  ;Setup next Bit of ID\r
+       ld r_temp2,Z\r
+       lds r_temp,srbyte  ;srbyte ist ein zeiger auf die bits fuer ein bit im Table\r
+h_searchrom_next_bit_l2:\r
+       cpi r_temp,3\r
+       breq h_searchrom_next_bit_l1\r
+       lsr r_temp2\r
+       lsr r_temp2\r
+       inc r_temp\r
+       rjmp h_searchrom_next_bit_l2\r
+h_searchrom_next_bit_l1:\r
+       lsr r_temp2\r
+       rol r_rwbyte  ; negiertes bit in rwbyte\r
+       lsr r_temp2\r
+       rol r_rwbyte  ; bit in rwbyte\r
+       ldi r_sendflag,1\r
+       ldi r_bcount,0x40 ; zwei bits sensden dann zu Searchromr \r
+       ldi r_mode,OW_SEARCHROMR\r
+       rjmp handle_end_no_bcount\r
+\r
+\r
+\r
+h_searchroms:  ; Modus Send zwei bit\r
+       configZ idtable,r_bytep\r
+       ld r_temp2,Z+\r
+       lds r_temp,srbyte\r
+       cpi r_temp,3\r
+       breq h_searchroms_idd\r
+       cpi r_temp,1\r
+       breq h_searchroms_id1\r
+       cpi r_temp,2\r
+       breq h_searchroms_id2\r
+       rjmp handle_end_sleep ; zur Sicherheit.....\r
+h_searchroms_idd:\r
+       andi r_rwbyte,0x80\r
+       breq h_searchroms_idd_zero\r
+       ; Master send 1\r
+       sbrc r_temp2,0 ;springe wenn nicht beide bits 0 (id 1 negiert und id 2 negiert)\r
+       rjmp handle_end_sleep ;\r
+       sbrc r_temp2,4  ;id1 set? then skip\r
+       cbr r_temp,1  ; loesche bit 1 in srbyte\r
+       sbrc r_temp2,2 ; springe wenn id 2 gesetzt ist\r
+       cbr r_temp,2 ;  loesche bit 2 in srbyte \r
+       sts srbyte,r_temp\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_idd_zero:\r
+       sbrc r_temp2,1 ;springe wenn nicht beide 1 (id 1  und id 2 )\r
+       rjmp handle_end_sleep ;beide 1 gehe schlafen\r
+       sbrs r_temp2,4  ;id1 0? then skip\r
+       cbr r_temp,1  ; loesche bit 1 in srbyte\r
+       sbrs r_temp2,2 ; springe wenn id 2  null ist\r
+       cbr r_temp,2  ; loesche bit 2 in srbyte\r
+       sts srbyte,r_temp\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_id1:\r
+       andi r_rwbyte,0x80\r
+       breq h_searchroms_id1_zero\r
+       ; Master send 1\r
+       sbrs r_temp2,5  ;id1 set? then skip\r
+       rjmp handle_end_sleep ;\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_id1_zero:         \r
+       sbrs r_temp2,4  ;id1 set? then skip\r
+       rjmp handle_end_sleep ;\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_id2:\r
+       andi r_rwbyte,0x80\r
+       breq h_searchroms_id2_zero\r
+       ; Master send 1\r
+       sbrs r_temp2,3  ;id1 set? then skip\r
+       rjmp handle_end_sleep ;\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_id2_zero:         \r
+       sbrs r_temp2,2  ;id1 set? then skip\r
+       rjmp handle_end_sleep ;\r
+       rjmp h_searchroms_idX_end\r
+h_searchroms_idX_end:\r
+       lds r_temp,srbyte\r
+       tst r_temp\r
+       brne h_searchroms_idX_end1\r
+       rjmp handle_end_sleep\r
+h_searchroms_idX_end1:\r
+       inc r_bytep\r
+       cpi r_bytep,64\r
+       breq h_searchrom_end_ok  ;unterschied nur das letzt bit wird wohl nie vorkommen\r
+       rjmp h_searchrom_next_bit\r
+\r
+h_searchrom_end_ok:\r
+       clr r_sendflag\r
+       rjmp hrc_start_read_command\r
+\r
+h_searchromr:  ; stelle um auf empfangen\r
+       clr r_sendflag\r
+       ldi r_mode,OW_SEARCHROMS\r
+       ldi r_bcount,0  ;gehe nach einem bit zu SEARCHROMS\r
+       rjmp handle_end_no_bcount\r
+\r
+\r
+;---------------------------------------------------\r
+;   FW_CONFIG_INFO\r
+;---------------------------------------------------\r
+\r
+h_fwconfiginfo1:\r
+       configZ config_info1,r_bytep\r
+       rjmp h_fwconfiginfo_go\r
+h_fwconfiginfo2:\r
+       configZ config_info2,r_bytep\r
+\r
+h_fwconfiginfo_go:\r
+       cpi  r_bytep,16\r
+       breq h_fwconfiginfo_crc\r
+#ifdef _CRC8_\r
+       cpi  r_bytep,17\r
+       breq h_fwconfiginfo_all\r
+#elif defined _CRC16_\r
+       cpi  r_bytep,17\r
+       breq h_fwconfiginfo_crc2\r
+       cpi  r_bytep,18\r
+       breq h_fwconfiginfo_all\r
+#else\r
+       cpi  r_bytep,16\r
+       breq h_fwconfiginfo_all\r
+#warning No CRC known code implemented\r
+#endif\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_crc:\r
+       lds r_rwbyte,crc\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_crc2:\r
+       lds r_rwbyte,crc+1\r
+       rjmp handle_end_inc\r
+h_fwconfiginfo_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+;---------------------------------------------------\r
+;   CHANGE ROM FUNCTIONS\r
+;---------------------------------------------------\r
+\r
+\r
+#ifdef _CHANGEABLE_ID_\r
+\r
+h_writeid:\r
+       configZ newid,r_bytep\r
+       st   Z,r_rwbyte\r
+       cpi  r_bytep,7\r
+       breq h_writeid_all\r
+       rjmp handle_end_inc\r
+h_writeid_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+hrc_set_readid:\r
+       ldi r_mode,OW_READ_NEWID\r
+       ldi r_sendflag,1\r
+h_readid:\r
+       cpi  r_bytep,8\r
+       breq h_readid_all\r
+       configZ newid,r_bytep\r
+       ld   r_rwbyte,Z\r
+       rjmp handle_end_inc\r
+h_readid_all:\r
+       clr  r_sendflag\r
+       rjmp handle_end_sleep\r
+\r
+hrc_set_setid:\r
+       ldi r_mode,OW_SET_NEWID\r
+       ;ldi r_bytep,1 ;start to write in 2\r
+       rjmp handle_end_inc ;set r_bytep to 1!!!\r
+\r
+h_setid:\r
+       lds r_bcount,srbyte\r
+       cpi r_bcount,2\r
+       breq h_setid2\r
+h_setid1:\r
+       configZ owid1,r_bytep\r
+       rjmp h_setido\r
+h_setid2:\r
+       configZ owid2,r_bytep\r
+h_setido:\r
+       ld r_temp,Z\r
+       cp r_rwbyte,r_temp\r
+       brne h_setid_bad_code_all\r
+       cpi r_bytep,1\r
+       breq h_setid_set2\r
+       cpi r_bytep,5 \r
+       breq h_setid_set3\r
+       cpi r_bytep,6\r
+       breq h_setid_copy_id\r
+       rjmp h_setid_bad_code_all ;sollte eigentlich nicht passieren\r
+h_setid_set2:\r
+       ldi r_temp,3\r
+       add r_bytep,r_temp\r
+h_setid_set3:\r
+       inc r_bytep\r
+       rjmp handle_end\r
+h_setid_copy_id:\r
+       ldi r_temp2,lo8(E2END)\r
+       ldi zh,hi8(E2END)\r
+       ldi r_temp,7\r
+       sbrc r_bcount,1\r
+       ldi r_temp,15\r
+       sub r_temp2,r_temp\r
+       ;ldi r_temp,0 ;kommt nicht vor das ein E2ROM genau n*256+(0 bis 7) byte gross ist\r
+       ;sbc zh\r
+       out _SFR_IO_ADDR(EEARH),zh\r
+       ldi zl,lo8(newid)\r
+       ldi zh,hi8(newid)\r
+       ldi r_bytep,0\r
+h_setid_EEPROM_write:\r
+       sbic _SFR_IO_ADDR(EECR), EEPE   \r
+       rjmp h_setid_EEPROM_write\r
+       ldi r_temp, (0<<EEPM1)|(0<<EEPM0)\r
+       out _SFR_IO_ADDR(EECR), r_temp\r
+       ;nur adresse L schreiben H bleibt aus oben genannten grund gleich.\r
+       out _SFR_IO_ADDR(EEARL),r_temp2\r
+       ld  r_rwbyte,Z+\r
+       out _SFR_IO_ADDR(EEDR), r_rwbyte\r
+       sbi _SFR_IO_ADDR(EECR), EEMPE\r
+       sbi _SFR_IO_ADDR(EECR), EEPE\r
+       inc r_bytep\r
+       inc r_temp2\r
+       cpi r_bytep,8\r
+       brne h_setid_EEPROM_write\r
+       //rcall read_EEPROM_ID1\r
+       //rcall read_EEPROM_ID2\r
+       push r_idm1\r
+       push r_idm2\r
+       push xl\r
+       push xh\r
+       rcall init_idtable\r
+       pop xh\r
+       pop xl\r
+       pop r_idm2\r
+       pop r_idm1\r
+h_setid_bad_code_all:\r
+       rjmp handle_end_sleep\r
+\r
+\r
+\r
+#endif\r
+\r
+\r
+spause:\r
+       nop\r
+       nop\r
+       nop\r
+       nop\r
+       ret\r
+\r
+\r
+.global OWINIT\r
+OWINIT:\r
+       \r
+#ifndef _DIS_FLASH_\r
+; check for bootloader jumper\r
+       ;vor allen anderen Registerconfigs\r
+       push r_temp\r
+\r
+       ldi r_temp,(1<<PUD) ;enable pullup \r
+       out _SFR_IO_ADDR(MCUCR) ,r_temp\r
+       sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5\r
+       sbi _SFR_IO_ADDR(PORTA),PINA4 ;internal pullup on PINA4\r
+       rcall spause\r
+       sbis _SFR_IO_ADDR(PINA),PINA5\r
+       rjmp owinit_botest_end  ;PinA5 nicht auf 1\r
+       sbis _SFR_IO_ADDR(PINA),PINA4\r
+       rjmp owinit_botest_end ;PinA4 nicht auf 1\r
+       cbi _SFR_IO_ADDR(PORTA),PINA4 \r
+       sbi _SFR_IO_ADDR(DDRA),PINA4  ;PINA4 AUSGANG und 0\r
+       rcall spause\r
+       sbic _SFR_IO_ADDR(PINA),PINA5 \r
+       rjmp owinit_botest_end ;PINA5 nicht 0.... nicht verbunden\r
+       cbi _SFR_IO_ADDR(DDRA),PINA4\r
+       ldi r_temp,0xC0\r
+       push r_temp\r
+       ldi r_temp,0x0E\r
+       push r_temp\r
+       ret ; Direkter Sprung zum Bootloader*/\r
+owinit_botest_end:\r
+#endif\r
+       HW_INIT  //Microcontroller specific\r
+       CHIP_INIT //1-Wire device specific\r
+       pop r_temp\r
+init_idtable:\r
+       push yl\r
+       push yh\r
+       push r_temp\r
+       push r_rwbyte\r
+       push r_idn1\r
+       push r_idn2\r
+#ifdef _CHANGEABLE_ID_\r
+       rcall read_EEPROM_ID1\r
+       rcall read_EEPROM_ID2\r
+#endif\r
+       ldi r_bytep,8\r
+       ldi r_temp,0\r
+       ldi  zl,lo8(idtable)\r
+    ldi  zh,hi8(idtable)\r
+       ldi  xl,lo8(owid1)\r
+       ldi  xh,hi8(owid1)\r
+       ldi      yl,lo8(owid2)\r
+       ldi  yh,hi8(owid2)\r
+owinit_odgen1:\r
+       ld r_idm1,X+\r
+       ld r_idm2,Y+\r
+       mov r_idn1,r_idm1\r
+       com r_idn1\r
+       mov r_idn2,r_idm2\r
+       com r_idn2\r
+       ldi r_bcount,8\r
+       mov r_temp,r_idm1\r
+       and r_temp,r_idm2\r
+       mov r_temp2,r_idn1\r
+       and r_temp2,r_idn2\r
+owinit_odgen2:\r
+       ldi r_mode,0\r
+       lsr r_idm1\r
+       rol r_mode  ;6. Bit id1 \r
+       lsr r_idn1  \r
+       rol r_mode ; 5. Bit id1negiert\r
+       lsr r_idm2\r
+       rol r_mode  ;;4. Bit id2 \r
+       lsr r_idn2  \r
+       rol r_mode  ;3. Bit id2 negiert\r
+       lsr r_temp \r
+       rol r_mode ;zweites bit  id1 und id2\r
+       lsr r_temp2\r
+       rol r_mode   ;erstes bit id1 negiert und id2  negiert\r
+       st  Z+,r_mode\r
+       dec r_bcount\r
+       brne owinit_odgen2\r
+       dec r_bytep\r
+       brne owinit_odgen1\r
+       ;copy ids in config bytes\r
+       ldi  xl,lo8(owid1)\r
+       ldi  xh,hi8(owid1)\r
+       ldi      yl,lo8(config_info2+9)\r
+       ldi  yh,hi8(config_info2+9)\r
+       ldi r_temp,7\r
+owinit_cpconfig1:\r
+       ld r_rwbyte,X+\r
+       st Y+,r_rwbyte\r
+       dec r_temp\r
+       brne owinit_cpconfig1\r
+       ldi  xl,lo8(owid2)\r
+       ldi  xh,hi8(owid2)\r
+       ldi      yl,lo8(config_info1+9)\r
+       ldi  yh,hi8(config_info1+9)\r
+       ldi r_temp,7\r
+owinit_cpconfig2:\r
+       ld r_rwbyte,X+\r
+       st Y+,r_rwbyte\r
+       dec r_temp\r
+       brne owinit_cpconfig2\r
+\r
+\r
+       ldi r_temp,0\r
+       sts mode,r_temp\r
+       sts bcount,r_temp\r
+       sts alarmflag,r_temp\r
+       RESETZEROMARKER\r
+       pop r_idn2\r
+       pop r_idn1\r
+       pop r_rwbyte\r
+       pop r_temp\r
+       pop yh\r
+       pop yl\r
+       \r
+       ret\r
+\r
+.global EXTERN_SLEEP\r
+EXTERN_SLEEP:\r
+       cli\r
+       push r_temp\r
+       ldi r_temp,0\r
+       sts mode,r_temp ;SLEEP\r
+       sts gcontrol,r_temp\r
+       sts sendflag,r_temp\r
+       sts bcount,r_temp\r
+       RESETZEROMARKER\r
+       pop r_temp\r
+       sei\r
        ret
\ No newline at end of file
index 98efef2..4ddead1 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-#define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
-#define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
-#define OW_PINN PORTB2
-#define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register
-#define TCNT_REG _SFR_IO_ADDR(TCNT0)
-
-
-#define DB_PORT _SFR_IO_ADDR(PORTB) //DEBUG
-#define DB_PIN _SFR_IO_ADDR(PINB) //DEBUG
-#define DB_DDR _SFR_IO_ADDR(DDRB) //DEBUG
-#define DB_PINN PORTB1
-
-#define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),3
-#define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),3
-#define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),3
-
-#ifdef _DB_
-#define sdb sbi _SFR_IO_ADDR(PORTB),DB_PINN
-#define cdb cbi _SFR_IO_ADDR(PORTB),DB_PINN
-#else
-#define sdb
-#define cdb
-#endif
-
-#define TIMER_INTERRUPT TIM0_OVF_vect
-#define PIN_INTERRIPT EXT_INT0_vect
-
-
-//#define OWT_MIN_RESET 160 
-//#define OWT_RESET2 40
-//#define OWT_RESET_PRESENT 15
-//#define OWT_PRESENT 50
-//#define OWT_WRITE 18
-//#define OWT_READ 4
-
-#define OWT_MIN_RESET 180
-#define OWT_RESET2 80
-#define OWT_RESET_PRESENT 30
-#define OWT_PRESENT 130
-#define OWT_WRITE 35
-#define OWT_READ 12
-#define OWT_ZP_WAIT_LOW_TO 60  ; Zeit fuer die Maximale Lowzeit bei der Zerro Polling pruefung. Ist die Leitung laenger low, ist es vieleicht ein Reset 
-#define OWT_ZP_WAIT_HIGH_TO 90 ; Zeit fuer die Maximale Hight zeit bis zu einem Low Impuls vom Master. Nach laengeren Pausen wird nicht mehr gepollt sondern der Interrup vererndet.
-
-
-.macro CLEAR_TOV_FLAG
-       ldi r_temp,1
-       out _SFR_IO_ADDR(TIFR0),r_temp
-.endm
-
-.macro JMP_NO_TOV
-       in r_temp, _SFR_IO_ADDR(TIFR0)
-       sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter
-.endm
-
-.macro CLEAR_INTERRUPT_FLAG 
-       ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix
-       out _SFR_IO_ADDR(GIFR),r_temp
-.endm
-
-.macro EN_TIM_INT
-       in r_temp,_SFR_IO_ADDR(TIMSK0)
-       sbr r_temp,(1<<TOIE0)
-       out _SFR_IO_ADDR(TIMSK0),r_temp
-       ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix
-       out _SFR_IO_ADDR(TIFR0),r_temp
-.endm
-
-.macro DIS_TIM_INT
-       in r_temp,_SFR_IO_ADDR(TIMSK0)
-       cbr r_temp,(1<<TOIE0)
-       out _SFR_IO_ADDR(TIMSK0),r_temp
-.endm
-
-.macro SET_FALLING_RESET_SLEEP
-       in r_temp,_SFR_IO_ADDR(MCUCR)
-       ori r_temp,(1<<ISC01)
-       andi r_temp,~(1<<SM1)
-       out     _SFR_IO_ADDR(MCUCR),r_temp
-.endm
-
-.macro HW_INIT  ;r_temp is pushed other Registers should be saved
-       ;set clock to 8 MHz
-       ldi r_temp,0x80;
-       out _SFR_IO_ADDR(CLKPR),r_temp
-       //ldi r_temp,(1<<CLKPS0)
-       ldi r_temp,0
-       out _SFR_IO_ADDR(CLKPR),r_temp
-       ;Disable Timer int
-       ldi r_temp,0
-       out _SFR_IO_ADDR(TIMSK0),r_temp ;; is default
-       ;Enable Pin int
-       ldi r_temp,(1<<INT0)
-       out _SFR_IO_ADDR(GIMSK),r_temp
-       ;Set Timerclock to Clock / 8 (2us bei 4MHz) bzw 1us bei 8 MHz
-       ldi r_temp,(1<<CS01)
-       out _SFR_IO_ADDR(TCCR0B),r_temp
-       ;OWPin as input
-       cbi OW_DDR,OW_PINN ;; is default.... 
-       cbi OW_PORT,OW_PINN ;; vereinfachung im Hauptprogram (PORTB=0xFF) wegen pullup
-       ;set falling edge
-       ldi r_temp,(1<<ISC01)
-       out _SFR_IO_ADDR(MCUCR),r_temp
-#ifdef _DB_
-       sbi DB_DDR,DB_PINN
-#endif
-.endm
-
-
-
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+#define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port\r
+#define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number\r
+#define OW_PINN PORTB2\r
+#define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register\r
+#define TCNT_REG _SFR_IO_ADDR(TCNT0)\r
+\r
+\r
+#define DB_PORT _SFR_IO_ADDR(PORTB) //DEBUG\r
+#define DB_PIN _SFR_IO_ADDR(PINB) //DEBUG\r
+#define DB_DDR _SFR_IO_ADDR(DDRB) //DEBUG\r
+#define DB_PINN PORTB1\r
+\r
+#define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),3\r
+#define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),3\r
+#define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),3\r
+\r
+#ifdef _DB_\r
+#define sdb sbi _SFR_IO_ADDR(PORTB),DB_PINN\r
+#define cdb cbi _SFR_IO_ADDR(PORTB),DB_PINN\r
+#else\r
+#define sdb\r
+#define cdb\r
+#endif\r
+\r
+#define TIMER_INTERRUPT TIM0_OVF_vect\r
+#define PIN_INTERRIPT EXT_INT0_vect\r
+\r
+\r
+//#define OWT_MIN_RESET 160 \r
+//#define OWT_RESET2 40\r
+//#define OWT_RESET_PRESENT 15\r
+//#define OWT_PRESENT 50\r
+//#define OWT_WRITE 18\r
+//#define OWT_READ 4\r
+\r
+#define OWT_MIN_RESET 180\r
+#define OWT_RESET2 80\r
+#define OWT_RESET_PRESENT 30\r
+#define OWT_PRESENT 130\r
+#define OWT_WRITE 35\r
+#define OWT_READ 12\r
+#define OWT_ZP_WAIT_LOW_TO 60  ; Zeit fuer die Maximale Lowzeit bei der Zerro Polling pruefung. Ist die Leitung laenger low, ist es vieleicht ein Reset \r
+#define OWT_ZP_WAIT_HIGH_TO 90 ; Zeit fuer die Maximale Hight zeit bis zu einem Low Impuls vom Master. Nach laengeren Pausen wird nicht mehr gepollt sondern der Interrup vererndet.\r
+\r
+\r
+.macro CLEAR_TOV_FLAG\r
+       ldi r_temp,1\r
+       out _SFR_IO_ADDR(TIFR0),r_temp\r
+.endm\r
+\r
+.macro JMP_NO_TOV\r
+       in r_temp, _SFR_IO_ADDR(TIFR0)\r
+       sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter\r
+.endm\r
+\r
+.macro CLEAR_INTERRUPT_FLAG \r
+       ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix\r
+       out _SFR_IO_ADDR(GIFR),r_temp\r
+.endm\r
+\r
+.macro EN_TIM_INT\r
+       in r_temp,_SFR_IO_ADDR(TIMSK0)\r
+       sbr r_temp,(1<<TOIE0)\r
+       out _SFR_IO_ADDR(TIMSK0),r_temp\r
+       ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix\r
+       out _SFR_IO_ADDR(TIFR0),r_temp\r
+.endm\r
+\r
+.macro DIS_TIM_INT\r
+       in r_temp,_SFR_IO_ADDR(TIMSK0)\r
+       cbr r_temp,(1<<TOIE0)\r
+       out _SFR_IO_ADDR(TIMSK0),r_temp\r
+.endm\r
+\r
+.macro SET_FALLING_RESET_SLEEP\r
+       in r_temp,_SFR_IO_ADDR(MCUCR)\r
+       ori r_temp,(1<<ISC01)\r
+       andi r_temp,~(1<<SM1)\r
+       out     _SFR_IO_ADDR(MCUCR),r_temp\r
+.endm\r
+\r
+.macro HW_INIT  ;r_temp is pushed other Registers should be saved\r
+       ;set clock to 8 MHz\r
+       ldi r_temp,0x80;\r
+       out _SFR_IO_ADDR(CLKPR),r_temp\r
+       //ldi r_temp,(1<<CLKPS0)\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(CLKPR),r_temp\r
+       ;Disable Timer int\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(TIMSK0),r_temp ;; is default\r
+       ;Enable Pin int\r
+       ldi r_temp,(1<<INT0)\r
+       out _SFR_IO_ADDR(GIMSK),r_temp\r
+       ;Set Timerclock to Clock / 8 (2us bei 4MHz) bzw 1us bei 8 MHz\r
+       ldi r_temp,(1<<CS01)\r
+       out _SFR_IO_ADDR(TCCR0B),r_temp\r
+       ;OWPin as input\r
+       cbi OW_DDR,OW_PINN ;; is default.... \r
+       cbi OW_PORT,OW_PINN ;; vereinfachung im Hauptprogram (PORTB=0xFF) wegen pullup\r
+       ;set falling edge\r
+       ldi r_temp,(1<<ISC01)\r
+       out _SFR_IO_ADDR(MCUCR),r_temp\r
+#ifdef _DB_\r
+       sbi DB_DDR,DB_PINN\r
+#endif\r
+.endm\r
+\r
+\r
+\r
index 159d151..a9cabec 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-//#define __4M__
-
-#define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
-#define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
-#define OW_PINN PORTB2
-#define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register
-#define TCNT_REG _SFR_IO_ADDR(TCNT0)
-
-#define DB_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port
-#define DB_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number
-#define DB_PINN PORTB1
-
-#define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),5
-#define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),5
-#define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),5
-
-;#define sdb sbi _SFR_IO_ADDR(PORTB),1
-;#define cdb cbi _SFR_IO_ADDR(PORTB),1
-
-#define TIMER_INTERRUPT TIM0_OVF_vect
-#define PIN_INTERRIPT INT0_vect
-
-#ifdef __4M__
-
-#define OWT_MIN_RESET 70 
-#define OWT_RESET2 40
-#define OWT_RESET_PRESENT 15
-#define OWT_PRESENT 50
-#define OWT_WRITE 18
-#define OWT_READ 5
-
-#else
-
-#define OWT_MIN_RESET 140
-#define OWT_RESET2 80
-#define OWT_RESET_PRESENT 30
-#define OWT_PRESENT 130
-#define OWT_WRITE 35
-#define OWT_READ 12
-
-#endif
-
-
-.macro CLEAR_TOV_FLAG
-       ldi r_temp,(1<<TOV0)
-       out _SFR_IO_ADDR(TIFR),r_temp
-.endm
-
-.macro JMP_NO_TOV
-       in r_temp, _SFR_IO_ADDR(TIFR)
-       sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter
-.endm
-
-.macro CLEAR_INTERRUPT_FLAG 
-       ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix
-       out _SFR_IO_ADDR(GIFR),r_temp
-.endm
-
-.macro EN_TIM_INT
-       in r_temp,_SFR_IO_ADDR(TIMSK)
-       sbr r_temp,(1<<TOIE0)
-       out _SFR_IO_ADDR(TIMSK),r_temp
-       ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix
-       out _SFR_IO_ADDR(TIFR),r_temp
-.endm
-
-.macro DIS_TIM_INT
-       in r_temp,_SFR_IO_ADDR(TIMSK)
-       cbr r_temp,(1<<TOIE0)
-       out _SFR_IO_ADDR(TIMSK),r_temp
-.endm
-
-
-.macro SET_FALLING
-       in r_temp,_SFR_IO_ADDR(MCUCR)
-       ori r_temp,(1<<ISC01)
-       out     _SFR_IO_ADDR(MCUCR),r_temp
-.endm
-
-
-.macro SET_FALLING_RESET_SLEEP
-       in r_temp,_SFR_IO_ADDR(MCUCR)
-       ori r_temp,(1<<ISC01)
-       andi r_temp,~(1<<SM1)
-       out     _SFR_IO_ADDR(MCUCR),r_temp
-.endm
-
-
-.macro HW_INIT
-       ;set clock to 8 MHz
-       ldi r_temp,0x80;
-       out _SFR_IO_ADDR(CLKPR),r_temp
-#ifdef __4M__
-       ldi r_temp,(1<<CLKPS0)
-#else
-       ldi r_temp,0
-#endif
-       out _SFR_IO_ADDR(CLKPR),r_temp
-       ;Disable Timer int
-       ldi r_temp,0
-       out _SFR_IO_ADDR(TIMSK),r_temp ;; is default
-       ;Enable Pin int
-       ldi r_temp,(1<<INT0)
-       out _SFR_IO_ADDR(GIMSK),r_temp
-       ;Set Timerclock to Clock / 8 (2us)
-       ldi r_temp,(1<<CS01)
-       out _SFR_IO_ADDR(TCCR0B),r_temp
-       ;OWPin as input
-       cbi OW_DDR,OW_PINN ;; is default.... 
-       ;set falling edge
-       ldi r_temp,(1<<ISC01)
-       out _SFR_IO_ADDR(MCUCR),r_temp
-.endm
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+//#define __4M__\r
+\r
+#define OW_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port\r
+#define OW_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number\r
+#define OW_PINN PORTB2\r
+#define OW_DDR _SFR_IO_ADDR(DDRB)  //pin direction register\r
+#define TCNT_REG _SFR_IO_ADDR(TCNT0)\r
+\r
+#define DB_PORT _SFR_IO_ADDR(PORTB) //1 Wire Port\r
+#define DB_PIN _SFR_IO_ADDR(PINB) //1 Wire Pin as number\r
+#define DB_PINN PORTB1\r
+\r
+#define SETZEROMARKER sbi _SFR_IO_ADDR(DDRB),5\r
+#define RESETZEROMARKER cbi _SFR_IO_ADDR(DDRB),5\r
+#define TESTZEROMARKER sbic _SFR_IO_ADDR(DDRB),5\r
+\r
+;#define sdb sbi _SFR_IO_ADDR(PORTB),1\r
+;#define cdb cbi _SFR_IO_ADDR(PORTB),1\r
+\r
+#define TIMER_INTERRUPT TIM0_OVF_vect\r
+#define PIN_INTERRIPT INT0_vect\r
+\r
+#ifdef __4M__\r
+\r
+#define OWT_MIN_RESET 70 \r
+#define OWT_RESET2 40\r
+#define OWT_RESET_PRESENT 15\r
+#define OWT_PRESENT 50\r
+#define OWT_WRITE 18\r
+#define OWT_READ 5\r
+\r
+#else\r
+\r
+#define OWT_MIN_RESET 140\r
+#define OWT_RESET2 80\r
+#define OWT_RESET_PRESENT 30\r
+#define OWT_PRESENT 130\r
+#define OWT_WRITE 35\r
+#define OWT_READ 12\r
+\r
+#endif\r
+\r
+\r
+.macro CLEAR_TOV_FLAG\r
+       ldi r_temp,(1<<TOV0)\r
+       out _SFR_IO_ADDR(TIFR),r_temp\r
+.endm\r
+\r
+.macro JMP_NO_TOV\r
+       in r_temp, _SFR_IO_ADDR(TIFR)\r
+       sbrc r_temp,TOV0 ; wenn ueberlauf gleiich weiter\r
+.endm\r
+\r
+.macro CLEAR_INTERRUPT_FLAG \r
+       ldi r_temp,(1<<INTF0);inerrupt flags durch 1 loeschen..... 0 macht nix\r
+       out _SFR_IO_ADDR(GIFR),r_temp\r
+.endm\r
+\r
+.macro EN_TIM_INT\r
+       in r_temp,_SFR_IO_ADDR(TIMSK)\r
+       sbr r_temp,(1<<TOIE0)\r
+       out _SFR_IO_ADDR(TIMSK),r_temp\r
+       ldi r_temp,(1<<TOV0) ;inerrupt flags durch 1 loeschen..... 0 macht nix\r
+       out _SFR_IO_ADDR(TIFR),r_temp\r
+.endm\r
+\r
+.macro DIS_TIM_INT\r
+       in r_temp,_SFR_IO_ADDR(TIMSK)\r
+       cbr r_temp,(1<<TOIE0)\r
+       out _SFR_IO_ADDR(TIMSK),r_temp\r
+.endm\r
+\r
+\r
+.macro SET_FALLING\r
+       in r_temp,_SFR_IO_ADDR(MCUCR)\r
+       ori r_temp,(1<<ISC01)\r
+       out     _SFR_IO_ADDR(MCUCR),r_temp\r
+.endm\r
+\r
+\r
+.macro SET_FALLING_RESET_SLEEP\r
+       in r_temp,_SFR_IO_ADDR(MCUCR)\r
+       ori r_temp,(1<<ISC01)\r
+       andi r_temp,~(1<<SM1)\r
+       out     _SFR_IO_ADDR(MCUCR),r_temp\r
+.endm\r
+\r
+\r
+.macro HW_INIT\r
+       ;set clock to 8 MHz\r
+       ldi r_temp,0x80;\r
+       out _SFR_IO_ADDR(CLKPR),r_temp\r
+#ifdef __4M__\r
+       ldi r_temp,(1<<CLKPS0)\r
+#else\r
+       ldi r_temp,0\r
+#endif\r
+       out _SFR_IO_ADDR(CLKPR),r_temp\r
+       ;Disable Timer int\r
+       ldi r_temp,0\r
+       out _SFR_IO_ADDR(TIMSK),r_temp ;; is default\r
+       ;Enable Pin int\r
+       ldi r_temp,(1<<INT0)\r
+       out _SFR_IO_ADDR(GIMSK),r_temp\r
+       ;Set Timerclock to Clock / 8 (2us)\r
+       ldi r_temp,(1<<CS01)\r
+       out _SFR_IO_ADDR(TCCR0B),r_temp\r
+       ;OWPin as input\r
+       cbi OW_DDR,OW_PINN ;; is default.... \r
+       ;set falling edge\r
+       ldi r_temp,(1<<ISC01)\r
+       out _SFR_IO_ADDR(MCUCR),r_temp\r
+.endm\r
index a23009e..1ad0afc 100644 (file)
@@ -1,86 +1,86 @@
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved. 
-// 
-// Redistribution and use in source and binary forms, with or without 
-// modification, are permitted provided that the following conditions are 
-// met: 
-// 
-//  * Redistributions of source code must retain the above copyright 
-//    notice, this list of conditions and the following disclaimer. 
-//  * Redistributions in binary form must reproduce the above copyright 
-//    notice, this list of conditions and the following disclaimer in the 
-//    documentation and/or other materials provided with the 
-//    distribution. 
-//  * All advertising materials mentioning features or use of this 
-//    software must display the following acknowledgement: This product 
-//    includes software developed by tm3d.de and its contributors. 
-//  * Neither the name of tm3d.de nor the names of its contributors may 
-//    be used to endorse or promote products derived from this software 
-//    without specific prior written permission. 
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-
-
-.global TIMER_INTERRUPT
-TIMER_INTERRUPT:
-       sdb
-       push r_temp
-       in r_temp,_SFR_IO_ADDR(SREG)  
-       push r_temp
-       cdb
-       sbic OW_PIN,OW_PINN  ; abkuerzung wenn Leitung schon h
-       rjmp tint_end ; Leitung 1 kein Reset
-       ldi r_temp,0  
-       out TCNT_REG,r_temp
-       CLEAR_TOV_FLAG
-tint_loop_rend:
-       sbis OW_PIN,OW_PINN ;warten bis leitung wieder h 
-       rjmp tint_loop_rend
-       JMP_NO_TOV ;ueberspringe wenn kein ueberlauf
-       rjmp tint_overrun
-       in r_temp,TCNT_REG ;schauen ob es lange genug gedauert hat fuer reset
-       cpi r_temp,OWT_RESET2 
-       brlo tint_end
-tint_overrun:
-       ldi r_temp,0
-       out TCNT_REG,r_temp
-       ;zwischen Reset und Presets
-tint_loop_res_pres:
-       in r_temp,TCNT_REG
-       cpi r_temp,OWT_RESET_PRESENT
-       brlo tint_loop_res_pres ;Warten zwischen reset und presets
-       sbi OW_DDR,OW_PINN  ;presents impuls
-       ;reset impuls
-tint_loop_pres:
-       in r_temp,TCNT_REG
-       cpi r_temp,OWT_PRESENT
-       brlo tint_loop_pres
-       cbi OW_DDR,OW_PINN  
-       ldi r_temp,OW_READ_ROM_COMMAND ; Initialisieren von Rom command
-       sts mode,r_temp
-       ldi r_temp,1
-       sts reset_indicator,r_temp
-       sts bcount,r_temp ;bit eins
-       clr r_temp
-       sts sendflag,r_temp ;empfangen (rom_command)
-       ;sts wzero,r_temp ;alles 0 
-       RESETZEROMARKER
-       CLEAR_INTERRUPT_FLAG
-tint_end:
-       ;CLEAR_INTERRUPT_FLAG
-       DIS_TIM_INT
-       pop r_temp
-       out _SFR_IO_ADDR(SREG),r_temp
-       pop r_temp
-       reti
-;;;
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved. \r
+// \r
+// Redistribution and use in source and binary forms, with or without \r
+// modification, are permitted provided that the following conditions are \r
+// met: \r
+// \r
+//  * Redistributions of source code must retain the above copyright \r
+//    notice, this list of conditions and the following disclaimer. \r
+//  * Redistributions in binary form must reproduce the above copyright \r
+//    notice, this list of conditions and the following disclaimer in the \r
+//    documentation and/or other materials provided with the \r
+//    distribution. \r
+//  * All advertising materials mentioning features or use of this \r
+//    software must display the following acknowledgement: This product \r
+//    includes software developed by tm3d.de and its contributors. \r
+//  * Neither the name of tm3d.de nor the names of its contributors may \r
+//    be used to endorse or promote products derived from this software \r
+//    without specific prior written permission. \r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+.global TIMER_INTERRUPT\r
+TIMER_INTERRUPT:\r
+       sdb\r
+       push r_temp\r
+       in r_temp,_SFR_IO_ADDR(SREG)  \r
+       push r_temp\r
+       cdb\r
+       sbic OW_PIN,OW_PINN  ; abkuerzung wenn Leitung schon h\r
+       rjmp tint_end ; Leitung 1 kein Reset\r
+       ldi r_temp,0  \r
+       out TCNT_REG,r_temp\r
+       CLEAR_TOV_FLAG\r
+tint_loop_rend:\r
+       sbis OW_PIN,OW_PINN ;warten bis leitung wieder h \r
+       rjmp tint_loop_rend\r
+       JMP_NO_TOV ;ueberspringe wenn kein ueberlauf\r
+       rjmp tint_overrun\r
+       in r_temp,TCNT_REG ;schauen ob es lange genug gedauert hat fuer reset\r
+       cpi r_temp,OWT_RESET2 \r
+       brlo tint_end\r
+tint_overrun:\r
+       ldi r_temp,0\r
+       out TCNT_REG,r_temp\r
+       ;zwischen Reset und Presets\r
+tint_loop_res_pres:\r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,OWT_RESET_PRESENT\r
+       brlo tint_loop_res_pres ;Warten zwischen reset und presets\r
+       sbi OW_DDR,OW_PINN  ;presents impuls\r
+       ;reset impuls\r
+tint_loop_pres:\r
+       in r_temp,TCNT_REG\r
+       cpi r_temp,OWT_PRESENT\r
+       brlo tint_loop_pres\r
+       cbi OW_DDR,OW_PINN  \r
+       ldi r_temp,OW_READ_ROM_COMMAND ; Initialisieren von Rom command\r
+       sts mode,r_temp\r
+       ldi r_temp,1\r
+       sts reset_indicator,r_temp\r
+       sts bcount,r_temp ;bit eins\r
+       clr r_temp\r
+       sts sendflag,r_temp ;empfangen (rom_command)\r
+       ;sts wzero,r_temp ;alles 0 \r
+       RESETZEROMARKER\r
+       CLEAR_INTERRUPT_FLAG\r
+tint_end:\r
+       ;CLEAR_INTERRUPT_FLAG\r
+       DIS_TIM_INT\r
+       pop r_temp\r
+       out _SFR_IO_ADDR(SREG),r_temp\r
+       pop r_temp\r
+       reti\r
+;;;\r
index 2f2e68a..e08d373 100644 (file)
@@ -1,23 +1,23 @@
-#include "calibr.h"
-#include <avr/pgmspace.h>
-#include <avr/io.h>
-
-
-
-//const uint8_t cor[] PROGMEM= {0, 3, 6, 10, 13, 17, 20, 24, 27, 30, 34, 37, 41, 44, 47, 51, 54, 58, 61, 64, 68, 71, 75, 78, 81, 85, 88, 91, 95, 98, 101, 105, 108, 111, 115, 118, 121, 125, 128, 131, 135, 138, 141, 144, 148, 151, 154, 158, 161, 164, 167, 171, 174, 177, 180, 184, 187, 190, 193, 197, 200, 203, 206, 209, 213, 216, 219, 222, 225, 229, 232, 235, 238, 241, 245, 248, 251, 254, 255, 255};
-
-#define a 7.5
-#define b 237.3
-
-inline double SDDD(double t,double x) {
-        //volatile double p=((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0;
-       //return ((p*3.3)/3000.0)+1;
-       //return ((3.5*((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0)/3000.0+1);
-       return 1 - (2.33333 *a* b* x)/((b + t)* (b + t + x));
-}
-
-double calibr_hum(double temp,double tempdiv,double hum) {
-        double r=hum*(SDDD(temp,tempdiv)*(tempdiv/(temp+273.15)+1));
-        if (r>100) return 100.0;
-       return r;
+#include "calibr.h"\r
+#include <avr/pgmspace.h>\r
+#include <avr/io.h>\r
+\r
+\r
+\r
+//const uint8_t cor[] PROGMEM= {0, 3, 6, 10, 13, 17, 20, 24, 27, 30, 34, 37, 41, 44, 47, 51, 54, 58, 61, 64, 68, 71, 75, 78, 81, 85, 88, 91, 95, 98, 101, 105, 108, 111, 115, 118, 121, 125, 128, 131, 135, 138, 141, 144, 148, 151, 154, 158, 161, 164, 167, 171, 174, 177, 180, 184, 187, 190, 193, 197, 200, 203, 206, 209, 213, 216, 219, 222, 225, 229, 232, 235, 238, 241, 245, 248, 251, 254, 255, 255};\r
+\r
+#define a 7.5\r
+#define b 237.3\r
+\r
+inline double SDDD(double t,double x) {\r
+        //volatile double p=((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0;\r
+       //return ((p*3.3)/3000.0)+1;\r
+       //return ((3.5*((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0)/3000.0+1);\r
+       return 1 - (2.33333 *a* b* x)/((b + t)* (b + t + x));\r
+}\r
+\r
+double calibr_hum(double temp,double tempdiv,double hum) {\r
+        double r=hum*(SDDD(temp,tempdiv)*(tempdiv/(temp+273.15)+1));\r
+        if (r>100) return 100.0;\r
+       return r;\r
 }
\ No newline at end of file
index a6bd4fe..2ba627c 100644 (file)
@@ -1,9 +1,9 @@
-#ifndef CALIBR_H
-#define CALIBR_H
-
-
-
-double calibr_hum(double temp,double tempdiv,double hum);
-
-
+#ifndef CALIBR_H\r
+#define CALIBR_H\r
+\r
+\r
+\r
+double calibr_hum(double temp,double tempdiv,double hum);\r
+\r
+\r
 #endif
\ No newline at end of file
index 323f30d..8699f70 100644 (file)
@@ -1,2 +1,2 @@
-avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDD:m -U efuse:w:0xFE:m
-avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"
+avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDD:m -U efuse:w:0xFE:m\r
+avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"\r
index 5159495..86322ed 100644 (file)
@@ -1,2 +1,2 @@
-avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDE:m -U efuse:w:0xFE:m
-avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"
+avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDE:m -U efuse:w:0xFE:m\r
+avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"\r
index bf34f1d..5b2bfd6 100644 (file)
@@ -1,20 +1,20 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{18226A42-8477-4023-8AD2-40C49DA407C9}") = "programmer", "programmer\programmer.asmproj", "{73DCF55E-6410-4DEA-8872-EE17F76DD05A}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|AVR = Debug|AVR
-               Release|AVR = Release|AVR
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.ActiveCfg = Debug|AVR
-               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.Build.0 = Debug|AVR
-               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.ActiveCfg = Release|AVR
-               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.Build.0 = Release|AVR
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Atmel Studio Solution File, Format Version 11.00\r
+Project("{18226A42-8477-4023-8AD2-40C49DA407C9}") = "programmer", "programmer\programmer.asmproj", "{73DCF55E-6410-4DEA-8872-EE17F76DD05A}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|AVR = Debug|AVR\r
+               Release|AVR = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.ActiveCfg = Debug|AVR\r
+               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Debug|AVR.Build.0 = Debug|AVR\r
+               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.ActiveCfg = Release|AVR\r
+               {73DCF55E-6410-4DEA-8872-EE17F76DD05A}.Release|AVR.Build.0 = Release|AVR\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index d047da0..cccdd18 100644 (file)
-.def srbyte = r12  ;byty for search rom algorithm
-.def writelow = r13;  marker for send low
-.def zero =r14;  always zero 
-.def smode=r15; if 1 then send 
-.def temp = r16 ; 
-.def temp2 = r17; 
-.def mode = r18 ; 
-.def bitp = r19 ; bit counter ... shift...
-.def rwbyte = r21;
-.def param = r22;
-.def bytep = r23  ;byte counter
-#define spmcrval  param
-
-
-.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet
-.equ OWM_SLEEP=1 ; Warten auf Reset
-.equ OWM_MATCH_ROM=2
-.equ OWM_SEARCH_ROM_S=3  ;send bit
-.equ OWM_SEARCH_ROM_R=4  ;resive master
-.equ OWM_READ_COMMAND=5
-.equ OWM_WRITE_SCRATCHPAD=6
-.equ OWM_READ_SCRATCHPAD=7
-.equ OWM_PROGRAMM_PAGE=8
-.equ OWM_RECALL_FLASH=9
-
-
-.equ OW_DDR = DDRB 
-.equ OW_PIN = PORTB2
-.equ OW_PORT = PORTB 
-.equ OW_PINN = PINB 
-
-;.equ SRAM_START = 0x60
-
-.macro set_clock
-               ldi temp,0x80;
-               out CLKPR,temp
-               ldi temp,@0
-               out CLKPR,temp
-.endmacro 
-
-.macro owwl
-               sbic OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-.macro owwh
-               sbis OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-
-
-
- ;---------------------------------------------------
-; START of PROG 
-;---------------------------------------------------
-
-
-.CSEG 
-.ORG 0x000
-jreset:
-               rjmp start ; Reset-Vector 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-
-
-.ORG 0x0EC0
-
-start: 
-               cli
-               ldi temp,0
-               mov zero,temp
-               set_clock 0x00 ;8mhz
-               ldi mode,OWM_SLEEP
-               ldi temp,(1<<CS01) //1us
-               out TCCR0B,temp
-               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse 
-               out SPH, temp 
-               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse 
-               out SPL, temp 
-               ;ldi temp,1
-               ;out DDRB,temp
-               clr writelow
-               clr bitp
-       
-               ;sbi PORTB,0
-               ldi ZL,low(pro_owid*2) 
-               ldi ZH,high(pro_owid*2) 
-               ldi XL,low(sowid)
-               ldi XH,high(sowid)
-               ;ldi temp2,8
-pro_copy_loop: ;copy ID on SRAM for better handling
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8
-               brlo pro_copy_loop
-pro_loop:
-               ;sbi PORTB,0
-               owwl                            ;wait for line goes low (polling)
-               sbrs writelow,0         ;test of zero send
-               rjmp pro_loop1          ;no ? goes next
-               sbi OW_DDR,OW_PIN       ;yes pull line to low
-               ldi param,45            ;wait for 50 us
-               rcall wait_time
-               clr writelow            ;reset write low indecator
-               cbi OW_DDR,OW_PIN   ;release line
-               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)
-pro_loop1:
-               tst smode                       ;smode=1 for slave sends to master
-               breq pro_loop_resv
-pro_loop_send:
-               tst bitp
-               brne pro_loop_send1
-               rcall pro_hb
-               tst smode
-               breq pro_loop_end ; now reading ... do nothing 
-pro_loop_send1:  ;prebare next bit
-               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
-               inc writelow
-               lsl bitp
-               ror rwbyte
-               rjmp pro_loop_end
-
-pro_loop_resv:
-               ldi param,15  ;wait 15us
-               rcall wait_time
-               lsr rwbyte
-               ;cbi PORTB,0
-               sbic OW_PINN,OW_PIN  ;test line
-               ori rwbyte,0x80
-               lsl bitp
-               brne pro_loop_end ;no handle need
-               rcall pro_hb
-               tst smode
-               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
-pro_loop_end:
-               //owwh
-               out TCNT0,zero
-pro_loop_end_test_reset:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               rjmp pro_loop
-               in temp,TCNT0
-               cpi temp,130
-               brlo pro_loop_end_test_reset
-               rcall pro_sleep_s2
-               rjmp pro_loop
-
-
-
-
-pro_sleep:
-               out TCNT0,zero
-pro_sleep_s1:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               ret
-               in temp,TCNT0
-               cpi temp,200
-               brlo pro_sleep_s1
-               //leitung wieder high
-pro_sleep_s2:
-               owwh 
-               ldi param,40
-               rcall wait_time
-               //Presents Impuls
-               sbi OW_DDR,OW_PIN
-               ldi param,130
-               rcall wait_time
-               cbi OW_DDR,OW_PIN
-               //init read byte
-               ldi bitp,0x01
-               ldi rwbyte,0
-               clr smode
-               ldi mode,OWM_READ_ROM_COMMAND
-               //Wait for all other devices presents impuls finished
-               ldi param,40
-               rcall wait_time
-               ret
-
-
-
-pro_hb:
-               ldi ZL,low(pro_stable) 
-               ldi ZH,high(pro_stable) 
-               add ZL,mode 
-               adc ZH,zero
-               icall
-               ret
-
-pro_stable: 
-               rjmp pro_read_rom_command
-               rjmp pro_sleep 
-               rjmp pro_match_rom
-               rjmp pro_search_rom_s
-               rjmp pro_search_rom_r
-               rjmp pro_read_command
-               rjmp pro_write_scratchpad
-               rjmp pro_read_scratchpad
-               rjmp pro_programm_page
-               rjmp pro_recall_flash
-
-pro_read_rom_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0xCC
-               brne pro_rcc_1
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-pro_rcc_1:
-               cpi rwbyte,0xF0 ;Searchrom
-               brne pro_rcc_2
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ld srbyte,X+
-               ldi bytep,0
-               rjmp pro_serchrom_next_bit
-pro_rcc_2:
-               cpi rwbyte,0x55 ;Matchrom
-               brne pro_rcc_3
-//             rcall pro_owidinit
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ldi mode,OWM_MATCH_ROM
-               rjmp pro_out_bytep0
-
-pro_rcc_3:
-               ret
-
-pro_match_rom:         
-               ld temp,X+
-               cp temp,rwbyte
-               breq pro_match_rom_next
-               ldi mode,OWM_SLEEP
-               ret
-pro_match_rom_next:                                    
-               cpi XL,SRAM_START+8
-               breq pro_match_rom_found
-               rjmp pro_out_bitp1
-pro_match_rom_found:
-           ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-
-pro_read_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0x0F ;; Write to Scratchpad
-               brne pro_rc_1
-               ldi mode,OWM_WRITE_SCRATCHPAD
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_1:
-               cpi rwbyte,0xAA
-               brne pro_rc_2
-               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               inc smode
-               ld rwbyte,X+
-               rjmp pro_out_bytep0
-
-pro_rc_2:
-               cpi rwbyte,0xB8
-               brne pro_rc_3
-               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_3:
-               cpi rwbyte,0x55 ; copy Scratchpad to Flash
-               brne pro_rc_4
-               ldi mode,OWM_SLEEP
-               rjmp pro_programm_page
-               
-pro_rc_4:
-               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware
-               brne pro_rc_5
-               rjmp jreset             
-pro_rc_5:
-               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1
-               brne pro_rc_6   
-               ldi temp,7
-pro_rc_5a:
-               ldi XL,low(E2END)
-               ldi XH,high(E2END)
-               sub XL,temp
-               out EEARH,XH
-               out EEARL,XL
-               ldi temp, (0<<EEPM1)|(0<<EEPM0)
-               out EECR, temp
-               ldi temp,0xFF
-               out EEDR, temp
-               sbi EECR, EEMPE
-               sbi EECR, EEPE
-               ret
-
-
-pro_rc_6:
-               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2
-               brne pro_rc_7
-               ldi temp,7+8
-               rjmp pro_rc_5a
-
-pro_rc_7:
-               ret
-
-pro_write_scratchpad:
-               st X+,rwbyte
-               cpi XL,SRAM_START+8+66
-               brlo pro_write_scratchpad_next
-               ldi mode,OWM_SLEEP
-               ret             
-pro_write_scratchpad_next:
-               ldi bitp,1
-               ret
-
-pro_read_scratchpad:
-               cpi XL,SRAM_START+8+66
-               brlo pro_read_scratchpad_next
-               ldi mode,OWM_SLEEP
-               clr smode
-               ret
-pro_read_scratchpad_next:
-               ld rwbyte,X+
-               rjmp pro_out_bitp1
-
-
-pro_programm_page:
-.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
-// .org SMALLBOOTSTART
-write_page:
-               ;transfer data from RAM to Flash page buffer
-               ldi bytep, PAGESIZEB ;init loop variable
-               ldi YL,low(scratchpad)  ;init sram pointer
-               ldi YH,high(scratchpad)
-               ld ZL,Y+
-               ld ZH,Y+
-               ;page erase
-               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
-               rcall do_spm
-wrloop:
-               ld r0, Y+
-               ld r1, Y+
-               ldi spmcrval, (1<<SPMEN)
-               rcall do_spm
-               adiw ZH:ZL, 2
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne wrloop
-               ;execute page write
-               subi ZL, low(PAGESIZEB) ;restore pointer
-               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
-               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
-               rcall do_spm
-               ;read back and check, optional
-               ldi bytep, PAGESIZEB
-               subi YL, low(PAGESIZEB) ;restore pointer
-               sbci YH, high(PAGESIZEB)
-rdloop:
-               lpm r0, Z+
-               ld r1, Y+
-               cpse r0, r1
-               rjmp error
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne rdloop
-               ;return
-               ret
-do_spm:
-                ;input: spmcrval determines SPM action
-               ;disable interrupts if enabled, store status
-               in temp2, SREG
-               cli
-               ;check for previous SPM complete
-wait:
-               in temp, SPMCSR
-               sbrc temp, SPMEN
-               rjmp wait
-               ;SPM timed sequence
-               out SPMCSR, spmcrval
-               spm
-               ;restore SREG (to enable interrupts if originally enabled)
-               out SREG, temp2
-               ret
-
-error:
-
-
-               ret
-
-pro_recall_flash:
-               st X+,rwbyte
-               ;inc bytep
-               cpi XL,SRAM_START+8+2
-               brlo pro_out_bitp1;pro_recall_flash_next
-               lds ZL,scratchpad
-               lds ZH,scratchpad+1
-pro_recall_flash_cl:
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8+66
-               brne pro_recall_flash_cl
-               ldi mode,OWM_SLEEP
-               ret
-
-pro_out_read_command:
-               ldi mode,OWM_READ_COMMAND
-pro_out_bytep0:
-               ldi bytep,0
-pro_out_bitp1:
-               ldi bitp,1
-               ret             
-
-
-
-pro_serchrom_next_bit:
-               mov rwbyte,srbyte
-               mov temp2,rwbyte
-               com rwbyte
-               ror temp2  ;first bit in C
-               rol rwbyte ;C in first bit 
-               inc smode
-               ldi bitp,0x40
-               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive
-               ret
-
-
-pro_search_rom_s:
-               clr temp2
-               lsr srbyte ;shift in C lowest bit
-               ror temp2  ; shift in temp2 as highest bit
-               andi rwbyte,0x80  ;  clear other bits
-               eor temp2,rwbyte
-               breq pro_search_rom_s_goon
-               ldi mode,OWM_SLEEP
-               ret
-pro_search_rom_s_goon:
-               inc bytep
-               mov temp2,bytep
-               andi temp2,0x07
-               brne pro_serchrom_next_bit ;prepare next bit
-               mov temp2,bytep
-               andi temp2,0x40 ;;end
-               brne pro_search_rom_found
-               ;read next byte
-               ld srbyte,X+
-               rjmp pro_serchrom_next_bit
-
-pro_search_rom_found:
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bytep0
-
-pro_search_rom_r:
-               clr smode
-               ldi mode,OWM_SEARCH_ROM_S
-               ldi bitp,0  ;go to searchrom_s after bit get
-               ret
-
-pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA
-
-
-
-
-
-wait_time:
-               out TCNT0,zero
-wait_time1:
-               in temp,TCNT0
-               cp temp,param
-               brlo wait_time1
-               ret
-
-
-.DSEG
-sowid: .BYTE 8
+.def srbyte = r12  ;byty for search rom algorithm\r
+.def writelow = r13;  marker for send low\r
+.def zero =r14;  always zero \r
+.def smode=r15; if 1 then send \r
+.def temp = r16 ; \r
+.def temp2 = r17; \r
+.def mode = r18 ; \r
+.def bitp = r19 ; bit counter ... shift...\r
+.def rwbyte = r21;\r
+.def param = r22;\r
+.def bytep = r23  ;byte counter\r
+#define spmcrval  param\r
+\r
+\r
+.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet\r
+.equ OWM_SLEEP=1 ; Warten auf Reset\r
+.equ OWM_MATCH_ROM=2\r
+.equ OWM_SEARCH_ROM_S=3  ;send bit\r
+.equ OWM_SEARCH_ROM_R=4  ;resive master\r
+.equ OWM_READ_COMMAND=5\r
+.equ OWM_WRITE_SCRATCHPAD=6\r
+.equ OWM_READ_SCRATCHPAD=7\r
+.equ OWM_PROGRAMM_PAGE=8\r
+.equ OWM_RECALL_FLASH=9\r
+\r
+\r
+.equ OW_DDR = DDRB \r
+.equ OW_PIN = PORTB2\r
+.equ OW_PORT = PORTB \r
+.equ OW_PINN = PINB \r
+\r
+;.equ SRAM_START = 0x60\r
+\r
+.macro set_clock\r
+               ldi temp,0x80;\r
+               out CLKPR,temp\r
+               ldi temp,@0\r
+               out CLKPR,temp\r
+.endmacro \r
+\r
+.macro owwl\r
+               sbic OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+.macro owwh\r
+               sbis OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+\r
+\r
+\r
+ ;---------------------------------------------------\r
+; START of PROG \r
+;---------------------------------------------------\r
+\r
+\r
+.CSEG \r
+.ORG 0x000\r
+jreset:\r
+               rjmp start ; Reset-Vector \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+\r
+\r
+.ORG 0x0EC0\r
+\r
+start: \r
+               cli\r
+               ldi temp,0\r
+               mov zero,temp\r
+               set_clock 0x00 ;8mhz\r
+               ldi mode,OWM_SLEEP\r
+               ldi temp,(1<<CS01) //1us\r
+               out TCCR0B,temp\r
+               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse \r
+               out SPH, temp \r
+               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse \r
+               out SPL, temp \r
+               ;ldi temp,1\r
+               ;out DDRB,temp\r
+               clr writelow\r
+               clr bitp\r
+       \r
+               ;sbi PORTB,0\r
+               ldi ZL,low(pro_owid*2) \r
+               ldi ZH,high(pro_owid*2) \r
+               ldi XL,low(sowid)\r
+               ldi XH,high(sowid)\r
+               ;ldi temp2,8\r
+pro_copy_loop: ;copy ID on SRAM for better handling\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8\r
+               brlo pro_copy_loop\r
+pro_loop:\r
+               ;sbi PORTB,0\r
+               owwl                            ;wait for line goes low (polling)\r
+               sbrs writelow,0         ;test of zero send\r
+               rjmp pro_loop1          ;no ? goes next\r
+               sbi OW_DDR,OW_PIN       ;yes pull line to low\r
+               ldi param,45            ;wait for 50 us\r
+               rcall wait_time\r
+               clr writelow            ;reset write low indecator\r
+               cbi OW_DDR,OW_PIN   ;release line\r
+               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)\r
+pro_loop1:\r
+               tst smode                       ;smode=1 for slave sends to master\r
+               breq pro_loop_resv\r
+pro_loop_send:\r
+               tst bitp\r
+               brne pro_loop_send1\r
+               rcall pro_hb\r
+               tst smode\r
+               breq pro_loop_end ; now reading ... do nothing \r
+pro_loop_send1:  ;prebare next bit\r
+               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command\r
+               inc writelow\r
+               lsl bitp\r
+               ror rwbyte\r
+               rjmp pro_loop_end\r
+\r
+pro_loop_resv:\r
+               ldi param,15  ;wait 15us\r
+               rcall wait_time\r
+               lsr rwbyte\r
+               ;cbi PORTB,0\r
+               sbic OW_PINN,OW_PIN  ;test line\r
+               ori rwbyte,0x80\r
+               lsl bitp\r
+               brne pro_loop_end ;no handle need\r
+               rcall pro_hb\r
+               tst smode\r
+               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+pro_loop_end:\r
+               //owwh\r
+               out TCNT0,zero\r
+pro_loop_end_test_reset:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               rjmp pro_loop\r
+               in temp,TCNT0\r
+               cpi temp,130\r
+               brlo pro_loop_end_test_reset\r
+               rcall pro_sleep_s2\r
+               rjmp pro_loop\r
+\r
+\r
+\r
+\r
+pro_sleep:\r
+               out TCNT0,zero\r
+pro_sleep_s1:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               ret\r
+               in temp,TCNT0\r
+               cpi temp,200\r
+               brlo pro_sleep_s1\r
+               //leitung wieder high\r
+pro_sleep_s2:\r
+               owwh \r
+               ldi param,40\r
+               rcall wait_time\r
+               //Presents Impuls\r
+               sbi OW_DDR,OW_PIN\r
+               ldi param,130\r
+               rcall wait_time\r
+               cbi OW_DDR,OW_PIN\r
+               //init read byte\r
+               ldi bitp,0x01\r
+               ldi rwbyte,0\r
+               clr smode\r
+               ldi mode,OWM_READ_ROM_COMMAND\r
+               //Wait for all other devices presents impuls finished\r
+               ldi param,40\r
+               rcall wait_time\r
+               ret\r
+\r
+\r
+\r
+pro_hb:\r
+               ldi ZL,low(pro_stable) \r
+               ldi ZH,high(pro_stable) \r
+               add ZL,mode \r
+               adc ZH,zero\r
+               icall\r
+               ret\r
+\r
+pro_stable: \r
+               rjmp pro_read_rom_command\r
+               rjmp pro_sleep \r
+               rjmp pro_match_rom\r
+               rjmp pro_search_rom_s\r
+               rjmp pro_search_rom_r\r
+               rjmp pro_read_command\r
+               rjmp pro_write_scratchpad\r
+               rjmp pro_read_scratchpad\r
+               rjmp pro_programm_page\r
+               rjmp pro_recall_flash\r
+\r
+pro_read_rom_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0xCC\r
+               brne pro_rcc_1\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+pro_rcc_1:\r
+               cpi rwbyte,0xF0 ;Searchrom\r
+               brne pro_rcc_2\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ld srbyte,X+\r
+               ldi bytep,0\r
+               rjmp pro_serchrom_next_bit\r
+pro_rcc_2:\r
+               cpi rwbyte,0x55 ;Matchrom\r
+               brne pro_rcc_3\r
+//             rcall pro_owidinit\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ldi mode,OWM_MATCH_ROM\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rcc_3:\r
+               ret\r
+\r
+pro_match_rom:         \r
+               ld temp,X+\r
+               cp temp,rwbyte\r
+               breq pro_match_rom_next\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_match_rom_next:                                    \r
+               cpi XL,SRAM_START+8\r
+               breq pro_match_rom_found\r
+               rjmp pro_out_bitp1\r
+pro_match_rom_found:\r
+           ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+\r
+pro_read_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0x0F ;; Write to Scratchpad\r
+               brne pro_rc_1\r
+               ldi mode,OWM_WRITE_SCRATCHPAD\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_1:\r
+               cpi rwbyte,0xAA\r
+               brne pro_rc_2\r
+               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               inc smode\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rc_2:\r
+               cpi rwbyte,0xB8\r
+               brne pro_rc_3\r
+               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_3:\r
+               cpi rwbyte,0x55 ; copy Scratchpad to Flash\r
+               brne pro_rc_4\r
+               ldi mode,OWM_SLEEP\r
+               rjmp pro_programm_page\r
+               \r
+pro_rc_4:\r
+               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware\r
+               brne pro_rc_5\r
+               rjmp jreset             \r
+pro_rc_5:\r
+               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1\r
+               brne pro_rc_6   \r
+               ldi temp,7\r
+pro_rc_5a:\r
+               ldi XL,low(E2END)\r
+               ldi XH,high(E2END)\r
+               sub XL,temp\r
+               out EEARH,XH\r
+               out EEARL,XL\r
+               ldi temp, (0<<EEPM1)|(0<<EEPM0)\r
+               out EECR, temp\r
+               ldi temp,0xFF\r
+               out EEDR, temp\r
+               sbi EECR, EEMPE\r
+               sbi EECR, EEPE\r
+               ret\r
+\r
+\r
+pro_rc_6:\r
+               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2\r
+               brne pro_rc_7\r
+               ldi temp,7+8\r
+               rjmp pro_rc_5a\r
+\r
+pro_rc_7:\r
+               ret\r
+\r
+pro_write_scratchpad:\r
+               st X+,rwbyte\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_write_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               ret             \r
+pro_write_scratchpad_next:\r
+               ldi bitp,1\r
+               ret\r
+\r
+pro_read_scratchpad:\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_read_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               clr smode\r
+               ret\r
+pro_read_scratchpad_next:\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bitp1\r
+\r
+\r
+pro_programm_page:\r
+.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words\r
+// .org SMALLBOOTSTART\r
+write_page:\r
+               ;transfer data from RAM to Flash page buffer\r
+               ldi bytep, PAGESIZEB ;init loop variable\r
+               ldi YL,low(scratchpad)  ;init sram pointer\r
+               ldi YH,high(scratchpad)\r
+               ld ZL,Y+\r
+               ld ZH,Y+\r
+               ;page erase\r
+               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)\r
+               rcall do_spm\r
+wrloop:\r
+               ld r0, Y+\r
+               ld r1, Y+\r
+               ldi spmcrval, (1<<SPMEN)\r
+               rcall do_spm\r
+               adiw ZH:ZL, 2\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne wrloop\r
+               ;execute page write\r
+               subi ZL, low(PAGESIZEB) ;restore pointer\r
+               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256\r
+               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)\r
+               rcall do_spm\r
+               ;read back and check, optional\r
+               ldi bytep, PAGESIZEB\r
+               subi YL, low(PAGESIZEB) ;restore pointer\r
+               sbci YH, high(PAGESIZEB)\r
+rdloop:\r
+               lpm r0, Z+\r
+               ld r1, Y+\r
+               cpse r0, r1\r
+               rjmp error\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne rdloop\r
+               ;return\r
+               ret\r
+do_spm:\r
+                ;input: spmcrval determines SPM action\r
+               ;disable interrupts if enabled, store status\r
+               in temp2, SREG\r
+               cli\r
+               ;check for previous SPM complete\r
+wait:\r
+               in temp, SPMCSR\r
+               sbrc temp, SPMEN\r
+               rjmp wait\r
+               ;SPM timed sequence\r
+               out SPMCSR, spmcrval\r
+               spm\r
+               ;restore SREG (to enable interrupts if originally enabled)\r
+               out SREG, temp2\r
+               ret\r
+\r
+error:\r
+\r
+\r
+               ret\r
+\r
+pro_recall_flash:\r
+               st X+,rwbyte\r
+               ;inc bytep\r
+               cpi XL,SRAM_START+8+2\r
+               brlo pro_out_bitp1;pro_recall_flash_next\r
+               lds ZL,scratchpad\r
+               lds ZH,scratchpad+1\r
+pro_recall_flash_cl:\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8+66\r
+               brne pro_recall_flash_cl\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+\r
+pro_out_read_command:\r
+               ldi mode,OWM_READ_COMMAND\r
+pro_out_bytep0:\r
+               ldi bytep,0\r
+pro_out_bitp1:\r
+               ldi bitp,1\r
+               ret             \r
+\r
+\r
+\r
+pro_serchrom_next_bit:\r
+               mov rwbyte,srbyte\r
+               mov temp2,rwbyte\r
+               com rwbyte\r
+               ror temp2  ;first bit in C\r
+               rol rwbyte ;C in first bit \r
+               inc smode\r
+               ldi bitp,0x40\r
+               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive\r
+               ret\r
+\r
+\r
+pro_search_rom_s:\r
+               clr temp2\r
+               lsr srbyte ;shift in C lowest bit\r
+               ror temp2  ; shift in temp2 as highest bit\r
+               andi rwbyte,0x80  ;  clear other bits\r
+               eor temp2,rwbyte\r
+               breq pro_search_rom_s_goon\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_search_rom_s_goon:\r
+               inc bytep\r
+               mov temp2,bytep\r
+               andi temp2,0x07\r
+               brne pro_serchrom_next_bit ;prepare next bit\r
+               mov temp2,bytep\r
+               andi temp2,0x40 ;;end\r
+               brne pro_search_rom_found\r
+               ;read next byte\r
+               ld srbyte,X+\r
+               rjmp pro_serchrom_next_bit\r
+\r
+pro_search_rom_found:\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bytep0\r
+\r
+pro_search_rom_r:\r
+               clr smode\r
+               ldi mode,OWM_SEARCH_ROM_S\r
+               ldi bitp,0  ;go to searchrom_s after bit get\r
+               ret\r
+\r
+pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA\r
+\r
+\r
+\r
+\r
+\r
+wait_time:\r
+               out TCNT0,zero\r
+wait_time1:\r
+               in temp,TCNT0\r
+               cp temp,param\r
+               brlo wait_time1\r
+               ret\r
+\r
+\r
+.DSEG\r
+sowid: .BYTE 8\r
 scratchpad: .BYTE 66
\ No newline at end of file
index c2a53d0..519af5b 100644 (file)
@@ -1,93 +1,93 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectVersion>7.0</ProjectVersion>
-    <ToolchainName>com.Atmel.AVRAssembler</ToolchainName>
-    <ProjectGuid>{73dcf55e-6410-4dea-8872-ee17f76dd05a}</ProjectGuid>
-    <avrdeviceseries>none</avrdeviceseries>
-    <avrdevice>ATtiny84A</avrdevice>
-    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
-    <OutputFileExtension>.obj</OutputFileExtension>
-    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
-    <Language>ASSEMBLY</Language>
-    <AssemblyName>programmer</AssemblyName>
-    <Name>programmer</Name>
-    <RootNamespace>programmer</RootNamespace>
-    <EntryFile>$(MSBuildProjectDirectory)\programmer.asm</EntryFile>
-    <ToolchainFlavour>Native</ToolchainFlavour>
-    <KeepTimersRunning>true</KeepTimersRunning>
-    <OverrideVtor>false</OverrideVtor>
-    <CacheFlash>true</CacheFlash>
-    <ProgFlashFromRam>true</ProgFlashFromRam>
-    <RamSnippetAddress>0x20000000</RamSnippetAddress>
-    <UncachedRange />
-    <preserveEEPROM>true</preserveEEPROM>
-    <OverrideVtorValue>exception_table</OverrideVtorValue>
-    <BootSegment>2</BootSegment>
-    <eraseonlaunchrule>1</eraseonlaunchrule>
-    <AsfFrameworkConfig>
-      <framework-data>
-        <options />
-        <configurations />
-        <files />
-        <documentation help="" />
-        <offline-documentation help="" />
-        <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.18.1" />
-        </dependencies>
-      </framework-data>
-    </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-          <IspClock>100000</IspClock>
-          <DebugWireClockDiv>0</DebugWireClockDiv>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
-    <ExternalProgrammingToolCommand />
-    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
-    <ToolchainSettings>
-      <AvrAssembler>
-        <avrasm.assembler.general.AdditionalIncludeDirectories>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>
-          </ListValues>
-        </avrasm.assembler.general.AdditionalIncludeDirectories>
-        <avrasm.assembler.general.IncludeFile>tn84adef.inc</avrasm.assembler.general.IncludeFile>
-      </AvrAssembler>
-    </ToolchainSettings>
-    <OutputType>Executable</OutputType>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <ToolchainSettings>
-      <AvrAssembler>
-        <avrasm.assembler.general.AdditionalIncludeDirectories>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>
-          </ListValues>
-        </avrasm.assembler.general.AdditionalIncludeDirectories>
-        <avrasm.assembler.general.IncludeFile>tn84adef.inc</avrasm.assembler.general.IncludeFile>
-      </AvrAssembler>
-    </ToolchainSettings>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="programmer.asm">
-      <SubType>Code</SubType>
-    </Compile>
-  </ItemGroup>
-  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Assembler.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectVersion>7.0</ProjectVersion>\r
+    <ToolchainName>com.Atmel.AVRAssembler</ToolchainName>\r
+    <ProjectGuid>{73dcf55e-6410-4dea-8872-ee17f76dd05a}</ProjectGuid>\r
+    <avrdeviceseries>none</avrdeviceseries>\r
+    <avrdevice>ATtiny84A</avrdevice>\r
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>\r
+    <OutputFileExtension>.obj</OutputFileExtension>\r
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>\r
+    <Language>ASSEMBLY</Language>\r
+    <AssemblyName>programmer</AssemblyName>\r
+    <Name>programmer</Name>\r
+    <RootNamespace>programmer</RootNamespace>\r
+    <EntryFile>$(MSBuildProjectDirectory)\programmer.asm</EntryFile>\r
+    <ToolchainFlavour>Native</ToolchainFlavour>\r
+    <KeepTimersRunning>true</KeepTimersRunning>\r
+    <OverrideVtor>false</OverrideVtor>\r
+    <CacheFlash>true</CacheFlash>\r
+    <ProgFlashFromRam>true</ProgFlashFromRam>\r
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>\r
+    <UncachedRange />\r
+    <preserveEEPROM>true</preserveEEPROM>\r
+    <OverrideVtorValue>exception_table</OverrideVtorValue>\r
+    <BootSegment>2</BootSegment>\r
+    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <AsfFrameworkConfig>\r
+      <framework-data>\r
+        <options />\r
+        <configurations />\r
+        <files />\r
+        <documentation help="" />\r
+        <offline-documentation help="" />\r
+        <dependencies>\r
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.18.1" />\r
+        </dependencies>\r
+      </framework-data>\r
+    </AsfFrameworkConfig>\r
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <com_atmel_avrdbg_tool_atmelice>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+          <IspClock>100000</IspClock>\r
+          <DebugWireClockDiv>0</DebugWireClockDiv>\r
+        </InterfaceProperties>\r
+        <InterfaceName>debugWIRE</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>\r
+      <ToolNumber>J41800000779</ToolNumber>\r
+      <ToolName>Atmel-ICE</ToolName>\r
+    </com_atmel_avrdbg_tool_atmelice>\r
+    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <ExternalProgrammingToolCommand />\r
+    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>\r
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
+    <ToolchainSettings>\r
+      <AvrAssembler>\r
+        <avrasm.assembler.general.AdditionalIncludeDirectories>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>\r
+          </ListValues>\r
+        </avrasm.assembler.general.AdditionalIncludeDirectories>\r
+        <avrasm.assembler.general.IncludeFile>tn84adef.inc</avrasm.assembler.general.IncludeFile>\r
+      </AvrAssembler>\r
+    </ToolchainSettings>\r
+    <OutputType>Executable</OutputType>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">\r
+    <ToolchainSettings>\r
+      <AvrAssembler>\r
+        <avrasm.assembler.general.AdditionalIncludeDirectories>\r
+          <ListValues>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>\r
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\avrasm\inc</Value>\r
+          </ListValues>\r
+        </avrasm.assembler.general.AdditionalIncludeDirectories>\r
+        <avrasm.assembler.general.IncludeFile>tn84adef.inc</avrasm.assembler.general.IncludeFile>\r
+      </AvrAssembler>\r
+    </ToolchainSettings>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="programmer.asm">\r
+      <SubType>Code</SubType>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Assembler.targets" />\r
 </Project>
\ No newline at end of file
index 9af0938..b08cc96 100644 (file)
-.def srbyte = r12  ;byty for search rom algorithm
-.def writelow = r13;  marker for send low
-.def zero =r14;  always zero 
-.def smode=r15; if 1 then send 
-.def temp = r16 ; 
-.def temp2 = r17; 
-.def mode = r18 ; 
-.def bitp = r19 ; bit counter ... shift...
-.def rwbyte = r21;
-.def param = r22;
-.def bytep = r23  ;byte counter
-#define spmcrval  param
-
-
-.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet
-.equ OWM_SLEEP=1 ; Warten auf Reset
-.equ OWM_MATCH_ROM=2
-.equ OWM_SEARCH_ROM_S=3  ;send bit
-.equ OWM_SEARCH_ROM_R=4  ;resive master
-.equ OWM_READ_COMMAND=5
-.equ OWM_WRITE_SCRATCHPAD=6
-.equ OWM_READ_SCRATCHPAD=7
-.equ OWM_PROGRAMM_PAGE=8
-.equ OWM_RECALL_FLASH=9
-
-
-.equ OW_DDR = DDRB 
-.equ OW_PIN = PORTB2
-.equ OW_PORT = PORTB 
-.equ OW_PINN = PINB 
-
-;.equ SRAM_START = 0x60
-
-.macro set_clock
-               ldi temp,0x80;
-               out CLKPR,temp
-               ldi temp,@0
-               out CLKPR,temp
-.endmacro 
-
-.macro owwl
-               sbic OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-.macro owwh
-               sbis OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-
-
-
- ;---------------------------------------------------
-; START of PROG 
-;---------------------------------------------------
-
-
-.CSEG 
-.ORG 0x000
-jreset:
-               rjmp start ; Reset-Vector 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-
-
-.ORG 0x0EC0
-
-start: 
-               cli
-               ldi temp,0
-               mov zero,temp
-               set_clock 0x01 ;4mhz
-               ldi mode,OWM_SLEEP
-               ldi temp,(1<<CS01) //2us
-               out TCCR0B,temp
-               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse 
-               out SPH, temp 
-               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse 
-               out SPL, temp 
-               ;ldi temp,1
-               ;out DDRB,temp
-               clr writelow
-               clr bitp
-       
-               ;sbi PORTB,0
-               ldi ZL,low(pro_owid*2) 
-               ldi ZH,high(pro_owid*2) 
-               ldi XL,low(sowid)
-               ldi XH,high(sowid)
-               ;ldi temp2,8
-pro_copy_loop: ;copy ID on SRAM for better handling
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8
-               brlo pro_copy_loop
-pro_loop:
-               ;sbi PORTB,0
-               owwl                            ;wait for line goes low (polling)
-               sbrc writelow,0         ;test of zero send
-               sbi OW_DDR,OW_PIN       ;yes pull line to low 2us faster
-               sbrs writelow,0     ;test egain 2us faster.....
-               rjmp pro_loop1          ;no ? goes next
-               ldi param,20            ;wait for 50 us
-               rcall wait_time
-               clr writelow            ;reset write low indecator
-               cbi OW_DDR,OW_PIN   ;release line
-               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)
-pro_loop1:
-               tst smode                       ;smode=1 for slave sends to master
-               breq pro_loop_resv
-pro_loop_send:
-               tst bitp
-               brne pro_loop_send1
-               rcall pro_hb
-               tst smode
-               breq pro_loop_end ; now reading ... do nothing 
-pro_loop_send1:  ;prebare next bit
-               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
-               inc writelow
-               lsl bitp
-               ror rwbyte
-               rjmp pro_loop_end
-
-pro_loop_resv:
-               ldi param,7  ;wait 15us
-               rcall wait_time
-               lsr rwbyte
-               ;cbi PORTB,0
-               sbic OW_PINN,OW_PIN  ;test line
-               ori rwbyte,0x80
-               lsl bitp
-               brne pro_loop_end ;no handle need
-               rcall pro_hb
-               tst smode
-               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
-pro_loop_end:
-               //owwh
-               out TCNT0,zero
-pro_loop_end_test_reset:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               rjmp pro_loop
-               in temp,TCNT0
-               cpi temp,63
-               brlo pro_loop_end_test_reset
-               rcall pro_sleep_s2
-               rjmp pro_loop
-
-
-
-
-pro_sleep:
-               out TCNT0,zero
-pro_sleep_s1:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               ret
-               in temp,TCNT0
-               cpi temp,100
-               brlo pro_sleep_s1
-               //leitung wieder high
-pro_sleep_s2:
-               owwh 
-               ldi param,20
-               rcall wait_time
-               //Presents Impuls
-               sbi OW_DDR,OW_PIN
-               ldi param,75
-               rcall wait_time
-               cbi OW_DDR,OW_PIN
-               //init read byte
-               ldi bitp,0x01
-               ldi rwbyte,0
-               clr smode
-               ldi mode,OWM_READ_ROM_COMMAND
-               //Wait for all other devices presents impuls finished
-               ldi param,20
-               rcall wait_time
-               ret
-
-
-
-pro_hb:
-               ldi ZL,low(pro_stable) 
-               ldi ZH,high(pro_stable) 
-               add ZL,mode 
-               adc ZH,zero
-               icall
-               ret
-
-pro_stable: 
-               rjmp pro_read_rom_command
-               rjmp pro_sleep 
-               rjmp pro_match_rom
-               rjmp pro_search_rom_s
-               rjmp pro_search_rom_r
-               rjmp pro_read_command
-               rjmp pro_write_scratchpad
-               rjmp pro_read_scratchpad
-               rjmp pro_programm_page
-               rjmp pro_recall_flash
-
-pro_read_rom_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0xCC
-               brne pro_rcc_1
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-pro_rcc_1:
-               cpi rwbyte,0xF0 ;Searchrom
-               brne pro_rcc_2
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ld srbyte,X+
-               ldi bytep,0
-               rjmp pro_serchrom_next_bit
-pro_rcc_2:
-               cpi rwbyte,0x55 ;Matchrom
-               brne pro_rcc_3
-//             rcall pro_owidinit
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ldi mode,OWM_MATCH_ROM
-               rjmp pro_out_bytep0
-
-pro_rcc_3:
-               ret
-
-pro_match_rom:         
-               ld temp,X+
-               cp temp,rwbyte
-               breq pro_match_rom_next
-               ldi mode,OWM_SLEEP
-               ret
-pro_match_rom_next:                                    
-               cpi XL,SRAM_START+8
-               breq pro_match_rom_found
-               rjmp pro_out_bitp1
-pro_match_rom_found:
-           ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-
-pro_read_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0x0F ;; Write to Scratchpad
-               brne pro_rc_1
-               ldi mode,OWM_WRITE_SCRATCHPAD
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_1:
-               cpi rwbyte,0xAA
-               brne pro_rc_2
-               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               inc smode
-               ld rwbyte,X+
-               rjmp pro_out_bytep0
-
-pro_rc_2:
-               cpi rwbyte,0xB8
-               brne pro_rc_3
-               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_3:
-               cpi rwbyte,0x55 ; copy Scratchpad to Flash
-               brne pro_rc_4
-               ldi mode,OWM_SLEEP
-               rjmp pro_programm_page
-               
-pro_rc_4:
-               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware
-               brne pro_rc_5
-               rjmp jreset             
-pro_rc_5:
-               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1
-               brne pro_rc_6   
-               ldi temp,7
-pro_rc_5a:
-               ldi XL,low(E2END)
-               ldi XH,high(E2END)
-               sub XL,temp
-               out EEARH,XH
-               out EEARL,XL
-               ldi temp, (0<<EEPM1)|(0<<EEPM0)
-               out EECR, temp
-               ldi temp,0xFF
-               out EEDR, temp
-               sbi EECR, EEMPE
-               sbi EECR, EEPE
-               ret
-
-
-pro_rc_6:
-               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2
-               brne pro_rc_7
-               ldi temp,7+8
-               rjmp pro_rc_5a
-
-pro_rc_7:
-               ret
-
-pro_write_scratchpad:
-               st X+,rwbyte
-               cpi XL,SRAM_START+8+66
-               brlo pro_write_scratchpad_next
-               ldi mode,OWM_SLEEP
-               ret             
-pro_write_scratchpad_next:
-               ldi bitp,1
-               ret
-
-pro_read_scratchpad:
-               cpi XL,SRAM_START+8+66
-               brlo pro_read_scratchpad_next
-               ldi mode,OWM_SLEEP
-               clr smode
-               ret
-pro_read_scratchpad_next:
-               ld rwbyte,X+
-               rjmp pro_out_bitp1
-
-
-pro_programm_page:
-.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
-// .org SMALLBOOTSTART
-write_page:
-               ;transfer data from RAM to Flash page buffer
-               ldi bytep, PAGESIZEB ;init loop variable
-               ldi YL,low(scratchpad)  ;init sram pointer
-               ldi YH,high(scratchpad)
-               ld ZL,Y+
-               ld ZH,Y+
-               ;page erase
-               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
-               rcall do_spm
-wrloop:
-               ld r0, Y+
-               ld r1, Y+
-               ldi spmcrval, (1<<SPMEN)
-               rcall do_spm
-               adiw ZH:ZL, 2
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne wrloop
-               ;execute page write
-               subi ZL, low(PAGESIZEB) ;restore pointer
-               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
-               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
-               rcall do_spm
-               ;read back and check, optional
-               ldi bytep, PAGESIZEB
-               subi YL, low(PAGESIZEB) ;restore pointer
-               sbci YH, high(PAGESIZEB)
-rdloop:
-               lpm r0, Z+
-               ld r1, Y+
-               cpse r0, r1
-               rjmp error
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne rdloop
-               ;return
-               ret
-do_spm:
-                ;input: spmcrval determines SPM action
-               ;disable interrupts if enabled, store status
-               in temp2, SREG
-               cli
-               ;check for previous SPM complete
-wait:
-               in temp, SPMCSR
-               sbrc temp, SPMEN
-               rjmp wait
-               ;SPM timed sequence
-               out SPMCSR, spmcrval
-               spm
-               ;restore SREG (to enable interrupts if originally enabled)
-               out SREG, temp2
-               ret
-
-error:
-
-
-               ret
-
-pro_recall_flash:
-               st X+,rwbyte
-               ;inc bytep
-               cpi XL,SRAM_START+8+2
-               brlo pro_out_bitp1;pro_recall_flash_next
-               lds ZL,scratchpad
-               lds ZH,scratchpad+1
-pro_recall_flash_cl:
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8+66
-               brne pro_recall_flash_cl
-               ldi mode,OWM_SLEEP
-               ret
-
-pro_out_read_command:
-               ldi mode,OWM_READ_COMMAND
-pro_out_bytep0:
-               ldi bytep,0
-pro_out_bitp1:
-               ldi bitp,1
-               ret             
-
-
-
-pro_serchrom_next_bit:
-               mov rwbyte,srbyte
-               mov temp2,rwbyte
-               com rwbyte
-               ror temp2  ;first bit in C
-               rol rwbyte ;C in first bit 
-               inc smode
-               ldi bitp,0x40
-               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive
-               ret
-
-
-pro_search_rom_s:
-               clr temp2
-               lsr srbyte ;shift in C lowest bit
-               ror temp2  ; shift in temp2 as highest bit
-               andi rwbyte,0x80  ;  clear other bits
-               eor temp2,rwbyte
-               breq pro_search_rom_s_goon
-               ldi mode,OWM_SLEEP
-               ret
-pro_search_rom_s_goon:
-               inc bytep
-               mov temp2,bytep
-               andi temp2,0x07
-               brne pro_serchrom_next_bit ;prepare next bit
-               mov temp2,bytep
-               andi temp2,0x40 ;;end
-               brne pro_search_rom_found
-               ;read next byte
-               ld srbyte,X+
-               rjmp pro_serchrom_next_bit
-
-pro_search_rom_found:
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bytep0
-
-pro_search_rom_r:
-               clr smode
-               ldi mode,OWM_SEARCH_ROM_S
-               ldi bitp,0  ;go to searchrom_s after bit get
-               ret
-
-pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA
-
-
-
-
-
-wait_time:
-               out TCNT0,zero
-wait_time1:
-               in temp,TCNT0
-               cp temp,param
-               brlo wait_time1
-               ret
-
-
-.DSEG
-sowid: .BYTE 8
+.def srbyte = r12  ;byty for search rom algorithm\r
+.def writelow = r13;  marker for send low\r
+.def zero =r14;  always zero \r
+.def smode=r15; if 1 then send \r
+.def temp = r16 ; \r
+.def temp2 = r17; \r
+.def mode = r18 ; \r
+.def bitp = r19 ; bit counter ... shift...\r
+.def rwbyte = r21;\r
+.def param = r22;\r
+.def bytep = r23  ;byte counter\r
+#define spmcrval  param\r
+\r
+\r
+.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet\r
+.equ OWM_SLEEP=1 ; Warten auf Reset\r
+.equ OWM_MATCH_ROM=2\r
+.equ OWM_SEARCH_ROM_S=3  ;send bit\r
+.equ OWM_SEARCH_ROM_R=4  ;resive master\r
+.equ OWM_READ_COMMAND=5\r
+.equ OWM_WRITE_SCRATCHPAD=6\r
+.equ OWM_READ_SCRATCHPAD=7\r
+.equ OWM_PROGRAMM_PAGE=8\r
+.equ OWM_RECALL_FLASH=9\r
+\r
+\r
+.equ OW_DDR = DDRB \r
+.equ OW_PIN = PORTB2\r
+.equ OW_PORT = PORTB \r
+.equ OW_PINN = PINB \r
+\r
+;.equ SRAM_START = 0x60\r
+\r
+.macro set_clock\r
+               ldi temp,0x80;\r
+               out CLKPR,temp\r
+               ldi temp,@0\r
+               out CLKPR,temp\r
+.endmacro \r
+\r
+.macro owwl\r
+               sbic OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+.macro owwh\r
+               sbis OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+\r
+\r
+\r
+ ;---------------------------------------------------\r
+; START of PROG \r
+;---------------------------------------------------\r
+\r
+\r
+.CSEG \r
+.ORG 0x000\r
+jreset:\r
+               rjmp start ; Reset-Vector \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+\r
+\r
+.ORG 0x0EC0\r
+\r
+start: \r
+               cli\r
+               ldi temp,0\r
+               mov zero,temp\r
+               set_clock 0x01 ;4mhz\r
+               ldi mode,OWM_SLEEP\r
+               ldi temp,(1<<CS01) //2us\r
+               out TCCR0B,temp\r
+               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse \r
+               out SPH, temp \r
+               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse \r
+               out SPL, temp \r
+               ;ldi temp,1\r
+               ;out DDRB,temp\r
+               clr writelow\r
+               clr bitp\r
+       \r
+               ;sbi PORTB,0\r
+               ldi ZL,low(pro_owid*2) \r
+               ldi ZH,high(pro_owid*2) \r
+               ldi XL,low(sowid)\r
+               ldi XH,high(sowid)\r
+               ;ldi temp2,8\r
+pro_copy_loop: ;copy ID on SRAM for better handling\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8\r
+               brlo pro_copy_loop\r
+pro_loop:\r
+               ;sbi PORTB,0\r
+               owwl                            ;wait for line goes low (polling)\r
+               sbrc writelow,0         ;test of zero send\r
+               sbi OW_DDR,OW_PIN       ;yes pull line to low 2us faster\r
+               sbrs writelow,0     ;test egain 2us faster.....\r
+               rjmp pro_loop1          ;no ? goes next\r
+               ldi param,20            ;wait for 50 us\r
+               rcall wait_time\r
+               clr writelow            ;reset write low indecator\r
+               cbi OW_DDR,OW_PIN   ;release line\r
+               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)\r
+pro_loop1:\r
+               tst smode                       ;smode=1 for slave sends to master\r
+               breq pro_loop_resv\r
+pro_loop_send:\r
+               tst bitp\r
+               brne pro_loop_send1\r
+               rcall pro_hb\r
+               tst smode\r
+               breq pro_loop_end ; now reading ... do nothing \r
+pro_loop_send1:  ;prebare next bit\r
+               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command\r
+               inc writelow\r
+               lsl bitp\r
+               ror rwbyte\r
+               rjmp pro_loop_end\r
+\r
+pro_loop_resv:\r
+               ldi param,7  ;wait 15us\r
+               rcall wait_time\r
+               lsr rwbyte\r
+               ;cbi PORTB,0\r
+               sbic OW_PINN,OW_PIN  ;test line\r
+               ori rwbyte,0x80\r
+               lsl bitp\r
+               brne pro_loop_end ;no handle need\r
+               rcall pro_hb\r
+               tst smode\r
+               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+pro_loop_end:\r
+               //owwh\r
+               out TCNT0,zero\r
+pro_loop_end_test_reset:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               rjmp pro_loop\r
+               in temp,TCNT0\r
+               cpi temp,63\r
+               brlo pro_loop_end_test_reset\r
+               rcall pro_sleep_s2\r
+               rjmp pro_loop\r
+\r
+\r
+\r
+\r
+pro_sleep:\r
+               out TCNT0,zero\r
+pro_sleep_s1:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               ret\r
+               in temp,TCNT0\r
+               cpi temp,100\r
+               brlo pro_sleep_s1\r
+               //leitung wieder high\r
+pro_sleep_s2:\r
+               owwh \r
+               ldi param,20\r
+               rcall wait_time\r
+               //Presents Impuls\r
+               sbi OW_DDR,OW_PIN\r
+               ldi param,75\r
+               rcall wait_time\r
+               cbi OW_DDR,OW_PIN\r
+               //init read byte\r
+               ldi bitp,0x01\r
+               ldi rwbyte,0\r
+               clr smode\r
+               ldi mode,OWM_READ_ROM_COMMAND\r
+               //Wait for all other devices presents impuls finished\r
+               ldi param,20\r
+               rcall wait_time\r
+               ret\r
+\r
+\r
+\r
+pro_hb:\r
+               ldi ZL,low(pro_stable) \r
+               ldi ZH,high(pro_stable) \r
+               add ZL,mode \r
+               adc ZH,zero\r
+               icall\r
+               ret\r
+\r
+pro_stable: \r
+               rjmp pro_read_rom_command\r
+               rjmp pro_sleep \r
+               rjmp pro_match_rom\r
+               rjmp pro_search_rom_s\r
+               rjmp pro_search_rom_r\r
+               rjmp pro_read_command\r
+               rjmp pro_write_scratchpad\r
+               rjmp pro_read_scratchpad\r
+               rjmp pro_programm_page\r
+               rjmp pro_recall_flash\r
+\r
+pro_read_rom_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0xCC\r
+               brne pro_rcc_1\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+pro_rcc_1:\r
+               cpi rwbyte,0xF0 ;Searchrom\r
+               brne pro_rcc_2\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ld srbyte,X+\r
+               ldi bytep,0\r
+               rjmp pro_serchrom_next_bit\r
+pro_rcc_2:\r
+               cpi rwbyte,0x55 ;Matchrom\r
+               brne pro_rcc_3\r
+//             rcall pro_owidinit\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ldi mode,OWM_MATCH_ROM\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rcc_3:\r
+               ret\r
+\r
+pro_match_rom:         \r
+               ld temp,X+\r
+               cp temp,rwbyte\r
+               breq pro_match_rom_next\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_match_rom_next:                                    \r
+               cpi XL,SRAM_START+8\r
+               breq pro_match_rom_found\r
+               rjmp pro_out_bitp1\r
+pro_match_rom_found:\r
+           ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+\r
+pro_read_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0x0F ;; Write to Scratchpad\r
+               brne pro_rc_1\r
+               ldi mode,OWM_WRITE_SCRATCHPAD\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_1:\r
+               cpi rwbyte,0xAA\r
+               brne pro_rc_2\r
+               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               inc smode\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rc_2:\r
+               cpi rwbyte,0xB8\r
+               brne pro_rc_3\r
+               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_3:\r
+               cpi rwbyte,0x55 ; copy Scratchpad to Flash\r
+               brne pro_rc_4\r
+               ldi mode,OWM_SLEEP\r
+               rjmp pro_programm_page\r
+               \r
+pro_rc_4:\r
+               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware\r
+               brne pro_rc_5\r
+               rjmp jreset             \r
+pro_rc_5:\r
+               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1\r
+               brne pro_rc_6   \r
+               ldi temp,7\r
+pro_rc_5a:\r
+               ldi XL,low(E2END)\r
+               ldi XH,high(E2END)\r
+               sub XL,temp\r
+               out EEARH,XH\r
+               out EEARL,XL\r
+               ldi temp, (0<<EEPM1)|(0<<EEPM0)\r
+               out EECR, temp\r
+               ldi temp,0xFF\r
+               out EEDR, temp\r
+               sbi EECR, EEMPE\r
+               sbi EECR, EEPE\r
+               ret\r
+\r
+\r
+pro_rc_6:\r
+               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2\r
+               brne pro_rc_7\r
+               ldi temp,7+8\r
+               rjmp pro_rc_5a\r
+\r
+pro_rc_7:\r
+               ret\r
+\r
+pro_write_scratchpad:\r
+               st X+,rwbyte\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_write_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               ret             \r
+pro_write_scratchpad_next:\r
+               ldi bitp,1\r
+               ret\r
+\r
+pro_read_scratchpad:\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_read_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               clr smode\r
+               ret\r
+pro_read_scratchpad_next:\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bitp1\r
+\r
+\r
+pro_programm_page:\r
+.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words\r
+// .org SMALLBOOTSTART\r
+write_page:\r
+               ;transfer data from RAM to Flash page buffer\r
+               ldi bytep, PAGESIZEB ;init loop variable\r
+               ldi YL,low(scratchpad)  ;init sram pointer\r
+               ldi YH,high(scratchpad)\r
+               ld ZL,Y+\r
+               ld ZH,Y+\r
+               ;page erase\r
+               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)\r
+               rcall do_spm\r
+wrloop:\r
+               ld r0, Y+\r
+               ld r1, Y+\r
+               ldi spmcrval, (1<<SPMEN)\r
+               rcall do_spm\r
+               adiw ZH:ZL, 2\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne wrloop\r
+               ;execute page write\r
+               subi ZL, low(PAGESIZEB) ;restore pointer\r
+               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256\r
+               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)\r
+               rcall do_spm\r
+               ;read back and check, optional\r
+               ldi bytep, PAGESIZEB\r
+               subi YL, low(PAGESIZEB) ;restore pointer\r
+               sbci YH, high(PAGESIZEB)\r
+rdloop:\r
+               lpm r0, Z+\r
+               ld r1, Y+\r
+               cpse r0, r1\r
+               rjmp error\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne rdloop\r
+               ;return\r
+               ret\r
+do_spm:\r
+                ;input: spmcrval determines SPM action\r
+               ;disable interrupts if enabled, store status\r
+               in temp2, SREG\r
+               cli\r
+               ;check for previous SPM complete\r
+wait:\r
+               in temp, SPMCSR\r
+               sbrc temp, SPMEN\r
+               rjmp wait\r
+               ;SPM timed sequence\r
+               out SPMCSR, spmcrval\r
+               spm\r
+               ;restore SREG (to enable interrupts if originally enabled)\r
+               out SREG, temp2\r
+               ret\r
+\r
+error:\r
+\r
+\r
+               ret\r
+\r
+pro_recall_flash:\r
+               st X+,rwbyte\r
+               ;inc bytep\r
+               cpi XL,SRAM_START+8+2\r
+               brlo pro_out_bitp1;pro_recall_flash_next\r
+               lds ZL,scratchpad\r
+               lds ZH,scratchpad+1\r
+pro_recall_flash_cl:\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8+66\r
+               brne pro_recall_flash_cl\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+\r
+pro_out_read_command:\r
+               ldi mode,OWM_READ_COMMAND\r
+pro_out_bytep0:\r
+               ldi bytep,0\r
+pro_out_bitp1:\r
+               ldi bitp,1\r
+               ret             \r
+\r
+\r
+\r
+pro_serchrom_next_bit:\r
+               mov rwbyte,srbyte\r
+               mov temp2,rwbyte\r
+               com rwbyte\r
+               ror temp2  ;first bit in C\r
+               rol rwbyte ;C in first bit \r
+               inc smode\r
+               ldi bitp,0x40\r
+               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive\r
+               ret\r
+\r
+\r
+pro_search_rom_s:\r
+               clr temp2\r
+               lsr srbyte ;shift in C lowest bit\r
+               ror temp2  ; shift in temp2 as highest bit\r
+               andi rwbyte,0x80  ;  clear other bits\r
+               eor temp2,rwbyte\r
+               breq pro_search_rom_s_goon\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_search_rom_s_goon:\r
+               inc bytep\r
+               mov temp2,bytep\r
+               andi temp2,0x07\r
+               brne pro_serchrom_next_bit ;prepare next bit\r
+               mov temp2,bytep\r
+               andi temp2,0x40 ;;end\r
+               brne pro_search_rom_found\r
+               ;read next byte\r
+               ld srbyte,X+\r
+               rjmp pro_serchrom_next_bit\r
+\r
+pro_search_rom_found:\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bytep0\r
+\r
+pro_search_rom_r:\r
+               clr smode\r
+               ldi mode,OWM_SEARCH_ROM_S\r
+               ldi bitp,0  ;go to searchrom_s after bit get\r
+               ret\r
+\r
+pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA\r
+\r
+\r
+\r
+\r
+\r
+wait_time:\r
+               out TCNT0,zero\r
+wait_time1:\r
+               in temp,TCNT0\r
+               cp temp,param\r
+               brlo wait_time1\r
+               ret\r
+\r
+\r
+.DSEG\r
+sowid: .BYTE 8\r
 scratchpad: .BYTE 66
\ No newline at end of file
index 3bf5f2d..4ee3fa1 100644 (file)
-.def srbyte = r12  ;byty for search rom algorithm
-.def writelow = r13;  marker for send low
-.def zero =r14;  always zero 
-.def smode=r15; if 1 then send 
-.def temp = r16 ; 
-.def temp2 = r17; 
-.def mode = r18 ; 
-.def bitp = r19 ; bit counter ... shift...
-.def rwbyte = r21;
-.def param = r22;
-.def bytep = r23  ;byte counter
-#define spmcrval  param
-
-
-.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet
-.equ OWM_SLEEP=1 ; Warten auf Reset
-.equ OWM_MATCH_ROM=2
-.equ OWM_SEARCH_ROM_S=3  ;send bit
-.equ OWM_SEARCH_ROM_R=4  ;resive master
-.equ OWM_READ_COMMAND=5
-.equ OWM_WRITE_SCRATCHPAD=6
-.equ OWM_READ_SCRATCHPAD=7
-.equ OWM_PROGRAMM_PAGE=8
-.equ OWM_RECALL_FLASH=9
-
-
-.equ OW_DDR = DDRB 
-.equ OW_PIN = PORTB2
-.equ OW_PORT = PORTB 
-.equ OW_PINN = PINB 
-
-;.equ SRAM_START = 0x60
-
-.macro set_clock
-               ldi temp,0x80;
-               out CLKPR,temp
-               ldi temp,@0
-               out CLKPR,temp
-.endmacro 
-
-.macro owwl
-               sbic OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-.macro owwh
-               sbis OW_PINN,OW_PIN
-               rjmp pc-1
-.endmacro 
-
-
-
-
- ;---------------------------------------------------
-; START of PROG 
-;---------------------------------------------------
-
-
-.CSEG 
-.ORG 0x000
-jreset:
-               rjmp start ; Reset-Vector 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-               reti ; 
-
-
-.ORG 0x0EC0
-
-start: 
-               cli
-               ldi temp,0
-               mov zero,temp
-               set_clock 0x00 ;8mhz
-               ldi mode,OWM_SLEEP
-               ldi temp,(1<<CS01) //1us
-               out TCCR0B,temp
-               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse 
-               out SPH, temp 
-               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse 
-               out SPL, temp 
-               ;ldi temp,1
-               ;out DDRB,temp
-               clr writelow
-               clr bitp
-       
-               ;sbi PORTB,0
-               ldi ZL,low(pro_owid*2) 
-               ldi ZH,high(pro_owid*2) 
-               ldi XL,low(sowid)
-               ldi XH,high(sowid)
-               ;ldi temp2,8
-pro_copy_loop: ;copy ID on SRAM for better handling
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8
-               brlo pro_copy_loop
-pro_loop:
-               ;sbi PORTB,0
-               owwl                            ;wait for line goes low (polling)
-               sbrs writelow,0         ;test of zero send
-               rjmp pro_loop1          ;no ? goes next
-               sbi OW_DDR,OW_PIN       ;yes pull line to low
-               ldi param,50            ;wait for 50 us
-               rcall wait_time
-               clr writelow            ;reset write low indecator
-               cbi OW_DDR,OW_PIN   ;release line
-               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)
-pro_loop1:
-               tst smode                       ;smode=1 for slave sends to master
-               breq pro_loop_resv
-pro_loop_send:
-               tst bitp
-               brne pro_loop_send1
-               rcall pro_hb
-               tst smode
-               breq pro_loop_end ; now reading ... do nothing 
-pro_loop_send1:  ;prebare next bit
-               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command
-               inc writelow
-               lsl bitp
-               ror rwbyte
-               rjmp pro_loop_end
-
-pro_loop_resv:
-               ldi param,15  ;wait 15us
-               rcall wait_time
-               lsr rwbyte
-               ;cbi PORTB,0
-               sbic OW_PINN,OW_PIN  ;test line
-               ori rwbyte,0x80
-               lsl bitp
-               brne pro_loop_end ;no handle need
-               rcall pro_hb
-               tst smode
-               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....
-pro_loop_end:
-               //owwh
-               out TCNT0,zero
-pro_loop_end_test_reset:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               rjmp pro_loop
-               in temp,TCNT0
-               cpi temp,130
-               brlo pro_loop_end_test_reset
-               rcall pro_sleep_s2
-               rjmp pro_loop
-
-
-
-
-pro_sleep:
-               out TCNT0,zero
-pro_sleep_s1:
-               sbic OW_PINN,OW_PIN  //leitung wieder high
-               ret
-               in temp,TCNT0
-               cpi temp,200
-               brlo pro_sleep_s1
-               //leitung wieder high
-pro_sleep_s2:
-               owwh 
-               ldi param,40
-               rcall wait_time
-               //Presents Impuls
-               sbi OW_DDR,OW_PIN
-               ldi param,130
-               rcall wait_time
-               cbi OW_DDR,OW_PIN
-               //init read byte
-               ldi bitp,0x01
-               ldi rwbyte,0
-               clr smode
-               ldi mode,OWM_READ_ROM_COMMAND
-               //Wait for all other devices presents impuls finished
-               ldi param,40
-               rcall wait_time
-               ret
-
-
-
-pro_hb:
-               ldi ZL,low(pro_stable) 
-               ldi ZH,high(pro_stable) 
-               add ZL,mode 
-               adc ZH,zero
-               icall
-               ret
-
-pro_stable: 
-               rjmp pro_read_rom_command
-               rjmp pro_sleep 
-               rjmp pro_match_rom
-               rjmp pro_search_rom_s
-               rjmp pro_search_rom_r
-               rjmp pro_read_command
-               rjmp pro_write_scratchpad
-               rjmp pro_read_scratchpad
-               rjmp pro_programm_page
-               rjmp pro_recall_flash
-
-pro_read_rom_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0xCC
-               brne pro_rcc_1
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-pro_rcc_1:
-               cpi rwbyte,0xF0 ;Searchrom
-               brne pro_rcc_2
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ld srbyte,X+
-               ldi bytep,0
-               rjmp pro_serchrom_next_bit
-pro_rcc_2:
-               cpi rwbyte,0x55 ;Matchrom
-               brne pro_rcc_3
-//             rcall pro_owidinit
-               ldi XL,low(sowid)  ;init sram pointer
-               ldi XH,high(sowid)
-               ldi mode,OWM_MATCH_ROM
-               rjmp pro_out_bytep0
-
-pro_rcc_3:
-               ret
-
-pro_match_rom:         
-               ld temp,X+
-               cp temp,rwbyte
-               breq pro_match_rom_next
-               ldi mode,OWM_SLEEP
-               ret
-pro_match_rom_next:                                    
-               cpi XL,SRAM_START+8
-               breq pro_match_rom_found
-               rjmp pro_out_bitp1
-pro_match_rom_found:
-           ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bitp1
-
-pro_read_command:
-               ldi mode,OWM_SLEEP
-               cpi rwbyte,0x0F ;; Write to Scratchpad
-               brne pro_rc_1
-               ldi mode,OWM_WRITE_SCRATCHPAD
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_1:
-               cpi rwbyte,0xAA
-               brne pro_rc_2
-               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               inc smode
-               ld rwbyte,X+
-               rjmp pro_out_bytep0
-
-pro_rc_2:
-               cpi rwbyte,0xB8
-               brne pro_rc_3
-               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad
-               ldi XL,low(scratchpad)  ;init sram pointer
-               ldi XH,high(scratchpad)
-               rjmp pro_out_bytep0
-pro_rc_3:
-               cpi rwbyte,0x55 ; copy Scratchpad to Flash
-               brne pro_rc_4
-               ldi mode,OWM_SLEEP
-               rjmp pro_programm_page
-               
-pro_rc_4:
-               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware
-               brne pro_rc_5
-               rjmp jreset             
-pro_rc_5:
-               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1
-               brne pro_rc_6   
-               ldi temp,7
-pro_rc_5a:
-               ldi XL,low(E2END)
-               ldi XH,high(E2END)
-               sub XL,temp
-               out EEARH,XH
-               out EEARL,XL
-               ldi temp, (0<<EEPM1)|(0<<EEPM0)
-               out EECR, temp
-               ldi temp,0xFF
-               out EEDR, temp
-               sbi EECR, EEMPE
-               sbi EECR, EEPE
-               ret
-
-
-pro_rc_6:
-               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2
-               brne pro_rc_7
-               ldi temp,7+8
-               rjmp pro_rc_5a
-
-pro_rc_7:
-               ret
-
-pro_write_scratchpad:
-               st X+,rwbyte
-               cpi XL,SRAM_START+8+66
-               brlo pro_write_scratchpad_next
-               ldi mode,OWM_SLEEP
-               ret             
-pro_write_scratchpad_next:
-               ldi bitp,1
-               ret
-
-pro_read_scratchpad:
-               cpi XL,SRAM_START+8+66
-               brlo pro_read_scratchpad_next
-               ldi mode,OWM_SLEEP
-               clr smode
-               ret
-pro_read_scratchpad_next:
-               ld rwbyte,X+
-               rjmp pro_out_bitp1
-
-
-pro_programm_page:
-.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words
-// .org SMALLBOOTSTART
-write_page:
-               ;transfer data from RAM to Flash page buffer
-               ldi bytep, PAGESIZEB ;init loop variable
-               ldi YL,low(scratchpad)  ;init sram pointer
-               ldi YH,high(scratchpad)
-               ld ZL,Y+
-               ld ZH,Y+
-               ;page erase
-               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)
-               rcall do_spm
-wrloop:
-               ld r0, Y+
-               ld r1, Y+
-               ldi spmcrval, (1<<SPMEN)
-               rcall do_spm
-               adiw ZH:ZL, 2
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne wrloop
-               ;execute page write
-               subi ZL, low(PAGESIZEB) ;restore pointer
-               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256
-               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)
-               rcall do_spm
-               ;read back and check, optional
-               ldi bytep, PAGESIZEB
-               subi YL, low(PAGESIZEB) ;restore pointer
-               sbci YH, high(PAGESIZEB)
-rdloop:
-               lpm r0, Z+
-               ld r1, Y+
-               cpse r0, r1
-               rjmp error
-               subi bytep, 2;use subi for PAGESIZEB<=256
-               brne rdloop
-               ;return
-               ret
-do_spm:
-                ;input: spmcrval determines SPM action
-               ;disable interrupts if enabled, store status
-               in temp2, SREG
-               cli
-               ;check for previous SPM complete
-wait:
-               in temp, SPMCSR
-               sbrc temp, SPMEN
-               rjmp wait
-               ;SPM timed sequence
-               out SPMCSR, spmcrval
-               spm
-               ;restore SREG (to enable interrupts if originally enabled)
-               out SREG, temp2
-               ret
-
-error:
-
-
-               ret
-
-pro_recall_flash:
-               st X+,rwbyte
-               ;inc bytep
-               cpi XL,SRAM_START+8+2
-               brlo pro_out_bitp1;pro_recall_flash_next
-               lds ZL,scratchpad
-               lds ZH,scratchpad+1
-pro_recall_flash_cl:
-               lpm temp,Z+
-               st X+,temp
-               cpi XL,SRAM_START+8+66
-               brne pro_recall_flash_cl
-               ldi mode,OWM_SLEEP
-               ret
-
-pro_out_read_command:
-               ldi mode,OWM_READ_COMMAND
-pro_out_bytep0:
-               ldi bytep,0
-pro_out_bitp1:
-               ldi bitp,1
-               ret             
-
-
-
-pro_serchrom_next_bit:
-               mov rwbyte,srbyte
-               mov temp2,rwbyte
-               com rwbyte
-               ror temp2  ;first bit in C
-               rol rwbyte ;C in first bit 
-               inc smode
-               ldi bitp,0x40
-               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive
-               ret
-
-
-pro_search_rom_s:
-               clr temp2
-               lsr srbyte ;shift in C lowest bit
-               ror temp2  ; shift in temp2 as highest bit
-               andi rwbyte,0x80  ;  clear other bits
-               eor temp2,rwbyte
-               breq pro_search_rom_s_goon
-               ldi mode,OWM_SLEEP
-               ret
-pro_search_rom_s_goon:
-               inc bytep
-               mov temp2,bytep
-               andi temp2,0x07
-               brne pro_serchrom_next_bit ;prepare next bit
-               mov temp2,bytep
-               andi temp2,0x40 ;;end
-               brne pro_search_rom_found
-               ;read next byte
-               ld srbyte,X+
-               rjmp pro_serchrom_next_bit
-
-pro_search_rom_found:
-               ldi mode,OWM_READ_COMMAND
-               rjmp pro_out_bytep0
-
-pro_search_rom_r:
-               clr smode
-               ldi mode,OWM_SEARCH_ROM_S
-               ldi bitp,0  ;go to searchrom_s after bit get
-               ret
-
-pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA
-
-
-
-
-
-wait_time:
-               out TCNT0,zero
-wait_time1:
-               in temp,TCNT0
-               cp temp,param
-               brlo wait_time1
-               ret
-
-
-.DSEG
-sowid: .BYTE 8
+.def srbyte = r12  ;byty for search rom algorithm\r
+.def writelow = r13;  marker for send low\r
+.def zero =r14;  always zero \r
+.def smode=r15; if 1 then send \r
+.def temp = r16 ; \r
+.def temp2 = r17; \r
+.def mode = r18 ; \r
+.def bitp = r19 ; bit counter ... shift...\r
+.def rwbyte = r21;\r
+.def param = r22;\r
+.def bytep = r23  ;byte counter\r
+#define spmcrval  param\r
+\r
+\r
+.equ OWM_READ_ROM_COMMAND=0 ; 0 wegen schnellen test ist dieser wert 0! Daturch wird die Sprungdabelle nicht verwendet\r
+.equ OWM_SLEEP=1 ; Warten auf Reset\r
+.equ OWM_MATCH_ROM=2\r
+.equ OWM_SEARCH_ROM_S=3  ;send bit\r
+.equ OWM_SEARCH_ROM_R=4  ;resive master\r
+.equ OWM_READ_COMMAND=5\r
+.equ OWM_WRITE_SCRATCHPAD=6\r
+.equ OWM_READ_SCRATCHPAD=7\r
+.equ OWM_PROGRAMM_PAGE=8\r
+.equ OWM_RECALL_FLASH=9\r
+\r
+\r
+.equ OW_DDR = DDRB \r
+.equ OW_PIN = PORTB2\r
+.equ OW_PORT = PORTB \r
+.equ OW_PINN = PINB \r
+\r
+;.equ SRAM_START = 0x60\r
+\r
+.macro set_clock\r
+               ldi temp,0x80;\r
+               out CLKPR,temp\r
+               ldi temp,@0\r
+               out CLKPR,temp\r
+.endmacro \r
+\r
+.macro owwl\r
+               sbic OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+.macro owwh\r
+               sbis OW_PINN,OW_PIN\r
+               rjmp pc-1\r
+.endmacro \r
+\r
+\r
+\r
+\r
+ ;---------------------------------------------------\r
+; START of PROG \r
+;---------------------------------------------------\r
+\r
+\r
+.CSEG \r
+.ORG 0x000\r
+jreset:\r
+               rjmp start ; Reset-Vector \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+               reti ; \r
+\r
+\r
+.ORG 0x0EC0\r
+\r
+start: \r
+               cli\r
+               ldi temp,0\r
+               mov zero,temp\r
+               set_clock 0x00 ;8mhz\r
+               ldi mode,OWM_SLEEP\r
+               ldi temp,(1<<CS01) //1us\r
+               out TCCR0B,temp\r
+               ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse \r
+               out SPH, temp \r
+               ldi temp, LOW(RAMEND) ; LOW-Byte der obersten RAM-Adresse \r
+               out SPL, temp \r
+               ;ldi temp,1\r
+               ;out DDRB,temp\r
+               clr writelow\r
+               clr bitp\r
+       \r
+               ;sbi PORTB,0\r
+               ldi ZL,low(pro_owid*2) \r
+               ldi ZH,high(pro_owid*2) \r
+               ldi XL,low(sowid)\r
+               ldi XH,high(sowid)\r
+               ;ldi temp2,8\r
+pro_copy_loop: ;copy ID on SRAM for better handling\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8\r
+               brlo pro_copy_loop\r
+pro_loop:\r
+               ;sbi PORTB,0\r
+               owwl                            ;wait for line goes low (polling)\r
+               sbrs writelow,0         ;test of zero send\r
+               rjmp pro_loop1          ;no ? goes next\r
+               sbi OW_DDR,OW_PIN       ;yes pull line to low\r
+               ldi param,50            ;wait for 50 us\r
+               rcall wait_time\r
+               clr writelow            ;reset write low indecator\r
+               cbi OW_DDR,OW_PIN   ;release line\r
+               owwh                            ;wait for line is high (it can takes some time cause of the capacity of line)\r
+pro_loop1:\r
+               tst smode                       ;smode=1 for slave sends to master\r
+               breq pro_loop_resv\r
+pro_loop_send:\r
+               tst bitp\r
+               brne pro_loop_send1\r
+               rcall pro_hb\r
+               tst smode\r
+               breq pro_loop_end ; now reading ... do nothing \r
+pro_loop_send1:  ;prebare next bit\r
+               sbrs rwbyte ,0; if bit 0 set in rwbyte then skip next command\r
+               inc writelow\r
+               lsl bitp\r
+               ror rwbyte\r
+               rjmp pro_loop_end\r
+\r
+pro_loop_resv:\r
+               ldi param,15  ;wait 15us\r
+               rcall wait_time\r
+               lsr rwbyte\r
+               ;cbi PORTB,0\r
+               sbic OW_PINN,OW_PIN  ;test line\r
+               ori rwbyte,0x80\r
+               lsl bitp\r
+               brne pro_loop_end ;no handle need\r
+               rcall pro_hb\r
+               tst smode\r
+               brne pro_loop_send ; Nach dem Gelesen byte koennte gesendet werden muessen....\r
+pro_loop_end:\r
+               //owwh\r
+               out TCNT0,zero\r
+pro_loop_end_test_reset:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               rjmp pro_loop\r
+               in temp,TCNT0\r
+               cpi temp,130\r
+               brlo pro_loop_end_test_reset\r
+               rcall pro_sleep_s2\r
+               rjmp pro_loop\r
+\r
+\r
+\r
+\r
+pro_sleep:\r
+               out TCNT0,zero\r
+pro_sleep_s1:\r
+               sbic OW_PINN,OW_PIN  //leitung wieder high\r
+               ret\r
+               in temp,TCNT0\r
+               cpi temp,200\r
+               brlo pro_sleep_s1\r
+               //leitung wieder high\r
+pro_sleep_s2:\r
+               owwh \r
+               ldi param,40\r
+               rcall wait_time\r
+               //Presents Impuls\r
+               sbi OW_DDR,OW_PIN\r
+               ldi param,130\r
+               rcall wait_time\r
+               cbi OW_DDR,OW_PIN\r
+               //init read byte\r
+               ldi bitp,0x01\r
+               ldi rwbyte,0\r
+               clr smode\r
+               ldi mode,OWM_READ_ROM_COMMAND\r
+               //Wait for all other devices presents impuls finished\r
+               ldi param,40\r
+               rcall wait_time\r
+               ret\r
+\r
+\r
+\r
+pro_hb:\r
+               ldi ZL,low(pro_stable) \r
+               ldi ZH,high(pro_stable) \r
+               add ZL,mode \r
+               adc ZH,zero\r
+               icall\r
+               ret\r
+\r
+pro_stable: \r
+               rjmp pro_read_rom_command\r
+               rjmp pro_sleep \r
+               rjmp pro_match_rom\r
+               rjmp pro_search_rom_s\r
+               rjmp pro_search_rom_r\r
+               rjmp pro_read_command\r
+               rjmp pro_write_scratchpad\r
+               rjmp pro_read_scratchpad\r
+               rjmp pro_programm_page\r
+               rjmp pro_recall_flash\r
+\r
+pro_read_rom_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0xCC\r
+               brne pro_rcc_1\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+pro_rcc_1:\r
+               cpi rwbyte,0xF0 ;Searchrom\r
+               brne pro_rcc_2\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ld srbyte,X+\r
+               ldi bytep,0\r
+               rjmp pro_serchrom_next_bit\r
+pro_rcc_2:\r
+               cpi rwbyte,0x55 ;Matchrom\r
+               brne pro_rcc_3\r
+//             rcall pro_owidinit\r
+               ldi XL,low(sowid)  ;init sram pointer\r
+               ldi XH,high(sowid)\r
+               ldi mode,OWM_MATCH_ROM\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rcc_3:\r
+               ret\r
+\r
+pro_match_rom:         \r
+               ld temp,X+\r
+               cp temp,rwbyte\r
+               breq pro_match_rom_next\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_match_rom_next:                                    \r
+               cpi XL,SRAM_START+8\r
+               breq pro_match_rom_found\r
+               rjmp pro_out_bitp1\r
+pro_match_rom_found:\r
+           ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bitp1\r
+\r
+pro_read_command:\r
+               ldi mode,OWM_SLEEP\r
+               cpi rwbyte,0x0F ;; Write to Scratchpad\r
+               brne pro_rc_1\r
+               ldi mode,OWM_WRITE_SCRATCHPAD\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_1:\r
+               cpi rwbyte,0xAA\r
+               brne pro_rc_2\r
+               ldi mode,OWM_READ_SCRATCHPAD  ;;Read from Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               inc smode\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bytep0\r
+\r
+pro_rc_2:\r
+               cpi rwbyte,0xB8\r
+               brne pro_rc_3\r
+               ldi mode,OWM_RECALL_FLASH  ;; copy Flash page in Scratchpad\r
+               ldi XL,low(scratchpad)  ;init sram pointer\r
+               ldi XH,high(scratchpad)\r
+               rjmp pro_out_bytep0\r
+pro_rc_3:\r
+               cpi rwbyte,0x55 ; copy Scratchpad to Flash\r
+               brne pro_rc_4\r
+               ldi mode,OWM_SLEEP\r
+               rjmp pro_programm_page\r
+               \r
+pro_rc_4:\r
+               cpi rwbyte,0x89 ; Reset Device /Boot (new) Firmware\r
+               brne pro_rc_5\r
+               rjmp jreset             \r
+pro_rc_5:\r
+               cpi rwbyte,0x8B ; Clear the OWID saved in EEPROM / one ID1\r
+               brne pro_rc_6   \r
+               ldi temp,7\r
+pro_rc_5a:\r
+               ldi XL,low(E2END)\r
+               ldi XH,high(E2END)\r
+               sub XL,temp\r
+               out EEARH,XH\r
+               out EEARL,XL\r
+               ldi temp, (0<<EEPM1)|(0<<EEPM0)\r
+               out EECR, temp\r
+               ldi temp,0xFF\r
+               out EEDR, temp\r
+               sbi EECR, EEMPE\r
+               sbi EECR, EEPE\r
+               ret\r
+\r
+\r
+pro_rc_6:\r
+               cpi rwbyte,0x8C ; Clear the OWID saved in EEPROM / one ID2\r
+               brne pro_rc_7\r
+               ldi temp,7+8\r
+               rjmp pro_rc_5a\r
+\r
+pro_rc_7:\r
+               ret\r
+\r
+pro_write_scratchpad:\r
+               st X+,rwbyte\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_write_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               ret             \r
+pro_write_scratchpad_next:\r
+               ldi bitp,1\r
+               ret\r
+\r
+pro_read_scratchpad:\r
+               cpi XL,SRAM_START+8+66\r
+               brlo pro_read_scratchpad_next\r
+               ldi mode,OWM_SLEEP\r
+               clr smode\r
+               ret\r
+pro_read_scratchpad_next:\r
+               ld rwbyte,X+\r
+               rjmp pro_out_bitp1\r
+\r
+\r
+pro_programm_page:\r
+.equ PAGESIZEB = PAGESIZE*2;PAGESIZEB is page size in BYTES, not words\r
+// .org SMALLBOOTSTART\r
+write_page:\r
+               ;transfer data from RAM to Flash page buffer\r
+               ldi bytep, PAGESIZEB ;init loop variable\r
+               ldi YL,low(scratchpad)  ;init sram pointer\r
+               ldi YH,high(scratchpad)\r
+               ld ZL,Y+\r
+               ld ZH,Y+\r
+               ;page erase\r
+               ldi spmcrval, (1<<PGERS) + (1<<SPMEN)\r
+               rcall do_spm\r
+wrloop:\r
+               ld r0, Y+\r
+               ld r1, Y+\r
+               ldi spmcrval, (1<<SPMEN)\r
+               rcall do_spm\r
+               adiw ZH:ZL, 2\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne wrloop\r
+               ;execute page write\r
+               subi ZL, low(PAGESIZEB) ;restore pointer\r
+               sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256\r
+               ldi spmcrval, (1<<PGWRT) + (1<<SPMEN)\r
+               rcall do_spm\r
+               ;read back and check, optional\r
+               ldi bytep, PAGESIZEB\r
+               subi YL, low(PAGESIZEB) ;restore pointer\r
+               sbci YH, high(PAGESIZEB)\r
+rdloop:\r
+               lpm r0, Z+\r
+               ld r1, Y+\r
+               cpse r0, r1\r
+               rjmp error\r
+               subi bytep, 2;use subi for PAGESIZEB<=256\r
+               brne rdloop\r
+               ;return\r
+               ret\r
+do_spm:\r
+                ;input: spmcrval determines SPM action\r
+               ;disable interrupts if enabled, store status\r
+               in temp2, SREG\r
+               cli\r
+               ;check for previous SPM complete\r
+wait:\r
+               in temp, SPMCSR\r
+               sbrc temp, SPMEN\r
+               rjmp wait\r
+               ;SPM timed sequence\r
+               out SPMCSR, spmcrval\r
+               spm\r
+               ;restore SREG (to enable interrupts if originally enabled)\r
+               out SREG, temp2\r
+               ret\r
+\r
+error:\r
+\r
+\r
+               ret\r
+\r
+pro_recall_flash:\r
+               st X+,rwbyte\r
+               ;inc bytep\r
+               cpi XL,SRAM_START+8+2\r
+               brlo pro_out_bitp1;pro_recall_flash_next\r
+               lds ZL,scratchpad\r
+               lds ZH,scratchpad+1\r
+pro_recall_flash_cl:\r
+               lpm temp,Z+\r
+               st X+,temp\r
+               cpi XL,SRAM_START+8+66\r
+               brne pro_recall_flash_cl\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+\r
+pro_out_read_command:\r
+               ldi mode,OWM_READ_COMMAND\r
+pro_out_bytep0:\r
+               ldi bytep,0\r
+pro_out_bitp1:\r
+               ldi bitp,1\r
+               ret             \r
+\r
+\r
+\r
+pro_serchrom_next_bit:\r
+               mov rwbyte,srbyte\r
+               mov temp2,rwbyte\r
+               com rwbyte\r
+               ror temp2  ;first bit in C\r
+               rol rwbyte ;C in first bit \r
+               inc smode\r
+               ldi bitp,0x40\r
+               ldi mode,OWM_SEARCH_ROM_R  ;next mod Resive\r
+               ret\r
+\r
+\r
+pro_search_rom_s:\r
+               clr temp2\r
+               lsr srbyte ;shift in C lowest bit\r
+               ror temp2  ; shift in temp2 as highest bit\r
+               andi rwbyte,0x80  ;  clear other bits\r
+               eor temp2,rwbyte\r
+               breq pro_search_rom_s_goon\r
+               ldi mode,OWM_SLEEP\r
+               ret\r
+pro_search_rom_s_goon:\r
+               inc bytep\r
+               mov temp2,bytep\r
+               andi temp2,0x07\r
+               brne pro_serchrom_next_bit ;prepare next bit\r
+               mov temp2,bytep\r
+               andi temp2,0x40 ;;end\r
+               brne pro_search_rom_found\r
+               ;read next byte\r
+               ld srbyte,X+\r
+               rjmp pro_serchrom_next_bit\r
+\r
+pro_search_rom_found:\r
+               ldi mode,OWM_READ_COMMAND\r
+               rjmp pro_out_bytep0\r
+\r
+pro_search_rom_r:\r
+               clr smode\r
+               ldi mode,OWM_SEARCH_ROM_S\r
+               ldi bitp,0  ;go to searchrom_s after bit get\r
+               ret\r
+\r
+pro_owid: .DB  0xA3, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xFA\r
+\r
+\r
+\r
+\r
+\r
+wait_time:\r
+               out TCNT0,zero\r
+wait_time1:\r
+               in temp,TCNT0\r
+               cp temp,param\r
+               brlo wait_time1\r
+               ret\r
+\r
+\r
+.DSEG\r
+sowid: .BYTE 8\r
 scratchpad: .BYTE 66
\ No newline at end of file
index ea227d0..e4c2056 100644 (file)
@@ -1,74 +1,74 @@
-import math
-#Bezeichnungen:
-#r = relative Luftfeuchte
-#T = Temperatur in C
-#TK = Temperatur in Kelvin (TK = T + 273.15)
-#TD = Taupunkttemperatur in C
-#DD = Dampfdruck in hPa
-#SDD = Saettigungsdampfdruck in hPa
-
-#Parameter:
-#a = 7.5, b = 237.3 fuer T >= 0
-#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)
-#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)
-
-Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)
-mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)
-#AF = absolute Feuchte in g Wasserdampf pro m3 Luft
-
-#Formeln:
-
-#    SDD(T) = 6.1078 * 10^((a*T)/(b+T))
-#    DD(r,T) = r/100 * SDD(T)
-#    r(T,TD) = 100 * SDD(TD) / SDD(T)
-#    TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078)
-#    AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK
-
-
-a=7.5
-b=237.3
-
-#a=r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
-#r=a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)
-
-def SDD(T):
-       return 6.1078 * 10**((a*T)/(b+T))
-
-#def DD(r,T):
-#      return r/100 * SDD(T)
-
-#def _r(T,TD):
-#      return 100 * SDD(TD) / SDD(T)
-
-#def _v(r,T):
-#      return math.log10(DD(r,T)/6.1078)
-       
-#def TD(r,T):
-#      return b*v/(a-_v(r,T))  
-
-       
-#def AF(r,T):
-#      return 10000 * mw/Rs * DD(r,T)/(T+273.15) #; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK
-
-def AF1(r,T):
-       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
-
-def RF1(a,T):
-       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    
-#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)
-d=[]
-for i in range(11):
-       s=""
-       r=[]
-       for j in range(6):
-               r.append((i*10)-RF1(AF1(i*10,j*10),j*10+0.5))
-               s=s+"%0.2f\t" % (r[len(r)-1])
-       print(s)
-       d.append(r)
-       
-for i in range(11):
-       s=""
-       for j in range(5):
-               s=s+"%0.4f\t" % (d[i][j]-d[i][j+1])
-       print(s)
-               
+import math\r
+#Bezeichnungen:\r
+#r = relative Luftfeuchte\r
+#T = Temperatur in C\r
+#TK = Temperatur in Kelvin (TK = T + 273.15)\r
+#TD = Taupunkttemperatur in C\r
+#DD = Dampfdruck in hPa\r
+#SDD = Saettigungsdampfdruck in hPa\r
+\r
+#Parameter:\r
+#a = 7.5, b = 237.3 fuer T >= 0\r
+#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)\r
+#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)\r
+\r
+Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)\r
+mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)\r
+#AF = absolute Feuchte in g Wasserdampf pro m3 Luft\r
+\r
+#Formeln:\r
+\r
+#    SDD(T) = 6.1078 * 10^((a*T)/(b+T))\r
+#    DD(r,T) = r/100 * SDD(T)\r
+#    r(T,TD) = 100 * SDD(TD) / SDD(T)\r
+#    TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078)\r
+#    AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK\r
+\r
+\r
+a=7.5\r
+b=237.3\r
+\r
+#a=r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000\r
+#r=a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)\r
+\r
+def SDD(T):\r
+       return 6.1078 * 10**((a*T)/(b+T))\r
+\r
+#def DD(r,T):\r
+#      return r/100 * SDD(T)\r
+\r
+#def _r(T,TD):\r
+#      return 100 * SDD(TD) / SDD(T)\r
+\r
+#def _v(r,T):\r
+#      return math.log10(DD(r,T)/6.1078)\r
+       \r
+#def TD(r,T):\r
+#      return b*v/(a-_v(r,T))  \r
+\r
+       \r
+#def AF(r,T):\r
+#      return 10000 * mw/Rs * DD(r,T)/(T+273.15) #; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK\r
+\r
+def AF1(r,T):\r
+       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000\r
+\r
+def RF1(a,T):\r
+       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    \r
+#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)\r
+d=[]\r
+for i in range(11):\r
+       s=""\r
+       r=[]\r
+       for j in range(6):\r
+               r.append((i*10)-RF1(AF1(i*10,j*10),j*10+0.5))\r
+               s=s+"%0.2f\t" % (r[len(r)-1])\r
+       print(s)\r
+       d.append(r)\r
+       \r
+for i in range(11):\r
+       s=""\r
+       for j in range(5):\r
+               s=s+"%0.4f\t" % (d[i][j]-d[i][j+1])\r
+       print(s)\r
+               \r
index 5c28895..415ffe3 100644 (file)
-import sys
-import os
-import os.path
-import subprocess
-import io
-import time
-import math
-import shutil
-
-toolstr="/home/muto/owtools/src/owtools USB1 DC "
-devdict={}
-devwholist=[]
-f=open("DEVLIST.txt","r")
-for l in f.readlines():
-       ls=l.split(" ")
-       if (len(ls)>1):
-               devdict[ls[0]]=l.replace("\n","")
-               devwholist.append(ls[0])
-f.close()
-
-def id2string(id):
-       s=""
-       for i in range(8):
-               s=s+"%02X" %(id[7-i])
-       return s
-
-def string2id(s):
-       for i in range(8):
-               bl=[]
-               i2=14-i*2;
-               bl.append(int(s[i2:i2+2],16))
-       return bl
-
-
-def calculateValues(code, V, vn):
-       if code==1:
-               return V[vn] / 16.0; 
-       elif code==2:
-               return V[vn]/1.6; 
-       elif code==3:
-               return V[vn]*0.2 + 700; 
-       elif code==4:
-               return math.exp(V[vn] / 160.0); 
-       elif code==5:
-               return V[vn]*62.5 + 55000; 
-       elif code==6:
-               return V[vn] / 256.0; 
-       elif code==7:
-               if V[1]!=0:
-                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); 
-               else:
-                       return 0
-       elif code==8:
-               return V[vn] / 100.0; 
-       elif code==9:
-               return V[vn] / 65535.0*5.1; 
-       elif code==10:
-               return V[vn] / 65535.0*2.55; 
-       elif code==11:
-               return V[vn] / 65535.0*1.1; 
-       elif code==12:
-               return V[vn] / 10.0; 
-       elif code==13:
-               return V[vn];  
-       elif code==14:
-               return (V[vn] - 32767.0) / 100.0;  
-       elif code==15:
-               return math.exp((V[vn]-32767.0)/1000.0); 
-       elif code==16:
-               return V[vn]/32.0; 
-       else:
-               return 0;
-
-def getName(code       ):
-       if code==1:
-               return ["Temperatur","C"]
-       if code==2:
-               return ["Druck","hPa"]
-       if code==3:
-               return ["Beleuchtungsstaerke","lux"]
-       if code==4:
-               return ["Luftfeuchte","%%"]
-       if code==5:
-               return ["Konstante",""]
-       if code==6:
-               return ["Spannung","V"]
-       if code==7:
-               return ["Strom","mA"]
-       if code==8:
-               return ["VOC","ppm"]
-       if code==9:
-               return ["Counter",""]
-       return []
-
-
-def owCom(dev,send,rcount):
-       cmd=toolstr+id2string(dev)
-       #for i in range(8):
-       #       cmd=cmd+"%02X" %(dev[7-i])
-       cmd=cmd+" "
-       for b in send:
-               cmd=cmd+"%02X" % (b)
-       for i in range(rcount):
-               cmd=cmd+"FF"
-       #print(cmd.split(' '));
-       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read().decode("utf-8")
-       l=s.split("\n");
-       #print(l[2])
-       bl=[]
-       for i in range(int(len(l[2])/2)):
-               i2=i*2;
-               bl.append(int(l[2][i2:i2+2],16))
-       return bl
-
-def owComStr(dev,sendstr):
-       cmd=toolstr+id2string(dev)
-       #for i in range(8):
-       #       cmd=cmd+"%02X" %(dev[7-i])
-       cmd=cmd+" "+sendstr
-       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read().decode("utf-8")
-       #print(s);
-       ll=s.split("\n");
-       bll=[]
-       for l in ll[2:]:
-               bl=[]
-               for i in range(int(len(l)/2)):
-                       i2=i*2;
-                       bl.append(int(l[i2:i2+2],16))
-               bll.append(bl)
-       return bll
-
-def getValues(dev,voc):
-       pl=[]
-       #print(id2string(dev[0]),voc)
-       if dev[0][0]==0x26:
-               vnok=1
-               rc=0
-               while (vnok):
-                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
-                       #print(sbl)
-                       sb=sbl[4]
-                       VDD=(sb[5]+sb[6]*256)
-                       sb=sbl[8]
-                       VAD=(sb[5]+sb[6]*256)
-                       Temp=(sb[3]+sb[4]*256)
-                       if (sb[4] & 0x80):
-                               Temp-=0x10000
-                       curr=sb[7]+sb[8]*256
-                       if (sb[8] & 0x80):
-                               curr-=0x10000
-                       vals=[Temp,VDD,VAD,curr]
-                       formellist=[6,8,7,8]
-                       if dev[1][0]!=0xFF:
-                               formellist=[]
-                               for i in range(4):
-                                       if (dev[1][i*2+1])!=0:
-                                               formellist.append(dev[1][i*2+1])
-                                       else:
-                                               break
-                       cvals=[]
-                       for i in range(len(formellist)):
-                               cvals.append(calculateValues(formellist[i],vals,i))
-                       if (cvals[2]<=110):
-                               vnok=0
-                       else:
-                               rc=rc+1
-                               if (rc==3):
-                                       vnok=0
-                                       cvals[2]=100
-                       if voc!=0:
-                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
-                               sb=sbl[9]
-                               R0=(sb[2]+sb[3]*256)/100.0
-                               VS=(sb[4]+sb[5]*256)/10000.0
-                               Corr=(sb[7]+sb[8]*256)/1000.0
-                               cmode=sb[6]
-                               RS=(3/VS-1)*30
-                               RSR0=(RS/R0)
-                               VOC1=RSR0*Corr
-                               VOC2=RSR0/Corr
-                               cvals.append(R0)
-                               cvals.append(VS)
-                               cvals.append(Corr)
-                               cvals.append(cmode)
-                               cvals.append(RS)
-                               cvals.append(RSR0)
-                               cvals.append(VOC1)
-                               cvals.append(VOC2)
-               return cvals
-       if dev[0][0]==0x28:
-               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
-               Temp=sbl[1][1]+sbl[1][2]*256
-               if (sbl[1][2] & 0x80):
-                       Temp=-(Temp&0x7FFF)
-               if dev[1][0]!=0xFF:
-                       return [calculateValues(dev[1][1],[Temp],0)]
-               else:
-                       return [calculateValues(1,[Temp],0)]
-       return []
-
-       
-def owList(): 
-       cmd=toolstr[0:-3]
-       print(cmd)
-       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read()
-       l=s.split("\n")
-       #print(l);
-       l=l[1:-1]
-       devlist=[]
-       ic=0
-       for d in l:
-               dev=[]
-               bl=[]
-               for i in range(8):
-                       i2=14-i*2;
-                       bl.append(int(d[i2:i2+2],16))
-               dev.append(bl)
-               #print(bl)
-               config=owCom(bl,[0x85],18)
-               #print(config)
-               if (config[1]==0xFF):
-                       if (bl[0]==0x26):
-                               config=[0,1,6,6,8,4,7,7,8,0]
-                       if (bl[0]==0x28):
-                               config=[0,1,1,0,0,0,0,0,0,0]
-               dev.append(config[1:])
-               bls=id2string(bl)
-               cs="%i: " %(ic)
-               ic=ic+1
-               cs=cs+bls+": "
-               if bls in devdict:
-                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "
-               for i in range(4):
-                       c=config[i*2+1]
-                       if (c==0xFF):
-                               cs=cs+"Noconfig "
-                               if (bl[0]==0x26):
-                                       config=[0,1,6,6,8,4,7,7,8,0]
-                               if (bl[0]==0x28):
-                                       config=[0,1,1,0,0,0,0,0,0,0]
-                               break
-                       if (c==0):
-                               break
-                       cs=cs+getName(c)[0]+" "
-               voc=0
-               if bls in devdict:
-                       if "VOC" in devdict[bls]:
-                               voc=1
-               l=getValues([bl,config[1:]],voc)
-               for v in l:
-                       cs=cs+" %0.2f " %(v)
-               print(cs)
-               ddev=0
-               vm=0
-               if config[1]==0x08:
-                       vm=1
-               #print("Test_configs")
-               i=0
-               for dv in devlist:
-                       #print("c",dv[1][9:16])
-                       #print("d",bl[0:7])
-                       if dv[1][9:16]==bl[0:7]:
-                               print("Double Device")
-                               ddev=1
-                               dv.append(dev[0])
-                               dv.append(dev[1])
-                               #if vm==1:
-                                       #voc_marker[i]=2
-                       i=i+1
-               if ddev==0:
-                       devlist.append(dev)
-                       #voc_marker.append(vm)
-               #print("devlist",devlist)
-       return devlist
-
-dl=owList()
-#for d in dl:
-#      print(d)
-
-#while (1):
-#      for d in dl:
-#              ds=id2string(d[0])
-#              print(ds)
-               
-       
+import sys\r
+import os\r
+import os.path\r
+import subprocess\r
+import io\r
+import time\r
+import math\r
+import shutil\r
+\r
+toolstr="/home/muto/owtools/src/owtools USB1 DC "\r
+devdict={}\r
+devwholist=[]\r
+f=open("DEVLIST.txt","r")\r
+for l in f.readlines():\r
+       ls=l.split(" ")\r
+       if (len(ls)>1):\r
+               devdict[ls[0]]=l.replace("\n","")\r
+               devwholist.append(ls[0])\r
+f.close()\r
+\r
+def id2string(id):\r
+       s=""\r
+       for i in range(8):\r
+               s=s+"%02X" %(id[7-i])\r
+       return s\r
+\r
+def string2id(s):\r
+       for i in range(8):\r
+               bl=[]\r
+               i2=14-i*2;\r
+               bl.append(int(s[i2:i2+2],16))\r
+       return bl\r
+\r
+\r
+def calculateValues(code, V, vn):\r
+       if code==1:\r
+               return V[vn] / 16.0; \r
+       elif code==2:\r
+               return V[vn]/1.6; \r
+       elif code==3:\r
+               return V[vn]*0.2 + 700; \r
+       elif code==4:\r
+               return math.exp(V[vn] / 160.0); \r
+       elif code==5:\r
+               return V[vn]*62.5 + 55000; \r
+       elif code==6:\r
+               return V[vn] / 256.0; \r
+       elif code==7:\r
+               if V[1]!=0:\r
+                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); \r
+               else:\r
+                       return 0\r
+       elif code==8:\r
+               return V[vn] / 100.0; \r
+       elif code==9:\r
+               return V[vn] / 65535.0*5.1; \r
+       elif code==10:\r
+               return V[vn] / 65535.0*2.55; \r
+       elif code==11:\r
+               return V[vn] / 65535.0*1.1; \r
+       elif code==12:\r
+               return V[vn] / 10.0; \r
+       elif code==13:\r
+               return V[vn];  \r
+       elif code==14:\r
+               return (V[vn] - 32767.0) / 100.0;  \r
+       elif code==15:\r
+               return math.exp((V[vn]-32767.0)/1000.0); \r
+       elif code==16:\r
+               return V[vn]/32.0; \r
+       else:\r
+               return 0;\r
+\r
+def getName(code       ):\r
+       if code==1:\r
+               return ["Temperatur","C"]\r
+       if code==2:\r
+               return ["Druck","hPa"]\r
+       if code==3:\r
+               return ["Beleuchtungsstaerke","lux"]\r
+       if code==4:\r
+               return ["Luftfeuchte","%%"]\r
+       if code==5:\r
+               return ["Konstante",""]\r
+       if code==6:\r
+               return ["Spannung","V"]\r
+       if code==7:\r
+               return ["Strom","mA"]\r
+       if code==8:\r
+               return ["VOC","ppm"]\r
+       if code==9:\r
+               return ["Counter",""]\r
+       return []\r
+\r
+\r
+def owCom(dev,send,rcount):\r
+       cmd=toolstr+id2string(dev)\r
+       #for i in range(8):\r
+       #       cmd=cmd+"%02X" %(dev[7-i])\r
+       cmd=cmd+" "\r
+       for b in send:\r
+               cmd=cmd+"%02X" % (b)\r
+       for i in range(rcount):\r
+               cmd=cmd+"FF"\r
+       #print(cmd.split(' '));\r
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read().decode("utf-8")\r
+       l=s.split("\n");\r
+       #print(l[2])\r
+       bl=[]\r
+       for i in range(int(len(l[2])/2)):\r
+               i2=i*2;\r
+               bl.append(int(l[2][i2:i2+2],16))\r
+       return bl\r
+\r
+def owComStr(dev,sendstr):\r
+       cmd=toolstr+id2string(dev)\r
+       #for i in range(8):\r
+       #       cmd=cmd+"%02X" %(dev[7-i])\r
+       cmd=cmd+" "+sendstr\r
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read().decode("utf-8")\r
+       #print(s);\r
+       ll=s.split("\n");\r
+       bll=[]\r
+       for l in ll[2:]:\r
+               bl=[]\r
+               for i in range(int(len(l)/2)):\r
+                       i2=i*2;\r
+                       bl.append(int(l[i2:i2+2],16))\r
+               bll.append(bl)\r
+       return bll\r
+\r
+def getValues(dev,voc):\r
+       pl=[]\r
+       #print(id2string(dev[0]),voc)\r
+       if dev[0][0]==0x26:\r
+               vnok=1\r
+               rc=0\r
+               while (vnok):\r
+                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")\r
+                       #print(sbl)\r
+                       sb=sbl[4]\r
+                       VDD=(sb[5]+sb[6]*256)\r
+                       sb=sbl[8]\r
+                       VAD=(sb[5]+sb[6]*256)\r
+                       Temp=(sb[3]+sb[4]*256)\r
+                       if (sb[4] & 0x80):\r
+                               Temp-=0x10000\r
+                       curr=sb[7]+sb[8]*256\r
+                       if (sb[8] & 0x80):\r
+                               curr-=0x10000\r
+                       vals=[Temp,VDD,VAD,curr]\r
+                       formellist=[6,8,7,8]\r
+                       if dev[1][0]!=0xFF:\r
+                               formellist=[]\r
+                               for i in range(4):\r
+                                       if (dev[1][i*2+1])!=0:\r
+                                               formellist.append(dev[1][i*2+1])\r
+                                       else:\r
+                                               break\r
+                       cvals=[]\r
+                       for i in range(len(formellist)):\r
+                               cvals.append(calculateValues(formellist[i],vals,i))\r
+                       if (cvals[2]<=110):\r
+                               vnok=0\r
+                       else:\r
+                               rc=rc+1\r
+                               if (rc==3):\r
+                                       vnok=0\r
+                                       cvals[2]=100\r
+                       if voc!=0:\r
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2\r
+                               sb=sbl[9]\r
+                               R0=(sb[2]+sb[3]*256)/100.0\r
+                               VS=(sb[4]+sb[5]*256)/10000.0\r
+                               Corr=(sb[7]+sb[8]*256)/1000.0\r
+                               cmode=sb[6]\r
+                               RS=(3/VS-1)*30\r
+                               RSR0=(RS/R0)\r
+                               VOC1=RSR0*Corr\r
+                               VOC2=RSR0/Corr\r
+                               cvals.append(R0)\r
+                               cvals.append(VS)\r
+                               cvals.append(Corr)\r
+                               cvals.append(cmode)\r
+                               cvals.append(RS)\r
+                               cvals.append(RSR0)\r
+                               cvals.append(VOC1)\r
+                               cvals.append(VOC2)\r
+               return cvals\r
+       if dev[0][0]==0x28:\r
+               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")\r
+               Temp=sbl[1][1]+sbl[1][2]*256\r
+               if (sbl[1][2] & 0x80):\r
+                       Temp=-(Temp&0x7FFF)\r
+               if dev[1][0]!=0xFF:\r
+                       return [calculateValues(dev[1][1],[Temp],0)]\r
+               else:\r
+                       return [calculateValues(1,[Temp],0)]\r
+       return []\r
+\r
+       \r
+def owList(): \r
+       cmd=toolstr[0:-3]\r
+       print(cmd)\r
+       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read()\r
+       l=s.split("\n")\r
+       #print(l);\r
+       l=l[1:-1]\r
+       devlist=[]\r
+       ic=0\r
+       for d in l:\r
+               dev=[]\r
+               bl=[]\r
+               for i in range(8):\r
+                       i2=14-i*2;\r
+                       bl.append(int(d[i2:i2+2],16))\r
+               dev.append(bl)\r
+               #print(bl)\r
+               config=owCom(bl,[0x85],18)\r
+               #print(config)\r
+               if (config[1]==0xFF):\r
+                       if (bl[0]==0x26):\r
+                               config=[0,1,6,6,8,4,7,7,8,0]\r
+                       if (bl[0]==0x28):\r
+                               config=[0,1,1,0,0,0,0,0,0,0]\r
+               dev.append(config[1:])\r
+               bls=id2string(bl)\r
+               cs="%i: " %(ic)\r
+               ic=ic+1\r
+               cs=cs+bls+": "\r
+               if bls in devdict:\r
+                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "\r
+               for i in range(4):\r
+                       c=config[i*2+1]\r
+                       if (c==0xFF):\r
+                               cs=cs+"Noconfig "\r
+                               if (bl[0]==0x26):\r
+                                       config=[0,1,6,6,8,4,7,7,8,0]\r
+                               if (bl[0]==0x28):\r
+                                       config=[0,1,1,0,0,0,0,0,0,0]\r
+                               break\r
+                       if (c==0):\r
+                               break\r
+                       cs=cs+getName(c)[0]+" "\r
+               voc=0\r
+               if bls in devdict:\r
+                       if "VOC" in devdict[bls]:\r
+                               voc=1\r
+               l=getValues([bl,config[1:]],voc)\r
+               for v in l:\r
+                       cs=cs+" %0.2f " %(v)\r
+               print(cs)\r
+               ddev=0\r
+               vm=0\r
+               if config[1]==0x08:\r
+                       vm=1\r
+               #print("Test_configs")\r
+               i=0\r
+               for dv in devlist:\r
+                       #print("c",dv[1][9:16])\r
+                       #print("d",bl[0:7])\r
+                       if dv[1][9:16]==bl[0:7]:\r
+                               print("Double Device")\r
+                               ddev=1\r
+                               dv.append(dev[0])\r
+                               dv.append(dev[1])\r
+                               #if vm==1:\r
+                                       #voc_marker[i]=2\r
+                       i=i+1\r
+               if ddev==0:\r
+                       devlist.append(dev)\r
+                       #voc_marker.append(vm)\r
+               #print("devlist",devlist)\r
+       return devlist\r
+\r
+dl=owList()\r
+#for d in dl:\r
+#      print(d)\r
+\r
+#while (1):\r
+#      for d in dl:\r
+#              ds=id2string(d[0])\r
+#              print(ds)\r
+               \r
+       \r
        
\ No newline at end of file
index 323d6fa..70b3e17 100644 (file)
-import sys
-import os
-import os.path
-import subprocess
-import io
-import time
-import datetime
-import math
-import shutil
-
-toolstr="/home/muto/owtools/src/owtools USB1 DC "
-devdict={}
-devwholist=[]
-f=open("DEVLIST.txt","r")
-for l in f.readlines():
-       ls=l.split(" ")
-       if (len(ls)>1):
-               devdict[ls[0]]=l.replace("\n","")
-               devwholist.append(ls[0])
-f.close()
-
-def id2string(id):
-       s=""
-       for i in range(8):
-               s=s+"%02X" %(id[7-i])
-       return s
-
-def string2id(s):
-       for i in range(8):
-               bl=[]
-               i2=14-i*2;
-               bl.append(int(s[i2:i2+2],16))
-       return bl
-
-
-def calculateValues(code, V, vn):
-       if code==1:
-               return V[vn] / 16.0; 
-       elif code==2:
-               return V[vn]/1.6; 
-       elif code==3:
-               return V[vn]*0.2 + 700; 
-       elif code==4:
-               return math.exp(V[vn] / 160.0); 
-       elif code==5:
-               return V[vn]*62.5 + 55000; 
-       elif code==6:
-               return V[vn] / 256.0; 
-       elif code==7:
-               if V[1]!=0:
-                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); 
-               else:
-                       return 0
-       elif code==8:
-               return V[vn] / 100.0; 
-       elif code==9:
-               return V[vn] / 65535.0*5.1; 
-       elif code==10:
-               return V[vn] / 65535.0*2.55; 
-       elif code==11:
-               return V[vn] / 65535.0*1.1; 
-       elif code==12:
-               return V[vn] / 10.0; 
-       elif code==13:
-               return V[vn];  
-       elif code==14:
-               return (V[vn] - 32767.0) / 100.0;  
-       elif code==15:
-               return math.exp((V[vn]-32767.0)/1000.0); 
-       elif code==16:
-               return V[vn]/32.0; 
-       else:
-               return 0;
-
-def getName(code       ):
-       if code==1:
-               return ["Temperatur","C"]
-       if code==2:
-               return ["Druck","hPa"]
-       if code==3:
-               return ["Beleuchtungsstaerke","lux"]
-       if code==4:
-               return ["Luftfeuchte","%%"]
-       if code==5:
-               return ["Konstante",""]
-       if code==6:
-               return ["Spannung","V"]
-       if code==7:
-               return ["Strom","mA"]
-       if code==8:
-               return ["VOC","ppm"]
-       if code==9:
-               return ["Counter",""]
-       return []
-
-
-def owCom(dev,send,rcount):
-       cmd=toolstr+id2string(dev)
-       #for i in range(8):
-       #       cmd=cmd+"%02X" %(dev[7-i])
-       cmd=cmd+" "
-       for b in send:
-               cmd=cmd+"%02X" % (b)
-       for i in range(rcount):
-               cmd=cmd+"FF"
-       #print(cmd.split(' '));
-       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read().decode("utf-8")
-       l=s.split("\n");
-       #print(l[2])
-       bl=[]
-       for i in range(int(len(l[2])/2)):
-               i2=i*2;
-               bl.append(int(l[2][i2:i2+2],16))
-       return bl
-
-def owComStr(dev,sendstr):
-       cmd=toolstr+id2string(dev)
-       #for i in range(8):
-       #       cmd=cmd+"%02X" %(dev[7-i])
-       cmd=cmd+" "+sendstr
-       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read().decode("utf-8")
-       #print(s);
-       ll=s.split("\n");
-       bll=[]
-       for l in ll[2:]:
-               bl=[]
-               for i in range(int(len(l)/2)):
-                       i2=i*2;
-                       bl.append(int(l[i2:i2+2],16))
-               bll.append(bl)
-       return bll
-
-def getValues(dev,voc):
-       pl=[]
-       #print(id2string(dev[0]),voc)
-       if dev[0][0]==0x26:
-               vnok=1
-               rc=0
-               while (vnok):
-                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
-                       #print(sbl)
-                       sb=sbl[4]
-                       VDD=(sb[5]+sb[6]*256)
-                       sb=sbl[8]
-                       VAD=(sb[5]+sb[6]*256)
-                       Temp=(sb[3]+sb[4]*256)
-                       if (sb[4] & 0x80):
-                               Temp-=0x10000
-                       curr=sb[7]+sb[8]*256
-                       if (sb[8] & 0x80):
-                               curr-=0x10000
-                       vals=[Temp,VDD,VAD,curr]
-                       formellist=[6,8,7,8]
-                       if dev[1][0]!=0xFF:
-                               formellist=[]
-                               for i in range(4):
-                                       if (dev[1][i*2+1])!=0:
-                                               formellist.append(dev[1][i*2+1])
-                                       else:
-                                               break
-                       cvals=[]
-                       for i in range(len(formellist)):
-                               cvals.append(calculateValues(formellist[i],vals,i))
-                       if (cvals[2]<=110):
-                               vnok=0
-                       else:
-                               rc=rc+1
-                               if (rc==3):
-                                       vnok=0
-                                       cvals[2]=100
-                       if voc!=0:
-                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
-                               sb=sbl[9]
-                               R0=(sb[2]+sb[3]*256)/100.0
-                               VS=(sb[4]+sb[5]*256)/10000.0
-                               Corr=(sb[7]+sb[8]*256)/1000.0
-                               cmode=sb[6]
-                               RS=(3/VS-1)*30
-                               RSR0=(RS/R0)
-                               VOC1=RSR0*Corr
-                               VOC2=RSR0/Corr
-                               cvals.append(R0)
-                               cvals.append(VS)
-                               cvals.append(Corr)
-                               cvals.append(cmode)
-                               cvals.append(RS)
-                               cvals.append(RSR0)
-                               cvals.append(VOC1)
-                               cvals.append(VOC2)
-               return cvals
-       if dev[0][0]==0x28:
-               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
-               Temp=sbl[1][1]+sbl[1][2]*256
-               if (sbl[1][2] & 0x80):
-                       Temp=-(Temp&0x7FFF)
-               if dev[1][0]!=0xFF:
-                       return [calculateValues(dev[1][1],[Temp],0)]
-               else:
-                       return [calculateValues(1,[Temp],0)]
-       return []
-
-       
-def owList(): 
-       cmd=toolstr[0:-3]
-       print(cmd)
-       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-       p.wait()
-       s=p.stdout.read()
-       l=s.split("\n")
-       #print(l);
-       l=l[1:-1]
-       devlist=[]
-       ic=0
-       for d in l:
-               dev=[]
-               bl=[]
-               for i in range(8):
-                       i2=14-i*2;
-                       bl.append(int(d[i2:i2+2],16))
-               dev.append(bl)
-               #print(bl)
-               config=owCom(bl,[0x85],18)
-               #print(config)
-               if (config[1]==0xFF):
-                       if (bl[0]==0x26):
-                               config=[0,1,6,6,8,4,7,7,8,0]
-                       if (bl[0]==0x28):
-                               config=[0,1,1,0,0,0,0,0,0,0]
-               dev.append(config[1:])
-               bls=id2string(bl)
-               cs="%i: " %(ic)
-               ic=ic+1
-               cs=cs+bls+": "
-               if bls in devdict:
-                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "
-               for i in range(4):
-                       c=config[i*2+1]
-                       if (c==0xFF):
-                               cs=cs+"Noconfig "
-                               config=[0,0,0,0,0,0,0,0,0,0]
-                               break
-                       if (c==0):
-                               break
-                       cs=cs+getName(c)[0]+" "
-               #voc=0
-               #if bls in devdict:
-               #       if "VOC" in devdict[bls]:
-               #               voc=1
-               #l=getValues([bl,config[1:]],voc)
-               #for v in l:
-               #       cs=cs+" %0.2f " %(v)
-               print(cs)
-               ddev=0
-               vm=0
-               if config[1]==0x08:
-                       vm=1
-               #print("Test_configs")
-               i=0
-               for dv in devlist:
-                       #print("c",dv[1][9:16])
-                       #print("d",bl[0:7])
-                       if dv[1][9:16]==bl[0:7]:
-                               print("Double Device")
-                               ddev=1
-                               dv.append(dev[0])
-                               dv.append(dev[1])
-                               #if vm==1:
-                                       #voc_marker[i]=2
-                       i=i+1
-               #if ddev==0:
-               devlist.append(dev)
-                       #voc_marker.append(vm)
-               #print("devlist",devlist)
-       return devlist
-
-dl=owList()
-#for d in dl:
-#      print(d)
-
-while (1):
-       lt = time.localtime()
-       vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
-       n = datetime.datetime.now()
-       unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3
-       for d in dl:
-               ds=id2string(d[0])
-               bezeichnung="not in List"
-               if ds in devdict:
-                       bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" "
-               vnames=[]
-               for i in range(4):
-                       c=d[1][i*2]
-                       if (c==0):
-                               break
-                       name=getName(c)
-                       if name!=[]:
-                               vnames.append(name[0])
-               voc=0
-               if "VOC" in bezeichnung:
-                       voc=1
-                       vnames.append("R0")
-                       vnames.append("VS")
-                       vnames.append("Corr")
-                       vnames.append("cmode")
-                       vnames.append("RS")
-                       vnames.append("RSR0")
-                       vnames.append("VOC1")
-                       vnames.append("VOC2")
-               #print(ds)
-               l=getValues([d[0],d[1]],voc)
-               s=vline+"%i" %(unix_timestamp)
-               for i in range(len(l)):
-                       print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i]))
-                       s=s+"\t%0.4f" % (l[i])
-               fname="log_%s.ow1" %(ds)
-               writeheader=1
-               if os.path.exists(fname):
-                       writeheader=0
-               f=open(fname,"a")
-               if writeheader==1:
-                       sh="time\tunixtime"
-                       for i in range(len(l)):
-                               sh=sh+"\t%s" % (vnames[i])
-                       f.write(sh+"\n")
-               f.write(s.replace(".",",").replace("#",".")+"\n")
-               f.close()
-       #execfile("separate1.py")
-       os.system("python separate1.py")
-       print("--------------------")
-       n = datetime.datetime.now()
-       unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3
-       d=unix_timestamp1-unix_timestamp
-       print (d)
-       print("--------------------")
-       time.sleep(120-d)
-       
+import sys\r
+import os\r
+import os.path\r
+import subprocess\r
+import io\r
+import time\r
+import datetime\r
+import math\r
+import shutil\r
+\r
+toolstr="/home/muto/owtools/src/owtools USB1 DC "\r
+devdict={}\r
+devwholist=[]\r
+f=open("DEVLIST.txt","r")\r
+for l in f.readlines():\r
+       ls=l.split(" ")\r
+       if (len(ls)>1):\r
+               devdict[ls[0]]=l.replace("\n","")\r
+               devwholist.append(ls[0])\r
+f.close()\r
+\r
+def id2string(id):\r
+       s=""\r
+       for i in range(8):\r
+               s=s+"%02X" %(id[7-i])\r
+       return s\r
+\r
+def string2id(s):\r
+       for i in range(8):\r
+               bl=[]\r
+               i2=14-i*2;\r
+               bl.append(int(s[i2:i2+2],16))\r
+       return bl\r
+\r
+\r
+def calculateValues(code, V, vn):\r
+       if code==1:\r
+               return V[vn] / 16.0; \r
+       elif code==2:\r
+               return V[vn]/1.6; \r
+       elif code==3:\r
+               return V[vn]*0.2 + 700; \r
+       elif code==4:\r
+               return math.exp(V[vn] / 160.0); \r
+       elif code==5:\r
+               return V[vn]*62.5 + 55000; \r
+       elif code==6:\r
+               return V[vn] / 256.0; \r
+       elif code==7:\r
+               if V[1]!=0:\r
+                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); \r
+               else:\r
+                       return 0\r
+       elif code==8:\r
+               return V[vn] / 100.0; \r
+       elif code==9:\r
+               return V[vn] / 65535.0*5.1; \r
+       elif code==10:\r
+               return V[vn] / 65535.0*2.55; \r
+       elif code==11:\r
+               return V[vn] / 65535.0*1.1; \r
+       elif code==12:\r
+               return V[vn] / 10.0; \r
+       elif code==13:\r
+               return V[vn];  \r
+       elif code==14:\r
+               return (V[vn] - 32767.0) / 100.0;  \r
+       elif code==15:\r
+               return math.exp((V[vn]-32767.0)/1000.0); \r
+       elif code==16:\r
+               return V[vn]/32.0; \r
+       else:\r
+               return 0;\r
+\r
+def getName(code       ):\r
+       if code==1:\r
+               return ["Temperatur","C"]\r
+       if code==2:\r
+               return ["Druck","hPa"]\r
+       if code==3:\r
+               return ["Beleuchtungsstaerke","lux"]\r
+       if code==4:\r
+               return ["Luftfeuchte","%%"]\r
+       if code==5:\r
+               return ["Konstante",""]\r
+       if code==6:\r
+               return ["Spannung","V"]\r
+       if code==7:\r
+               return ["Strom","mA"]\r
+       if code==8:\r
+               return ["VOC","ppm"]\r
+       if code==9:\r
+               return ["Counter",""]\r
+       return []\r
+\r
+\r
+def owCom(dev,send,rcount):\r
+       cmd=toolstr+id2string(dev)\r
+       #for i in range(8):\r
+       #       cmd=cmd+"%02X" %(dev[7-i])\r
+       cmd=cmd+" "\r
+       for b in send:\r
+               cmd=cmd+"%02X" % (b)\r
+       for i in range(rcount):\r
+               cmd=cmd+"FF"\r
+       #print(cmd.split(' '));\r
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read().decode("utf-8")\r
+       l=s.split("\n");\r
+       #print(l[2])\r
+       bl=[]\r
+       for i in range(int(len(l[2])/2)):\r
+               i2=i*2;\r
+               bl.append(int(l[2][i2:i2+2],16))\r
+       return bl\r
+\r
+def owComStr(dev,sendstr):\r
+       cmd=toolstr+id2string(dev)\r
+       #for i in range(8):\r
+       #       cmd=cmd+"%02X" %(dev[7-i])\r
+       cmd=cmd+" "+sendstr\r
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read().decode("utf-8")\r
+       #print(s);\r
+       ll=s.split("\n");\r
+       bll=[]\r
+       for l in ll[2:]:\r
+               bl=[]\r
+               for i in range(int(len(l)/2)):\r
+                       i2=i*2;\r
+                       bl.append(int(l[i2:i2+2],16))\r
+               bll.append(bl)\r
+       return bll\r
+\r
+def getValues(dev,voc):\r
+       pl=[]\r
+       #print(id2string(dev[0]),voc)\r
+       if dev[0][0]==0x26:\r
+               vnok=1\r
+               rc=0\r
+               while (vnok):\r
+                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")\r
+                       #print(sbl)\r
+                       sb=sbl[4]\r
+                       VDD=(sb[5]+sb[6]*256)\r
+                       sb=sbl[8]\r
+                       VAD=(sb[5]+sb[6]*256)\r
+                       Temp=(sb[3]+sb[4]*256)\r
+                       if (sb[4] & 0x80):\r
+                               Temp-=0x10000\r
+                       curr=sb[7]+sb[8]*256\r
+                       if (sb[8] & 0x80):\r
+                               curr-=0x10000\r
+                       vals=[Temp,VDD,VAD,curr]\r
+                       formellist=[6,8,7,8]\r
+                       if dev[1][0]!=0xFF:\r
+                               formellist=[]\r
+                               for i in range(4):\r
+                                       if (dev[1][i*2+1])!=0:\r
+                                               formellist.append(dev[1][i*2+1])\r
+                                       else:\r
+                                               break\r
+                       cvals=[]\r
+                       for i in range(len(formellist)):\r
+                               cvals.append(calculateValues(formellist[i],vals,i))\r
+                       if (cvals[2]<=110):\r
+                               vnok=0\r
+                       else:\r
+                               rc=rc+1\r
+                               if (rc==3):\r
+                                       vnok=0\r
+                                       cvals[2]=100\r
+                       if voc!=0:\r
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2\r
+                               sb=sbl[9]\r
+                               R0=(sb[2]+sb[3]*256)/100.0\r
+                               VS=(sb[4]+sb[5]*256)/10000.0\r
+                               Corr=(sb[7]+sb[8]*256)/1000.0\r
+                               cmode=sb[6]\r
+                               RS=(3/VS-1)*30\r
+                               RSR0=(RS/R0)\r
+                               VOC1=RSR0*Corr\r
+                               VOC2=RSR0/Corr\r
+                               cvals.append(R0)\r
+                               cvals.append(VS)\r
+                               cvals.append(Corr)\r
+                               cvals.append(cmode)\r
+                               cvals.append(RS)\r
+                               cvals.append(RSR0)\r
+                               cvals.append(VOC1)\r
+                               cvals.append(VOC2)\r
+               return cvals\r
+       if dev[0][0]==0x28:\r
+               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")\r
+               Temp=sbl[1][1]+sbl[1][2]*256\r
+               if (sbl[1][2] & 0x80):\r
+                       Temp=-(Temp&0x7FFF)\r
+               if dev[1][0]!=0xFF:\r
+                       return [calculateValues(dev[1][1],[Temp],0)]\r
+               else:\r
+                       return [calculateValues(1,[Temp],0)]\r
+       return []\r
+\r
+       \r
+def owList(): \r
+       cmd=toolstr[0:-3]\r
+       print(cmd)\r
+       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
+       p.wait()\r
+       s=p.stdout.read()\r
+       l=s.split("\n")\r
+       #print(l);\r
+       l=l[1:-1]\r
+       devlist=[]\r
+       ic=0\r
+       for d in l:\r
+               dev=[]\r
+               bl=[]\r
+               for i in range(8):\r
+                       i2=14-i*2;\r
+                       bl.append(int(d[i2:i2+2],16))\r
+               dev.append(bl)\r
+               #print(bl)\r
+               config=owCom(bl,[0x85],18)\r
+               #print(config)\r
+               if (config[1]==0xFF):\r
+                       if (bl[0]==0x26):\r
+                               config=[0,1,6,6,8,4,7,7,8,0]\r
+                       if (bl[0]==0x28):\r
+                               config=[0,1,1,0,0,0,0,0,0,0]\r
+               dev.append(config[1:])\r
+               bls=id2string(bl)\r
+               cs="%i: " %(ic)\r
+               ic=ic+1\r
+               cs=cs+bls+": "\r
+               if bls in devdict:\r
+                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "\r
+               for i in range(4):\r
+                       c=config[i*2+1]\r
+                       if (c==0xFF):\r
+                               cs=cs+"Noconfig "\r
+                               config=[0,0,0,0,0,0,0,0,0,0]\r
+                               break\r
+                       if (c==0):\r
+                               break\r
+                       cs=cs+getName(c)[0]+" "\r
+               #voc=0\r
+               #if bls in devdict:\r
+               #       if "VOC" in devdict[bls]:\r
+               #               voc=1\r
+               #l=getValues([bl,config[1:]],voc)\r
+               #for v in l:\r
+               #       cs=cs+" %0.2f " %(v)\r
+               print(cs)\r
+               ddev=0\r
+               vm=0\r
+               if config[1]==0x08:\r
+                       vm=1\r
+               #print("Test_configs")\r
+               i=0\r
+               for dv in devlist:\r
+                       #print("c",dv[1][9:16])\r
+                       #print("d",bl[0:7])\r
+                       if dv[1][9:16]==bl[0:7]:\r
+                               print("Double Device")\r
+                               ddev=1\r
+                               dv.append(dev[0])\r
+                               dv.append(dev[1])\r
+                               #if vm==1:\r
+                                       #voc_marker[i]=2\r
+                       i=i+1\r
+               #if ddev==0:\r
+               devlist.append(dev)\r
+                       #voc_marker.append(vm)\r
+               #print("devlist",devlist)\r
+       return devlist\r
+\r
+dl=owList()\r
+#for d in dl:\r
+#      print(d)\r
+\r
+while (1):\r
+       lt = time.localtime()\r
+       vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)\r
+       n = datetime.datetime.now()\r
+       unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3\r
+       for d in dl:\r
+               ds=id2string(d[0])\r
+               bezeichnung="not in List"\r
+               if ds in devdict:\r
+                       bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" "\r
+               vnames=[]\r
+               for i in range(4):\r
+                       c=d[1][i*2]\r
+                       if (c==0):\r
+                               break\r
+                       name=getName(c)\r
+                       if name!=[]:\r
+                               vnames.append(name[0])\r
+               voc=0\r
+               if "VOC" in bezeichnung:\r
+                       voc=1\r
+                       vnames.append("R0")\r
+                       vnames.append("VS")\r
+                       vnames.append("Corr")\r
+                       vnames.append("cmode")\r
+                       vnames.append("RS")\r
+                       vnames.append("RSR0")\r
+                       vnames.append("VOC1")\r
+                       vnames.append("VOC2")\r
+               #print(ds)\r
+               l=getValues([d[0],d[1]],voc)\r
+               s=vline+"%i" %(unix_timestamp)\r
+               for i in range(len(l)):\r
+                       print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i]))\r
+                       s=s+"\t%0.4f" % (l[i])\r
+               fname="log_%s.ow1" %(ds)\r
+               writeheader=1\r
+               if os.path.exists(fname):\r
+                       writeheader=0\r
+               f=open(fname,"a")\r
+               if writeheader==1:\r
+                       sh="time\tunixtime"\r
+                       for i in range(len(l)):\r
+                               sh=sh+"\t%s" % (vnames[i])\r
+                       f.write(sh+"\n")\r
+               f.write(s.replace(".",",").replace("#",".")+"\n")\r
+               f.close()\r
+       #execfile("separate1.py")\r
+       os.system("python separate1.py")\r
+       print("--------------------")\r
+       n = datetime.datetime.now()\r
+       unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3\r
+       d=unix_timestamp1-unix_timestamp\r
+       print (d)\r
+       print("--------------------")\r
+       time.sleep(120-d)\r
+       \r
        
\ No newline at end of file
index bffda77..b1c2871 100644 (file)
-import sys
-import os
-import os.path
-import subprocess
-import io
-import time
-import math
-import shutil
-import datetime
-
-
-#Parameter:
-#a = 7.5, b = 237.3 fuer T >= 0
-#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)
-#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)
-a=7.5
-b=237.3
-Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)
-mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)
-
-def SDD(T):
-       return 6.1078 * 10**((a*T)/(b+T))
-       
-def AF1(r,T):
-       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
-
-def RF1(a,T):
-       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    
-#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)
-
-def rdiff(r1,t1,t2):
-       return (r1)-RF1(AF1(r1,t1),t2)
-
-
-def calcDerivation(Name,Valuetype,Value,T):
-       return [0.5,0.5]
-
-
-devdict={}
-devwholist=[]
-f=open("DEVLIST.txt","r")
-for l in f.readlines():
-       ls=l.split(" ")
-       if (len(ls)>1):
-               devdict[ls[0]]=l.replace("\n","").split(",")[0].split(" ")[1]
-               devwholist.append(ls[0])
-f.close()
-
-sel_list=["Temperatur","Luftfeuchte","Beleuchtungsstaerke","R0","VOC","RS","Corr"]
-data=[]
-for s in sel_list:
-       data.append(["Time"])
-
-for ds in devwholist:   #fuer Jedes Geraet in DEVLIST.txt
-       fname="log_%s.ow1" %(ds)  #Sind Daten da?
-       if os.path.exists(fname):
-               f=open(fname,"r")  #Lesen
-               lines=f.readlines()
-               ti=lines[0][:-1].split("\t")  #Ueberschriften aufteilen
-               i=0
-               if ("Temperatur" in ti):
-                       tempindex=ti.index("Temperatur")
-               for t in ti:   #fuer jedes Element in der Ueberschrift
-                       if t in sel_list:  #schauen ob es Uebernommen werden soll
-                               p=sel_list.index(t)  #schaue nach Nummer in der Datenbank
-                               data[p][0]=data[p][0]+","+ds+" "+devdict[ds] #hinzufuegen der Ueberschrift in der Tabelle
-                               if len(data[p])==1: #erstes Element, Time einfuegen und neue zeile anlegen
-                                       for l in lines[1:]:
-                                               l=l[:-1]
-                                               ll=l.split("\t")
-                                               la=ll[0].split(" ")
-                                               lb=la[0].split(".")
-                                               ts=lb[2]+"/"+lb[1]+"/"+lb[0]+" "+la[1]
-                                               data[p].append(ts)
-                               j=1;
-                               for l in lines[1:]:
-                                       #print(ll)
-                                       l=l[:-1] #\n wegmachen
-                                       ll=l.split("\t") #telen
-                                       fl=float(ll[i].replace(",","."))
-                                       if "VOC" in devdict[ds] or "Lum" in devdict[ds]:
-                                               if (t=="Temperatur"):
-                                                       ltemp=fl
-                                                       fl=fl-1
-                                               if (t=="Luftfeuchte"):
-                                                       ltemp=float(ll[tempindex].replace(",","."))
-                                                       fl=fl-rdiff(fl,ltemp,ltemp-1)
-                                       data[p][j]=data[p][j]+",%0.2f" % (fl)
-                                       j=j+1
-                       i=i+1
-               f.close()               
-                        
-       
-#print data
-
-for i in range(len(sel_list)):
-       f=open("/var/www/html/"+sel_list[i]+".csv","w")
-       for l in data[i]:
-               f.write(l+"\n")
-       f.close()
-
-       
-
+import sys\r
+import os\r
+import os.path\r
+import subprocess\r
+import io\r
+import time\r
+import math\r
+import shutil\r
+import datetime\r
+\r
+\r
+#Parameter:\r
+#a = 7.5, b = 237.3 fuer T >= 0\r
+#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)\r
+#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)\r
+a=7.5\r
+b=237.3\r
+Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)\r
+mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)\r
+\r
+def SDD(T):\r
+       return 6.1078 * 10**((a*T)/(b+T))\r
+       \r
+def AF1(r,T):\r
+       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000\r
+\r
+def RF1(a,T):\r
+       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    \r
+#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)\r
+\r
+def rdiff(r1,t1,t2):\r
+       return (r1)-RF1(AF1(r1,t1),t2)\r
+\r
+\r
+def calcDerivation(Name,Valuetype,Value,T):\r
+       return [0.5,0.5]\r
+\r
+\r
+devdict={}\r
+devwholist=[]\r
+f=open("DEVLIST.txt","r")\r
+for l in f.readlines():\r
+       ls=l.split(" ")\r
+       if (len(ls)>1):\r
+               devdict[ls[0]]=l.replace("\n","").split(",")[0].split(" ")[1]\r
+               devwholist.append(ls[0])\r
+f.close()\r
+\r
+sel_list=["Temperatur","Luftfeuchte","Beleuchtungsstaerke","R0","VOC","RS","Corr"]\r
+data=[]\r
+for s in sel_list:\r
+       data.append(["Time"])\r
+\r
+for ds in devwholist:   #fuer Jedes Geraet in DEVLIST.txt\r
+       fname="log_%s.ow1" %(ds)  #Sind Daten da?\r
+       if os.path.exists(fname):\r
+               f=open(fname,"r")  #Lesen\r
+               lines=f.readlines()\r
+               ti=lines[0][:-1].split("\t")  #Ueberschriften aufteilen\r
+               i=0\r
+               if ("Temperatur" in ti):\r
+                       tempindex=ti.index("Temperatur")\r
+               for t in ti:   #fuer jedes Element in der Ueberschrift\r
+                       if t in sel_list:  #schauen ob es Uebernommen werden soll\r
+                               p=sel_list.index(t)  #schaue nach Nummer in der Datenbank\r
+                               data[p][0]=data[p][0]+","+ds+" "+devdict[ds] #hinzufuegen der Ueberschrift in der Tabelle\r
+                               if len(data[p])==1: #erstes Element, Time einfuegen und neue zeile anlegen\r
+                                       for l in lines[1:]:\r
+                                               l=l[:-1]\r
+                                               ll=l.split("\t")\r
+                                               la=ll[0].split(" ")\r
+                                               lb=la[0].split(".")\r
+                                               ts=lb[2]+"/"+lb[1]+"/"+lb[0]+" "+la[1]\r
+                                               data[p].append(ts)\r
+                               j=1;\r
+                               for l in lines[1:]:\r
+                                       #print(ll)\r
+                                       l=l[:-1] #\n wegmachen\r
+                                       ll=l.split("\t") #telen\r
+                                       fl=float(ll[i].replace(",","."))\r
+                                       if "VOC" in devdict[ds] or "Lum" in devdict[ds]:\r
+                                               if (t=="Temperatur"):\r
+                                                       ltemp=fl\r
+                                                       fl=fl-1\r
+                                               if (t=="Luftfeuchte"):\r
+                                                       ltemp=float(ll[tempindex].replace(",","."))\r
+                                                       fl=fl-rdiff(fl,ltemp,ltemp-1)\r
+                                       data[p][j]=data[p][j]+",%0.2f" % (fl)\r
+                                       j=j+1\r
+                       i=i+1\r
+               f.close()               \r
+                        \r
+       \r
+#print data\r
+\r
+for i in range(len(sel_list)):\r
+       f=open("/var/www/html/"+sel_list[i]+".csv","w")\r
+       for l in data[i]:\r
+               f.write(l+"\n")\r
+       f.close()\r
+\r
+       \r
+\r
index 16df8ea..367c2e9 100644 (file)
Binary files a/tools_cmd/owtools.sdf and b/tools_cmd/owtools.sdf differ
index 50196c8..a00b8e7 100644 (file)
@@ -1,22 +1,22 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30501.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rwOW", "rwOW\rwOW.vcxproj", "{5D2435E4-D963-4533-AC3B-C4E0F2C251DB}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|Win32 = Debug|Win32
-               Release|Win32 = Release|Win32
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.ActiveCfg = Debug|Win32
-               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.Build.0 = Debug|Win32
-               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.ActiveCfg = Release|Win32
-               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.Build.0 = Release|Win32
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\r
+Microsoft Visual Studio Solution File, Format Version 12.00\r
+# Visual Studio 2013\r
+VisualStudioVersion = 12.0.30501.0\r
+MinimumVisualStudioVersion = 10.0.40219.1\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rwOW", "rwOW\rwOW.vcxproj", "{5D2435E4-D963-4533-AC3B-C4E0F2C251DB}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|Win32 = Debug|Win32\r
+               Release|Win32 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.Build.0 = Debug|Win32\r
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.ActiveCfg = Release|Win32\r
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index 7ae13cb..cf1bef8 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//--------------------------------------------------------------------------
-//
-//  crcutil.c - Keeps track of the CRC for 16 and 8 bit operations
-//  version 2.00
-
-// Include files
-#include "ownet.h"
-
-// Local global variables
-ushort utilcrc16[MAX_PORTNUM];
-uchar utilcrc8[MAX_PORTNUM];
-static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
-static uchar dscrc_table[] = {
-        0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
-      157,195, 33,127,252,162, 64, 30, 95,  1,227,189, 62, 96,130,220,
-       35,125,159,193, 66, 28,254,160,225,191, 93,  3,128,222, 60, 98,
-      190,224,  2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
-       70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89,  7,
-      219,133,103, 57,186,228,  6, 88, 25, 71,165,251,120, 38,196,154,
-      101, 59,217,135,  4, 90,184,230,167,249, 27, 69,198,152,122, 36,
-      248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91,  5,231,185,
-      140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
-       17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
-      175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
-       50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
-      202,148,118, 40,171,245, 23, 73,  8, 86,180,234,105, 55,213,139,
-       87,  9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
-      233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
-      116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
-
-//--------------------------------------------------------------------------
-// Reset crc16 to the value passed in
-//
-// 'reset' - data to set crc16 to.
-//
-void setcrc16(int portnum, ushort reset)
-{
-   utilcrc16[portnum&0x0FF] = reset;
-   return;
-}
-
-//--------------------------------------------------------------------------
-// Reset crc8 to the value passed in
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
-//              indicate the symbolic port number.
-// 'reset'    - data to set crc8 to
-//
-void setcrc8(int portnum, uchar reset)
-{
-   utilcrc8[portnum&0x0FF] = reset;
-   return;
-}
-
-//--------------------------------------------------------------------------
-// Calculate a new CRC16 from the input data short.  Return the current
-// CRC16 and also update the global variable CRC16.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
-//              indicate the symbolic port number.
-// 'data'     - data to perform a CRC16 on
-//
-// Returns: the current CRC16
-//
-ushort docrc16(int portnum, ushort cdata)
-{
-   cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff;
-   utilcrc16[portnum&0x0FF] >>= 8;
-
-   if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
-     utilcrc16[portnum&0x0FF] ^= 0xc001;
-
-   cdata <<= 6;
-   utilcrc16[portnum&0x0FF]   ^= cdata;
-   cdata <<= 1;
-   utilcrc16[portnum&0x0FF]   ^= cdata;
-
-   return utilcrc16[portnum&0x0FF];
-}
-
-//--------------------------------------------------------------------------
-// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global
-// variable utilcrc8 and the argument.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
-//              indicate the symbolic port number.
-// 'x'        - data byte to calculate the 8 bit crc from
-//
-// Returns: the updated utilcrc8.
-//
-uchar docrc8(int portnum, uchar x)
-{
-   utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x];
-   return utilcrc8[portnum&0x0FF];
-}
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//--------------------------------------------------------------------------\r
+//\r
+//  crcutil.c - Keeps track of the CRC for 16 and 8 bit operations\r
+//  version 2.00\r
+\r
+// Include files\r
+#include "ownet.h"\r
+\r
+// Local global variables\r
+ushort utilcrc16[MAX_PORTNUM];\r
+uchar utilcrc8[MAX_PORTNUM];\r
+static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };\r
+static uchar dscrc_table[] = {\r
+        0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,\r
+      157,195, 33,127,252,162, 64, 30, 95,  1,227,189, 62, 96,130,220,\r
+       35,125,159,193, 66, 28,254,160,225,191, 93,  3,128,222, 60, 98,\r
+      190,224,  2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,\r
+       70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89,  7,\r
+      219,133,103, 57,186,228,  6, 88, 25, 71,165,251,120, 38,196,154,\r
+      101, 59,217,135,  4, 90,184,230,167,249, 27, 69,198,152,122, 36,\r
+      248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91,  5,231,185,\r
+      140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,\r
+       17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,\r
+      175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,\r
+       50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,\r
+      202,148,118, 40,171,245, 23, 73,  8, 86,180,234,105, 55,213,139,\r
+       87,  9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,\r
+      233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,\r
+      116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset crc16 to the value passed in\r
+//\r
+// 'reset' - data to set crc16 to.\r
+//\r
+void setcrc16(int portnum, ushort reset)\r
+{\r
+   utilcrc16[portnum&0x0FF] = reset;\r
+   return;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset crc8 to the value passed in\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//              indicate the symbolic port number.\r
+// 'reset'    - data to set crc8 to\r
+//\r
+void setcrc8(int portnum, uchar reset)\r
+{\r
+   utilcrc8[portnum&0x0FF] = reset;\r
+   return;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Calculate a new CRC16 from the input data short.  Return the current\r
+// CRC16 and also update the global variable CRC16.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//              indicate the symbolic port number.\r
+// 'data'     - data to perform a CRC16 on\r
+//\r
+// Returns: the current CRC16\r
+//\r
+ushort docrc16(int portnum, ushort cdata)\r
+{\r
+   cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff;\r
+   utilcrc16[portnum&0x0FF] >>= 8;\r
+\r
+   if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])\r
+     utilcrc16[portnum&0x0FF] ^= 0xc001;\r
+\r
+   cdata <<= 6;\r
+   utilcrc16[portnum&0x0FF]   ^= cdata;\r
+   cdata <<= 1;\r
+   utilcrc16[portnum&0x0FF]   ^= cdata;\r
+\r
+   return utilcrc16[portnum&0x0FF];\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global\r
+// variable utilcrc8 and the argument.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//              indicate the symbolic port number.\r
+// 'x'        - data byte to calculate the 8 bit crc from\r
+//\r
+// Returns: the updated utilcrc8.\r
+//\r
+uchar docrc8(int portnum, uchar x)\r
+{\r
+   utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x];\r
+   return utilcrc8[portnum&0x0FF];\r
+}\r
index 6c1bfbe..8729c7c 100644 (file)
-/*---------------------------------------------------------------------------
-* Copyright Â© 1992-2008 Maxim Integrated Products, All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included
-* in all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-* IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
-* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-* OTHER DEALINGS IN THE SOFTWARE.
-*
-* Except as contained in this notice, the name of Maxim Integrated Products
-* shall not be used except as stated in the Maxim Integrated Products
-* Branding Policy.
-*---------------------------------------------------------------------------
-* Version 4.01
-*/
-
-/* includes */
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <windows.h>
-#ifndef _WIN32_WCE
-#include <stdio.h>
-#include <conio.h>
-#include <dos.h>
-#include <fcntl.h>
-#include <io.h>
-#include <time.h>
-#endif
-
-/* type defs */
-typedef unsigned char uchar;
-typedef unsigned short ushort;
-typedef unsigned long ulong;
-
-/* typedef structure sent back by TMEX routines */
-typedef struct 
-{
-uchar name[4];
-uchar extension;
-uchar startpage;
-uchar numpages;
-uchar attrib;
-uchar bitmap[32];
-} FileEntry;
-
-/* structure to hold directory path */
-typedef struct
-{
-uchar NumEntries; /* number of entries in path 0-10 */
-char Ref; /* reference character '\' or '.' */
-char Entries[10][4]; /* sub-directory entry names */ 
-} DirectoryPath;
-
-/* Holds info of each object in the Directory list */
-struct DirNumInfo 
-{ 
-unsigned char Name[4];
-unsigned char Extension;
-char Attrib;
-};
-
-/* structure to hold exportable device parameters by family code (3.11) */
-typedef struct
-{
-short features[32];
-char dscrptn[255];
-} Specification;
-
-
-/* Error codes from TMEX functions */
-#define NO_DEVICE -1 
-#define WRONG_TYPE -2 
-#define FILE_READ_ERR -3 
-#define BUFFER_TOO_SMALL -4 
-#define HANDLE_NOT_AVAIL -5 
-#define FILE_NOT_FOUND -6 
-#define REPEAT_FILE -7 
-#define HANDLE_NOT_USED -8 
-#define FILE_WRITE_ONLY -9 
-#define OUT_OF_SPACE -10 
-#define FILE_WRITE_ERR -11 
-#define TMFILE_READ_ONLY -12 
-#define FUNC_NOT_SUP -13 
-#define BAD_FILENAME -14 
-#define CANT_DEL_READ_ONLY -15 
-#define HANDLE_NOT_EXIST -16 
-#define ONE_WIRE_PORT_ERROR -17 
-#define INVALID_DIRECTORY -18 
-#define DIRECTORY_NOT_EMPTY -19 
-#define UNABLE_TO_CREATE_DIR -20 
-#define NO_PROGRAM_JOB -21 
-#define PROGRAM_WRITE_PROTECT -22
-#define NON_PROGRAM_PARTS -23 
-#define ADDFILE_TERMINATED -24 
-#define TIMEOUT -25 
-#define INVALID_ARGUMENT -26 
-#define BAD_ACK -27 
-#define INVALID_SESSION -200
-#define NO_BASDRV_FOUND -201
-
-/* Basic physical level error codes */
-#define BPORT_NOT_INITIALIZED -1 
-#define BPORT_NOT_EXIST -2 
-#define BNO_SUCH_FUNCTION -3 
-
-/* Transport level error codes */
-#define TERROR_READ_WRITE -4 
-#define TBUFFER_TOO_SMALL -5 
-#define TDEVICE_TOO_SMALL -6 
-#define TNO_DEVICE -7 
-#define TBLOCK_TOO_BIG -8 
-#define TWRONG_TYPE -9 
-#define TPAGE_REDIRECTED -10
-#define TPROGRAM_NOT_POSSIBLE -11
-#define BCOM_FAILURE -12
-#define BCOM_EVENT -13
-
-/* for TMOneWireLevel */
-#define LEVEL_NORMAL 0
-#define LEVEL_STRONG_PULLUP 1
-#define LEVEL_BREAK 2
-#define LEVEL_PROGRAM 3 
-#define PRIMED_NONE 0
-#define PRIMED_BIT 1
-#define PRIMED_BYTE 2 
-#define LEVEL_READ 1
-#define LEVEL_SET 0
-
-/* misc */
-#define GENERAL_FAIL -2 
-#define BAD_ARGUMENT 50
-#define NO_DRIVERS 51
-#define KEY_ABORT 52
-#define OUT_MEMORY 53
-#define NORMAL_EXIT 0
-
-#define TRUE 1
-#define FALSE 0
-#define DIR_READ 1
-#define DIR_SET 0
-#define DIR_REMOVE 1
-#define DIR_MAKE 0
-
-/* for specification */
-#define NOMEM 0
-#define NVRAM 1
-#define EPROM1 2
-#define EPROM2 3
-#define EPROM3 4
-#define EEPROM1 5
-#define MNVRAM 6
-#define EEPROM2 7
-#define NVRAM2 8
-#define NVRAM3 9 
-#define FTR_REG_PAGES 0
-#define FTR_REG_LEN 1
-#define FTR_STAT_PAGES 2
-#define FTR_STAT_LEN 3
-#define FTR_MAX_COM 4 
-#define FTR_MEM_TYPE 5
-
-// session
-extern long __fastcall TMExtendedStartSession(short, short, void far *);
-extern short __fastcall TMValidSession(long); 
-extern short __fastcall TMEndSession(long); 
-extern short __fastcall Get_Version(char far *); 
-// file_operations
-extern short __fastcall TMFirstFile(long, void far *, FileEntry far *); 
-extern short __fastcall TMNextFile(long, void far *, FileEntry far *);
-extern short __fastcall TMOpenFile(long, void far *, FileEntry far *);
-extern short __fastcall TMCreateFile(long, void far *, short far *, FileEntry far *);
-extern short __fastcall TMCloseFile(long, void far *, short);
-extern short __fastcall TMReadFile(long, void far *, short, uchar far *, short);
-extern short __fastcall TMWriteFile(long, void far *, short, uchar far *, short);
-extern short __fastcall TMDeleteFile(long, void far *, FileEntry far *);
-extern short __fastcall TMFormat(long, void far *);
-extern short __fastcall TMAttribute(long, void far *, short, FileEntry far *);
-extern short __fastcall TMReNameFile(long, void far *, short, FileEntry far *); 
-extern short __fastcall TMChangeDirectory(long, void far *, short, DirectoryPath far *); 
-extern short __fastcall TMDirectoryMR(long, void far *, short, FileEntry far *);
-extern short __fastcall TMCreateProgramJob(long, void far *);
-extern short __fastcall TMDoProgramJob(long, void far *);
-extern short __fastcall TMWriteAddFile(long, void far *, short, short, short, uchar far *, short);
-extern short __fastcall TMTerminateAddFile(long, void far *, FileEntry far *);
-extern short __fastcall TMGetFamilySpec(long, void far *, Specification *); 
-// transport
-extern short __fastcall TMReadPacket(long, void far *, short, uchar far *, short);
-extern short __fastcall TMWritePacket(long, void far *, short, uchar far *, short);
-extern short __fastcall TMBlockIO(long, uchar far *, short);
-extern short __fastcall TMExtendedReadPage(long, void far *, short, uchar far *, short);
-extern short __fastcall TMProgramByte(long, void far *, short, short, short, short far *, short);
-extern short __fastcall TMProgramBlock(long, void far *, uchar far *, short, short, short far *); /* (3.11) */
-extern long __fastcall TMCRC(short, uchar far *, ushort, short); 
-// network
-extern short __fastcall TMSkipFamily(long, void far *); 
-extern short __fastcall TMFamilySearchSetup(long, void far *, short); 
-extern short __fastcall TMFirst(long, void far *);
-extern short __fastcall TMNext(long, void far *);
-extern short __fastcall TMAccess(long, void far *);
-extern short __fastcall TMOverAccess(long, void far *);
-extern short __fastcall TMStrongAccess(long, void far *);
-extern short __fastcall TMStrongAlarmAccess(long, void far *);
-extern short __fastcall TMRom(long, void far *, short far *);
-extern short __fastcall TMFirstAlarm(long, void far *);
-extern short __fastcall TMNextAlarm(long, void far *); 
-extern short __fastcall TMAutoOverDrive(long, void far *, short); 
-extern short __fastcall TMSearch(short, short, short, short); 
-// hardware_specific
-extern short __fastcall TMSetup(long);
-extern short __fastcall TMTouchByte(long, short);
-extern short __fastcall TMTouchReset(long);
-extern short __fastcall TMTouchBit(long, short);
-extern short __fastcall TMClose(long);
-extern short __fastcall TMProgramPulse(long); 
-extern short __fastcall TMOneWireCom(long, short, short); 
-extern short __fastcall TMOneWireLevel(long, short, short, short); 
-extern short __fastcall TMGetTypeVersion(short,char far *); 
-extern short __fastcall TMBlockStream(long, uchar far *, short);
-extern short __fastcall TMGetAdapterSpec(long, Specification far *); 
-extern short __fastcall TMReadDefaultPort(short far *, short far *); 
-
+/*---------------------------------------------------------------------------\r
+* Copyright Â© 1992-2008 Maxim Integrated Products, All Rights Reserved.\r
+*\r
+* Permission is hereby granted, free of charge, to any person obtaining a\r
+* copy of this software and associated documentation files (the "Software"),\r
+* to deal in the Software without restriction, including without limitation\r
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+* and/or sell copies of the Software, and to permit persons to whom the\r
+* Software is furnished to do so, subject to the following conditions:\r
+*\r
+* The above copyright notice and this permission notice shall be included\r
+* in all copies or substantial portions of the Software.\r
+*\r
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+* IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES\r
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+* OTHER DEALINGS IN THE SOFTWARE.\r
+*\r
+* Except as contained in this notice, the name of Maxim Integrated Products\r
+* shall not be used except as stated in the Maxim Integrated Products\r
+* Branding Policy.\r
+*---------------------------------------------------------------------------\r
+* Version 4.01\r
+*/\r
+\r
+/* includes */\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+#include <windows.h>\r
+#ifndef _WIN32_WCE\r
+#include <stdio.h>\r
+#include <conio.h>\r
+#include <dos.h>\r
+#include <fcntl.h>\r
+#include <io.h>\r
+#include <time.h>\r
+#endif\r
+\r
+/* type defs */\r
+typedef unsigned char uchar;\r
+typedef unsigned short ushort;\r
+typedef unsigned long ulong;\r
+\r
+/* typedef structure sent back by TMEX routines */\r
+typedef struct \r
+{\r
+uchar name[4];\r
+uchar extension;\r
+uchar startpage;\r
+uchar numpages;\r
+uchar attrib;\r
+uchar bitmap[32];\r
+} FileEntry;\r
+\r
+/* structure to hold directory path */\r
+typedef struct\r
+{\r
+uchar NumEntries; /* number of entries in path 0-10 */\r
+char Ref; /* reference character '\' or '.' */\r
+char Entries[10][4]; /* sub-directory entry names */ \r
+} DirectoryPath;\r
+\r
+/* Holds info of each object in the Directory list */\r
+struct DirNumInfo \r
+{ \r
+unsigned char Name[4];\r
+unsigned char Extension;\r
+char Attrib;\r
+};\r
+\r
+/* structure to hold exportable device parameters by family code (3.11) */\r
+typedef struct\r
+{\r
+short features[32];\r
+char dscrptn[255];\r
+} Specification;\r
+\r
+\r
+/* Error codes from TMEX functions */\r
+#define NO_DEVICE -1 \r
+#define WRONG_TYPE -2 \r
+#define FILE_READ_ERR -3 \r
+#define BUFFER_TOO_SMALL -4 \r
+#define HANDLE_NOT_AVAIL -5 \r
+#define FILE_NOT_FOUND -6 \r
+#define REPEAT_FILE -7 \r
+#define HANDLE_NOT_USED -8 \r
+#define FILE_WRITE_ONLY -9 \r
+#define OUT_OF_SPACE -10 \r
+#define FILE_WRITE_ERR -11 \r
+#define TMFILE_READ_ONLY -12 \r
+#define FUNC_NOT_SUP -13 \r
+#define BAD_FILENAME -14 \r
+#define CANT_DEL_READ_ONLY -15 \r
+#define HANDLE_NOT_EXIST -16 \r
+#define ONE_WIRE_PORT_ERROR -17 \r
+#define INVALID_DIRECTORY -18 \r
+#define DIRECTORY_NOT_EMPTY -19 \r
+#define UNABLE_TO_CREATE_DIR -20 \r
+#define NO_PROGRAM_JOB -21 \r
+#define PROGRAM_WRITE_PROTECT -22\r
+#define NON_PROGRAM_PARTS -23 \r
+#define ADDFILE_TERMINATED -24 \r
+#define TIMEOUT -25 \r
+#define INVALID_ARGUMENT -26 \r
+#define BAD_ACK -27 \r
+#define INVALID_SESSION -200\r
+#define NO_BASDRV_FOUND -201\r
+\r
+/* Basic physical level error codes */\r
+#define BPORT_NOT_INITIALIZED -1 \r
+#define BPORT_NOT_EXIST -2 \r
+#define BNO_SUCH_FUNCTION -3 \r
+\r
+/* Transport level error codes */\r
+#define TERROR_READ_WRITE -4 \r
+#define TBUFFER_TOO_SMALL -5 \r
+#define TDEVICE_TOO_SMALL -6 \r
+#define TNO_DEVICE -7 \r
+#define TBLOCK_TOO_BIG -8 \r
+#define TWRONG_TYPE -9 \r
+#define TPAGE_REDIRECTED -10\r
+#define TPROGRAM_NOT_POSSIBLE -11\r
+#define BCOM_FAILURE -12\r
+#define BCOM_EVENT -13\r
+\r
+/* for TMOneWireLevel */\r
+#define LEVEL_NORMAL 0\r
+#define LEVEL_STRONG_PULLUP 1\r
+#define LEVEL_BREAK 2\r
+#define LEVEL_PROGRAM 3 \r
+#define PRIMED_NONE 0\r
+#define PRIMED_BIT 1\r
+#define PRIMED_BYTE 2 \r
+#define LEVEL_READ 1\r
+#define LEVEL_SET 0\r
+\r
+/* misc */\r
+#define GENERAL_FAIL -2 \r
+#define BAD_ARGUMENT 50\r
+#define NO_DRIVERS 51\r
+#define KEY_ABORT 52\r
+#define OUT_MEMORY 53\r
+#define NORMAL_EXIT 0\r
+\r
+#define TRUE 1\r
+#define FALSE 0\r
+#define DIR_READ 1\r
+#define DIR_SET 0\r
+#define DIR_REMOVE 1\r
+#define DIR_MAKE 0\r
+\r
+/* for specification */\r
+#define NOMEM 0\r
+#define NVRAM 1\r
+#define EPROM1 2\r
+#define EPROM2 3\r
+#define EPROM3 4\r
+#define EEPROM1 5\r
+#define MNVRAM 6\r
+#define EEPROM2 7\r
+#define NVRAM2 8\r
+#define NVRAM3 9 \r
+#define FTR_REG_PAGES 0\r
+#define FTR_REG_LEN 1\r
+#define FTR_STAT_PAGES 2\r
+#define FTR_STAT_LEN 3\r
+#define FTR_MAX_COM 4 \r
+#define FTR_MEM_TYPE 5\r
+\r
+// session\r
+extern long __fastcall TMExtendedStartSession(short, short, void far *);\r
+extern short __fastcall TMValidSession(long); \r
+extern short __fastcall TMEndSession(long); \r
+extern short __fastcall Get_Version(char far *); \r
+// file_operations\r
+extern short __fastcall TMFirstFile(long, void far *, FileEntry far *); \r
+extern short __fastcall TMNextFile(long, void far *, FileEntry far *);\r
+extern short __fastcall TMOpenFile(long, void far *, FileEntry far *);\r
+extern short __fastcall TMCreateFile(long, void far *, short far *, FileEntry far *);\r
+extern short __fastcall TMCloseFile(long, void far *, short);\r
+extern short __fastcall TMReadFile(long, void far *, short, uchar far *, short);\r
+extern short __fastcall TMWriteFile(long, void far *, short, uchar far *, short);\r
+extern short __fastcall TMDeleteFile(long, void far *, FileEntry far *);\r
+extern short __fastcall TMFormat(long, void far *);\r
+extern short __fastcall TMAttribute(long, void far *, short, FileEntry far *);\r
+extern short __fastcall TMReNameFile(long, void far *, short, FileEntry far *); \r
+extern short __fastcall TMChangeDirectory(long, void far *, short, DirectoryPath far *); \r
+extern short __fastcall TMDirectoryMR(long, void far *, short, FileEntry far *);\r
+extern short __fastcall TMCreateProgramJob(long, void far *);\r
+extern short __fastcall TMDoProgramJob(long, void far *);\r
+extern short __fastcall TMWriteAddFile(long, void far *, short, short, short, uchar far *, short);\r
+extern short __fastcall TMTerminateAddFile(long, void far *, FileEntry far *);\r
+extern short __fastcall TMGetFamilySpec(long, void far *, Specification *); \r
+// transport\r
+extern short __fastcall TMReadPacket(long, void far *, short, uchar far *, short);\r
+extern short __fastcall TMWritePacket(long, void far *, short, uchar far *, short);\r
+extern short __fastcall TMBlockIO(long, uchar far *, short);\r
+extern short __fastcall TMExtendedReadPage(long, void far *, short, uchar far *, short);\r
+extern short __fastcall TMProgramByte(long, void far *, short, short, short, short far *, short);\r
+extern short __fastcall TMProgramBlock(long, void far *, uchar far *, short, short, short far *); /* (3.11) */\r
+extern long __fastcall TMCRC(short, uchar far *, ushort, short); \r
+// network\r
+extern short __fastcall TMSkipFamily(long, void far *); \r
+extern short __fastcall TMFamilySearchSetup(long, void far *, short); \r
+extern short __fastcall TMFirst(long, void far *);\r
+extern short __fastcall TMNext(long, void far *);\r
+extern short __fastcall TMAccess(long, void far *);\r
+extern short __fastcall TMOverAccess(long, void far *);\r
+extern short __fastcall TMStrongAccess(long, void far *);\r
+extern short __fastcall TMStrongAlarmAccess(long, void far *);\r
+extern short __fastcall TMRom(long, void far *, short far *);\r
+extern short __fastcall TMFirstAlarm(long, void far *);\r
+extern short __fastcall TMNextAlarm(long, void far *); \r
+extern short __fastcall TMAutoOverDrive(long, void far *, short); \r
+extern short __fastcall TMSearch(short, short, short, short); \r
+// hardware_specific\r
+extern short __fastcall TMSetup(long);\r
+extern short __fastcall TMTouchByte(long, short);\r
+extern short __fastcall TMTouchReset(long);\r
+extern short __fastcall TMTouchBit(long, short);\r
+extern short __fastcall TMClose(long);\r
+extern short __fastcall TMProgramPulse(long); \r
+extern short __fastcall TMOneWireCom(long, short, short); \r
+extern short __fastcall TMOneWireLevel(long, short, short, short); \r
+extern short __fastcall TMGetTypeVersion(short,char far *); \r
+extern short __fastcall TMBlockStream(long, uchar far *, short);\r
+extern short __fastcall TMGetAdapterSpec(long, Specification far *); \r
+extern short __fastcall TMReadDefaultPort(short far *, short far *); \r
+\r
index 184ffd7..fa6df19 100644 (file)
-#define _CRT_SECURE_NO_WARNINGS 1
-extern "C" {
-#include "ownet.h"
-}
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-FILE *fio;
-char s[100], fname[254];
-
-
-SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i;
-       int address;
-       char s[100];
-       FILE *f;
-       sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);
-       fprintf(fio, ">14\n");
-       send_cnt = 0;
-       printf("Read Data MEM  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-       send_cnt = 0;
-       printf("Read App MEM  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xC3;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-
-       send_cnt = 0;
-       printf("Read App State  \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x66;
-       for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]);  fprintf(fio, "%02X ", send_block[i]); }
-       printf("\n");
-       fprintf(fio, "\n");
-}
-
-
-SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2433 \n");
-       fprintf(fio, ">23\n");
-
-       send_cnt = 0;
-       printf("\nRead MEM ALL \n");
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       send_block[send_cnt++] = 0x00;
-       for (j = 0; j<16; j++) {
-               for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
-               send_cnt = 0;
-               printf("\n");
-               fprintf(fio, "\n");
-       }
-
-}
-
-
-int findDev(uchar code) {
-       int find = 0;
-       fio = fopen(fname, "r");
-       while (!feof(fio)) {
-               s[0] = fgetc(fio);
-               if (s[0] == '>') {
-                       s[0] = fgetc(fio);
-                       s[1] = fgetc(fio);
-                       s[2] = 0;
-                       uchar w = strtol(s, NULL, 16);
-                       if (code ==w) return 1;
-               }
-       }
-       fclose(fio);
-       return 0;
-}
-
-
-
-SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2433 \n");
-       if (findDev(0x23)) {
-               for (j = 0; j < 16; j++) {
-                       for (i = 0; i < 32; i++) {
-                               fscanf(fio, "%02X", &send_block[i + 3]);
-                       }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_block[0] = 0x0F;
-                       send_block[1] = j << 5;
-                       send_block[2] = j >> 3;
-                       if (!owBlock(portnum, FALSE, send_block, 32 + 3))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_cnt = 0;
-                       send_block[send_cnt++] = 0xAA;
-                       for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;
-                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
-                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-                       send_cnt = 0;
-                       send_block[send_cnt++] = 0x55;
-                       send_cnt += 3;
-                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-                       msDelay(100);
-                       printf("\n");
-               }
-       
-       }
-       fclose(fio);
-       return 0;
-
-
-}
-
-
-SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i, j;
-       int address;
-       send_cnt = 0;
-       printf("-----> TEST DS2430 \n");
-       if (findDev(0x14)) {
-               for (i = 0; i < 32; i++) {
-                       fscanf(fio, "%02X", &send_block[i + 2]);
-               }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_block[0] = 0x0F;
-               send_block[1] = 0;
-               if (!owBlock(portnum, FALSE, send_block, 32 + 2))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_cnt = 0;
-               send_block[send_cnt++] = 0xAA;
-               send_block[send_cnt++] = 0x00;
-               for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
-               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-               send_cnt = 0;
-               send_block[send_cnt++] = 0x55;
-               send_block[send_cnt++] = 0xA5;
-               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-               msDelay(100);
-               printf("\n");
-       }
-       fclose(fio);
-
-}
-/*
-SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {
-       uchar rt = FALSE;
-       uchar send_block[145];
-       uchar send_cnt = 0, i;
-       int address;
-       uchar readbl[64];
-       FILE *f;
-       f = fopen(fname, "rb");
-       fread(readbl, 1, 32 + 16, f);
-       fclose(f);
-       ResetDS2430(portnum, SerialNum);
-       msDelay(1000);
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x0F;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xAA;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x55;
-       send_block[send_cnt++] = 0xA5;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       msDelay(10);
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0xF0;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x99;
-       send_block[send_cnt++] = 0x00;
-       for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-
-       send_cnt = 0;
-       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
-       send_block[send_cnt++] = 0x5A;
-       send_block[send_cnt++] = 0xA5;
-       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
-       msDelay(10);
-       SetIDDS2430(portnum, SerialNum, readbl);
-
-
-}
-*/
-
-
-
-unsigned char conf2(const char *s) {
-       unsigned char b = 0;
-       for (int i = 0; i < 2; i++) {
-               b = b * 16;
-               if ((s[i] >= '0') && (s[i] <= '9')) {
-                       b += s[i] - '0';
-               } else
-               if ((s[i] >= 'A') && (s[i] <= 'F')) {
-                       b += s[i] - 'A'+10;
-               } else
-               if ((s[i] >= 'a') && (s[i] <= 'f')) {
-                       b += s[i] - 'a'+10;
-               }
-               
-       }
-       return b;
-}
-
-void strcpys(char *s, const char* d,bool up) {
-       if (strlen(d) > 7990) {
-               strncpy(s, d, 7990);
-               s[200] = 0;
-       }
-       else strcpy(s, d);
-       if (up) {
-               for (int i = 0; i<strlen(s); i++)
-                       if ((s[i] >= 'a') && (s[i] <= 'z'))
-                               s[i] += 'A' - 'a';
-       }
-}
-
-int main(int argc, char *argv[]) {
-       uchar SNum[8];
-       int rslt, cnt, i;
-       uchar send_block[256];
-       uchar send_cnt = 0;
-       int portnum;
-       char adapter[20];
-       int found = 0;
-       int rw = 0;
-       int err = 0;
-       char s[8000];
-       int adt = 0;
-       int mod = 0;
-       if (argc >= 2) {
-               strcpys(s, argv[1],true);
-               
-               
-               if (strncmp(s,"USB",3)==0) {adt = 6;}
-               if (strncmp(s, "COM", 3) == 0) { adt = 5; }
-               if (adt != 0) {
-                       strcpy(s, argv[1] + 3);
-                       sprintf(adapter, "{%s,%i}\0",s,adt);
-                       printf("Open Port %s\n", argv[1]);
-                       if ((portnum = owAcquireEx(adapter)) < 0) {
-                               printf("ERROR \n", adt);
-                       }
-                       else mod = 1;
-
-               } 
-               if ((argc == 2) && (mod == 1)) mod = 2;
-               if (argc > 2) {
-                       strcpys(s, argv[2],true);
-                       if (strncmp(s, "DC", 2) == 0) {
-                               if (argc > 3) {
-                                       if (strlen(argv[3])>=16)
-                                       for (int i = 0; i < 16; i += 2) {
-                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);
-
-                                       }
-                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
-                                       mod = 3;
-                               }
-
-                       }
-               }
-               if ((mod == 3) && (argc>4)) {
-                       strcpys(s, argv[4], true);
-                       mod = 4;
-               }
-       
-       }
-
-       if (mod == 2) {
-               rslt = owFirst(portnum, TRUE, FALSE);
-               cnt = 0;
-               while (rslt) {
-                       cnt++;
-                       owSerialNum(portnum, &SNum[0], TRUE);
-                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
-                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);
-/*                     switch (SNum[0]) {
-
-
-                               case 0x14: {
-                                       //TestDS2430(portnum,&SNum[0]);
-                                       //scanf("%i",&i);
-                                       //ResetDS2430(portnum,&SNum[0]);
-                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};
-                                       //SetIDDS2430(portnum,&SNum[0],id);
-                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);
-                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");
-                                       break;
-                               }
-                               case 0x23: {
-                                       //TestDS2433(portnum,&SNum[0]);
-                                       //TestDS2433_reset(portnum,&SNum[0]);
-                                       //scanf("%i",&i);
-                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);
-                                       break;
-                               }
-                               }*/
-                       rslt = owNext(portnum, TRUE, FALSE);
-               }
-       }
-       if (mod == 4) {
-               owSerialNum(portnum, SNum, FALSE);
-               strcat(s, "_R");
-               int len = strlen(s);
-               int i = 0;
-               while (i < len) {
-                       if (s[i] == '_') {
-                               if (s[i + 1] == 'R') {
-                                       if (owAccess(portnum)) {
-                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {
-                                                       for (int j = 0; j < send_cnt; j++) {
-                                                               printf("%02X", send_block[j]);
-                                                       }
-                                                       printf("\n");
-                                               }
-                                               else printf("ERROR RESET\n");
-                                       }
-                                       else printf("ERROR SEND\n");
-                                       send_cnt = 0;
-                               }
-                               if (s[i + 1] == 'P') {
-                                       if (i + 2 < len) {
-                                               i += 2;
-                                               msDelay(conf2(s + i));
-                                               
-                                       }
-                               }
-                       }
-                       else {
-                               send_block[send_cnt++] = conf2(s + i);
-                       }
-                       i += 2;
-               
-                       
-               }
-       }
-       if (mod>0) owRelease(portnum);
-       
-       return 0;
+#define _CRT_SECURE_NO_WARNINGS 1\r
+extern "C" {\r
+#include "ownet.h"\r
+}\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+FILE *fio;\r
+char s[100], fname[254];\r
+\r
+\r
+SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i;\r
+       int address;\r
+       char s[100];\r
+       FILE *f;\r
+       sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);\r
+       fprintf(fio, ">14\n");\r
+       send_cnt = 0;\r
+       printf("Read Data MEM  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+       send_cnt = 0;\r
+       printf("Read App MEM  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xC3;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+\r
+       send_cnt = 0;\r
+       printf("Read App State  \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x66;\r
+       for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]);  fprintf(fio, "%02X ", send_block[i]); }\r
+       printf("\n");\r
+       fprintf(fio, "\n");\r
+}\r
+\r
+\r
+SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2433 \n");\r
+       fprintf(fio, ">23\n");\r
+\r
+       send_cnt = 0;\r
+       printf("\nRead MEM ALL \n");\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (j = 0; j<16; j++) {\r
+               for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }\r
+               send_cnt = 0;\r
+               printf("\n");\r
+               fprintf(fio, "\n");\r
+       }\r
+\r
+}\r
+\r
+\r
+int findDev(uchar code) {\r
+       int find = 0;\r
+       fio = fopen(fname, "r");\r
+       while (!feof(fio)) {\r
+               s[0] = fgetc(fio);\r
+               if (s[0] == '>') {\r
+                       s[0] = fgetc(fio);\r
+                       s[1] = fgetc(fio);\r
+                       s[2] = 0;\r
+                       uchar w = strtol(s, NULL, 16);\r
+                       if (code ==w) return 1;\r
+               }\r
+       }\r
+       fclose(fio);\r
+       return 0;\r
+}\r
+\r
+\r
+\r
+SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2433 \n");\r
+       if (findDev(0x23)) {\r
+               for (j = 0; j < 16; j++) {\r
+                       for (i = 0; i < 32; i++) {\r
+                               fscanf(fio, "%02X", &send_block[i + 3]);\r
+                       }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_block[0] = 0x0F;\r
+                       send_block[1] = j << 5;\r
+                       send_block[2] = j >> 3;\r
+                       if (!owBlock(portnum, FALSE, send_block, 32 + 3))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_cnt = 0;\r
+                       send_block[send_cnt++] = 0xAA;\r
+                       for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;\r
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }\r
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+                       send_cnt = 0;\r
+                       send_block[send_cnt++] = 0x55;\r
+                       send_cnt += 3;\r
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+                       msDelay(100);\r
+                       printf("\n");\r
+               }\r
+       \r
+       }\r
+       fclose(fio);\r
+       return 0;\r
+\r
+\r
+}\r
+\r
+\r
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i, j;\r
+       int address;\r
+       send_cnt = 0;\r
+       printf("-----> TEST DS2430 \n");\r
+       if (findDev(0x14)) {\r
+               for (i = 0; i < 32; i++) {\r
+                       fscanf(fio, "%02X", &send_block[i + 2]);\r
+               }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_block[0] = 0x0F;\r
+               send_block[1] = 0;\r
+               if (!owBlock(portnum, FALSE, send_block, 32 + 2))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_cnt = 0;\r
+               send_block[send_cnt++] = 0xAA;\r
+               send_block[send_cnt++] = 0x00;\r
+               for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }\r
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+               send_cnt = 0;\r
+               send_block[send_cnt++] = 0x55;\r
+               send_block[send_cnt++] = 0xA5;\r
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+               msDelay(100);\r
+               printf("\n");\r
+       }\r
+       fclose(fio);\r
+\r
+}\r
+/*\r
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {\r
+       uchar rt = FALSE;\r
+       uchar send_block[145];\r
+       uchar send_cnt = 0, i;\r
+       int address;\r
+       uchar readbl[64];\r
+       FILE *f;\r
+       f = fopen(fname, "rb");\r
+       fread(readbl, 1, 32 + 16, f);\r
+       fclose(f);\r
+       ResetDS2430(portnum, SerialNum);\r
+       msDelay(1000);\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x0F;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xAA;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x55;\r
+       send_block[send_cnt++] = 0xA5;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       msDelay(10);\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0xF0;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x99;\r
+       send_block[send_cnt++] = 0x00;\r
+       for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+\r
+       send_cnt = 0;\r
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }\r
+       send_block[send_cnt++] = 0x5A;\r
+       send_block[send_cnt++] = 0xA5;\r
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }\r
+       msDelay(10);\r
+       SetIDDS2430(portnum, SerialNum, readbl);\r
+\r
+\r
+}\r
+*/\r
+\r
+\r
+\r
+unsigned char conf2(const char *s) {\r
+       unsigned char b = 0;\r
+       for (int i = 0; i < 2; i++) {\r
+               b = b * 16;\r
+               if ((s[i] >= '0') && (s[i] <= '9')) {\r
+                       b += s[i] - '0';\r
+               } else\r
+               if ((s[i] >= 'A') && (s[i] <= 'F')) {\r
+                       b += s[i] - 'A'+10;\r
+               } else\r
+               if ((s[i] >= 'a') && (s[i] <= 'f')) {\r
+                       b += s[i] - 'a'+10;\r
+               }\r
+               \r
+       }\r
+       return b;\r
+}\r
+\r
+void strcpys(char *s, const char* d,bool up) {\r
+       if (strlen(d) > 7990) {\r
+               strncpy(s, d, 7990);\r
+               s[200] = 0;\r
+       }\r
+       else strcpy(s, d);\r
+       if (up) {\r
+               for (int i = 0; i<strlen(s); i++)\r
+                       if ((s[i] >= 'a') && (s[i] <= 'z'))\r
+                               s[i] += 'A' - 'a';\r
+       }\r
+}\r
+\r
+int main(int argc, char *argv[]) {\r
+       uchar SNum[8];\r
+       int rslt, cnt, i;\r
+       uchar send_block[256];\r
+       uchar send_cnt = 0;\r
+       int portnum;\r
+       char adapter[20];\r
+       int found = 0;\r
+       int rw = 0;\r
+       int err = 0;\r
+       char s[8000];\r
+       int adt = 0;\r
+       int mod = 0;\r
+       if (argc >= 2) {\r
+               strcpys(s, argv[1],true);\r
+               \r
+               \r
+               if (strncmp(s,"USB",3)==0) {adt = 6;}\r
+               if (strncmp(s, "COM", 3) == 0) { adt = 5; }\r
+               if (adt != 0) {\r
+                       strcpy(s, argv[1] + 3);\r
+                       sprintf(adapter, "{%s,%i}\0",s,adt);\r
+                       printf("Open Port %s\n", argv[1]);\r
+                       if ((portnum = owAcquireEx(adapter)) < 0) {\r
+                               printf("ERROR \n", adt);\r
+                       }\r
+                       else mod = 1;\r
+\r
+               } \r
+               if ((argc == 2) && (mod == 1)) mod = 2;\r
+               if (argc > 2) {\r
+                       strcpys(s, argv[2],true);\r
+                       if (strncmp(s, "DC", 2) == 0) {\r
+                               if (argc > 3) {\r
+                                       if (strlen(argv[3])>=16)\r
+                                       for (int i = 0; i < 16; i += 2) {\r
+                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);\r
+\r
+                                       }\r
+                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);\r
+                                       mod = 3;\r
+                               }\r
+\r
+                       }\r
+               }\r
+               if ((mod == 3) && (argc>4)) {\r
+                       strcpys(s, argv[4], true);\r
+                       mod = 4;\r
+               }\r
+       \r
+       }\r
+\r
+       if (mod == 2) {\r
+               rslt = owFirst(portnum, TRUE, FALSE);\r
+               cnt = 0;\r
+               while (rslt) {\r
+                       cnt++;\r
+                       owSerialNum(portnum, &SNum[0], TRUE);\r
+                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);\r
+                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);\r
+/*                     switch (SNum[0]) {\r
+\r
+\r
+                               case 0x14: {\r
+                                       //TestDS2430(portnum,&SNum[0]);\r
+                                       //scanf("%i",&i);\r
+                                       //ResetDS2430(portnum,&SNum[0]);\r
+                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};\r
+                                       //SetIDDS2430(portnum,&SNum[0],id);\r
+                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);\r
+                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");\r
+                                       break;\r
+                               }\r
+                               case 0x23: {\r
+                                       //TestDS2433(portnum,&SNum[0]);\r
+                                       //TestDS2433_reset(portnum,&SNum[0]);\r
+                                       //scanf("%i",&i);\r
+                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);\r
+                                       break;\r
+                               }\r
+                               }*/\r
+                       rslt = owNext(portnum, TRUE, FALSE);\r
+               }\r
+       }\r
+       if (mod == 4) {\r
+               owSerialNum(portnum, SNum, FALSE);\r
+               strcat(s, "_R");\r
+               int len = strlen(s);\r
+               int i = 0;\r
+               while (i < len) {\r
+                       if (s[i] == '_') {\r
+                               if (s[i + 1] == 'R') {\r
+                                       if (owAccess(portnum)) {\r
+                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {\r
+                                                       for (int j = 0; j < send_cnt; j++) {\r
+                                                               printf("%02X", send_block[j]);\r
+                                                       }\r
+                                                       printf("\n");\r
+                                               }\r
+                                               else printf("ERROR RESET\n");\r
+                                       }\r
+                                       else printf("ERROR SEND\n");\r
+                                       send_cnt = 0;\r
+                               }\r
+                               if (s[i + 1] == 'P') {\r
+                                       if (i + 2 < len) {\r
+                                               i += 2;\r
+                                               msDelay(conf2(s + i));\r
+                                               \r
+                                       }\r
+                               }\r
+                       }\r
+                       else {\r
+                               send_block[send_cnt++] = conf2(s + i);\r
+                       }\r
+                       i += 2;\r
+               \r
+                       \r
+               }\r
+       }\r
+       if (mod>0) owRelease(portnum);\r
+       \r
+       return 0;\r
 }
\ No newline at end of file
index e26a97a..76c5176 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-// owerr.c - Library functions for error handling with 1-Wire library
-//
-// Version: 1.00
-//
-
-#include <string.h>
-#ifndef _WIN32_WCE
-#include <stdio.h>
-#endif
-#ifdef _WIN64
-#include <stdio.h>
-#endif
-#include "ownet.h"
-
-#ifndef SIZE_OWERROR_STACK
-   #ifdef SMALL_MEMORY_TARGET
-      //for small memory, only hole 1 error
-      #define SIZE_OWERROR_STACK 1
-   #else
-      #define SIZE_OWERROR_STACK 10
-   #endif
-#endif
-
-//---------------------------------------------------------------------------
-// Variables
-//---------------------------------------------------------------------------
-
-// Error Struct for holding error information.
-// In DEBUG, this will also hold the line number and filename.
-typedef struct
-{
-   int owErrorNum;
-#ifdef DEBUG
-   int lineno;
-   char *filename;
-#endif
-} owErrorStruct;
-
-// Ring-buffer used for stack.
-// In case of overflow, deepest error is over-written.
-static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
-
-// Stack pointer to top-most error.
-static int owErrorPointer = 0;
-
-
-//---------------------------------------------------------------------------
-// Functions Definitions
-//---------------------------------------------------------------------------
-int owGetErrorNum(void);
-void owClearError(void);
-int owHasErrors(void);
-#ifdef DEBUG
-   void owRaiseError(int,int,char*);
-#else
-   void owRaiseError(int);
-#endif
-#ifndef SMALL_MEMORY_TARGET
-   void owPrintErrorMsg(FILE *);
-   void owPrintErrorMsgStd();
-   char *owGetErrorMsg(int);
-#endif
-
-
-//--------------------------------------------------------------------------
-// The 'owGetErroNum' returns the error code of the top-most error on the
-// error stack.  NOTE: This function has the side effect of popping the
-// current error off the stack.  All successive calls to 'owGetErrorNum'
-// will further clear the error stack.
-//
-// For list of error codes, see 'ownet.h'
-//
-// Returns:   int :  The error code of the top-most error on the stack
-//
-int owGetErrorNum(void)
-{
-   int i = owErrorStack[ owErrorPointer ].owErrorNum;
-   owErrorStack[ owErrorPointer ].owErrorNum = 0;
-   if(!owErrorPointer)
-      owErrorPointer = SIZE_OWERROR_STACK - 1;
-   else
-      owErrorPointer = (owErrorPointer - 1);
-   return i;
-}
-
-//--------------------------------------------------------------------------
-// The 'owClearError' clears all the errors.
-//
-void owClearError(void)
-{
-   owErrorStack[ owErrorPointer ].owErrorNum = 0;
-}
-
-//--------------------------------------------------------------------------
-// The 'owHasErrors' is a boolean test function which tests whether or not
-// a valid error is waiting on the stack.
-//
-// Returns:   TRUE (1) : When there are errors on the stack.
-//            FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.
-//
-int owHasErrors(void)
-{
-   if(owErrorStack[ owErrorPointer ].owErrorNum)
-      return 1; //TRUE
-   else
-      return 0; //FALSE
-}
-
-#ifdef DEBUG
-   //--------------------------------------------------------------------------
-   // The 'owRaiseError' is the method for raising an error onto the error
-   // stack.
-   //
-   // Arguments:  int err - the error code you wish to raise.
-   //             int lineno - DEBUG only - the line number where it was raised
-   //             char* filename - DEBUG only - the file name where it occured.
-   //
-   void owRaiseError(int err, int lineno, char* filename)
-   {
-      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
-      owErrorStack[ owErrorPointer ].owErrorNum = err;
-      owErrorStack[ owErrorPointer ].lineno = lineno;
-      owErrorStack[ owErrorPointer ].filename = filename;
-   }
-#else
-   //--------------------------------------------------------------------------
-   // The 'owRaiseError' is the method for raising an error onto the error
-   // stack.
-   //
-   // Arguments:  int err - the error code you wish to raise.
-   //
-   void owRaiseError(int err)
-   {
-      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
-      owErrorStack[ owErrorPointer ].owErrorNum = err;
-   }
-#endif
-
-
-// SMALL_MEMORY_TARGET - embedded microcontrollers, where these
-// messaging functions might not make any sense.
-#ifndef SMALL_MEMORY_TARGET
-   //Array of meaningful error messages to associate with codes.
-   //Not used on targets with low memory (i.e. PIC).
-   static char *owErrorMsg[125] =
-   {
-   /*000*/ "No Error Was Set",
-   /*001*/ "No Devices found on 1-Wire Network",
-   /*002*/ "1-Wire Net Reset Failed",
-   /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",
-   /*004*/ "Access Failed: Could not select device",
-   /*005*/ "DS2480B Adapter Not Detected",
-   /*006*/ "DS2480B: Wrong Baud",
-   /*007*/ "DS2480B: Bad Response",
-   /*008*/ "Open COM Failed",
-   /*009*/ "Write COM Failed",
-   /*010*/ "Read COM Failed",
-   /*011*/ "Data Block Too Large",
-   /*012*/ "Block Transfer failed",
-   /*013*/ "Program Pulse Failed",
-   /*014*/ "Program Byte Failed",
-   /*015*/ "Write Byte Failed",
-   /*016*/ "Read Byte Failed",
-   /*017*/ "Write Verify Failed",
-   /*018*/ "Read Verify Failed",
-   /*019*/ "Write Scratchpad Failed",
-   /*020*/ "Copy Scratchpad Failed",
-   /*021*/ "Incorrect CRC Length",
-   /*022*/ "CRC Failed",
-   /*023*/ "Failed to acquire a necessary system resource",
-   /*024*/ "Failed to initialize system resource",
-   /*025*/ "Data too long to fit on specified device.",
-   /*026*/ "Read exceeds memory bank end.",
-   /*027*/ "Write exceeds memory bank end.",
-   /*028*/ "Device select failed",
-   /*029*/ "Read Scratch Pad verify failed.",
-   /*030*/ "Copy scratchpad complete not found",
-   /*031*/ "Erase scratchpad complete not found",
-   /*032*/ "Address read back from scrachpad was incorrect",
-   /*033*/ "Read page with extra-info not supported by this memory bank",
-   /*034*/ "Read page packet with extra-info not supported by this memory bank",
-   /*035*/ "Length of packet requested exceeds page size",
-   /*036*/ "Invalid length in packet",
-   /*037*/ "Program pulse required but not available",
-   /*038*/ "Trying to access a read-only memory bank",
-   /*039*/ "Current bank is not general purpose memory",
-   /*040*/ "Read back from write compare is incorrect, page may be locked",
-   /*041*/ "Invalid page number for this memory bank",
-   /*042*/ "Read page with CRC not supported by this memory bank",
-   /*043*/ "Read page with CRC and extra-info not supported by this memory bank",
-   /*044*/ "Read back from write incorrect, could not lock page",
-   /*045*/ "Read back from write incorrect, could not lock redirect byte",
-   /*046*/ "The read of the status was not completed.",
-   /*047*/ "Page redirection not supported by this memory bank",
-   /*048*/ "Lock Page redirection not supported by this memory bank",
-   /*049*/ "Read back byte on EPROM programming did not match.",
-   /*050*/ "Can not write to a page that is locked.",
-   /*051*/ "Can not lock a redirected page that has already been locked.",
-   /*052*/ "Trying to redirect a locked redirected page.",
-   /*053*/ "Trying to lock a page that is already locked.",
-   /*054*/ "Trying to write to a memory bank that is write protected.",
-   /*055*/ "Error due to not matching MAC.",
-   /*056*/ "Memory Bank is write protected.",
-   /*057*/ "Secret is write protected, can not Load First Secret.",
-   /*058*/ "Error in Reading Scratchpad after Computing Next Secret.",
-   /*059*/ "Load Error from Loading First Secret.",
-   /*060*/ "Power delivery required but not available",
-   /*061*/ "Not a valid file name.",
-   /*062*/ "Unable to Create a Directory in this part.",
-   /*063*/ "That file already exists.",
-   /*064*/ "The directory is not empty.",
-   /*065*/ "The wrong type of part for this operation.",
-   /*066*/ "The max len for this file is too small.",
-   /*067*/ "This is not a write once bank.",
-   /*068*/ "The file can not be found.",
-   /*069*/ "There is not enough space available.",
-   /*070*/ "There is not a page to match that bit in the bitmap.",
-   /*071*/ "There are no jobs for EPROM parts.",
-   /*072*/ "Function not supported to modify attributes.",
-   /*073*/ "Handle is not in use.",
-   /*074*/ "Tring to read a write only file.",
-   /*075*/ "There is no handle available for use.",
-   /*076*/ "The directory provided is an invalid directory.",
-   /*077*/ "Handle does not exist.",
-   /*078*/ "Serial Number did not match with current job.",
-   /*079*/ "Can not program EPROM because a non-EPROM part on the network.",
-   /*080*/ "Write protect redirection byte is set.",
-   /*081*/ "There is an inappropriate directory length.",
-   /*082*/ "The file has already been terminated.",
-   /*083*/ "Failed to read memory page of iButton part.",
-   /*084*/ "Failed to match scratchpad of iButton part.",
-   /*085*/ "Failed to erase scratchpad of iButton part.",
-   /*086*/ "Failed to read scratchpad of iButton part.",
-   /*087*/ "Failed to execute SHA function on SHA iButton.",
-   /*088*/ "SHA iButton did not return a status completion byte.",
-   /*089*/ "Write data page failed.",
-   /*090*/ "Copy secret into secret memory pages failed.",
-   /*091*/ "Bind unique secret to iButton failed.",
-   /*092*/ "Could not install secret into user token.",
-   /*093*/ "Transaction Incomplete: signature did not match.",
-   /*094*/ "Transaction Incomplete: could not sign service data.",
-   /*095*/ "User token did not provide a valid authentication response.",
-   /*096*/ "Failed to answer a challenge on the user token.",
-   /*097*/ "Failed to create a challenge on the coprocessor.",
-   /*098*/ "Transaction Incomplete: service data was not valid.",
-   /*099*/ "Transaction Incomplete: service data was not updated.",
-   /*100*/ "Unrecoverable, catastrophic service failure occured.",
-   /*101*/ "Load First Secret from scratchpad data failed.",
-   /*102*/ "Failed to match signature of user's service data.",
-   /*103*/ "Subkey out of range for the DS1991.",
-   /*104*/ "Block ID out of range for the DS1991",
-   /*105*/ "Password is enabled",
-   /*106*/ "Password is invalid",
-   /*107*/ "This memory bank has no read only password",
-   /*108*/ "This memory bank has no read/write password",
-   /*109*/ "1-Wire is shorted",
-   /*110*/ "Error communicating with 1-Wire adapter",
-   /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",
-   /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",
-   /*113*/ "Mission can not be stopped while one is not in progress",
-   /*114*/ "Error stopping the mission",
-   /*115*/ "Port number is outside (0,MAX_PORTNUM) interval",
-   /*116*/ "Level of the 1-Wire was not changed",
-   /*117*/ "Both the Read Only and Read Write Passwords must be set",
-   /*118*/ "Failure to change latch state."
-   /*119*/ "Could not open usb port through libusb",
-   /*120*/ "Libusb DS2490 port already opened",
-   /*121*/ "Failed to set libusb configuration",
-   /*122*/ "Failed to claim libusb interface",
-   /*123*/ "Failed to set libusb altinterface",
-   /*124*/ "No adapter found at this port number"
-   };
-
-   char *owGetErrorMsg(int err)
-   {
-      return owErrorMsg[err];
-   }
-
-#ifndef __C51__
-   //--------------------------------------------------------------------------
-   // The 'owPrintErrorMsg' is the method for printing an error from the stack.
-   // The destination for the print is specified by the argument, fileno, which
-   // can be stderr, stdout, or a log file.  In non-debug mode, the output is
-   // of the form:
-   // Error num: Error msg
-   //
-   // In debug-mode, the output is of the form:
-   // Error num: filename line#: Error msg
-   //
-   // NOTE: This function has the side-effect of popping the error off the stack.
-   //
-   // Arguments:  FILE*: the destination for printing.
-   //
-   void owPrintErrorMsg(FILE *filenum)
-   {
-   #ifdef DEBUG
-      int l = owErrorStack[ owErrorPointer ].lineno;
-      char *f = owErrorStack[ owErrorPointer ].filename;
-      int err = owGetErrorNum();
-      fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
-   #else
-      int err = owGetErrorNum();
-      fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);
-   #endif
-   }
-#endif //__C51__
-
-   // Same as above, except uses default printf output
-   void owPrintErrorMsgStd()
-   {
-   #ifdef DEBUG
-      int l = owErrorStack[ owErrorPointer ].lineno;
-      char *f = owErrorStack[ owErrorPointer ].filename;
-      int err = owGetErrorNum();
-      printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
-   #else
-      int err = owGetErrorNum();
-      printf("Error %d: %s\r\n",err,owErrorMsg[err]);
-   #endif
-   }
-#endif
-
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+// owerr.c - Library functions for error handling with 1-Wire library\r
+//\r
+// Version: 1.00\r
+//\r
+\r
+#include <string.h>\r
+#ifndef _WIN32_WCE\r
+#include <stdio.h>\r
+#endif\r
+#ifdef _WIN64\r
+#include <stdio.h>\r
+#endif\r
+#include "ownet.h"\r
+\r
+#ifndef SIZE_OWERROR_STACK\r
+   #ifdef SMALL_MEMORY_TARGET\r
+      //for small memory, only hole 1 error\r
+      #define SIZE_OWERROR_STACK 1\r
+   #else\r
+      #define SIZE_OWERROR_STACK 10\r
+   #endif\r
+#endif\r
+\r
+//---------------------------------------------------------------------------\r
+// Variables\r
+//---------------------------------------------------------------------------\r
+\r
+// Error Struct for holding error information.\r
+// In DEBUG, this will also hold the line number and filename.\r
+typedef struct\r
+{\r
+   int owErrorNum;\r
+#ifdef DEBUG\r
+   int lineno;\r
+   char *filename;\r
+#endif\r
+} owErrorStruct;\r
+\r
+// Ring-buffer used for stack.\r
+// In case of overflow, deepest error is over-written.\r
+static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];\r
+\r
+// Stack pointer to top-most error.\r
+static int owErrorPointer = 0;\r
+\r
+\r
+//---------------------------------------------------------------------------\r
+// Functions Definitions\r
+//---------------------------------------------------------------------------\r
+int owGetErrorNum(void);\r
+void owClearError(void);\r
+int owHasErrors(void);\r
+#ifdef DEBUG\r
+   void owRaiseError(int,int,char*);\r
+#else\r
+   void owRaiseError(int);\r
+#endif\r
+#ifndef SMALL_MEMORY_TARGET\r
+   void owPrintErrorMsg(FILE *);\r
+   void owPrintErrorMsgStd();\r
+   char *owGetErrorMsg(int);\r
+#endif\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owGetErroNum' returns the error code of the top-most error on the\r
+// error stack.  NOTE: This function has the side effect of popping the\r
+// current error off the stack.  All successive calls to 'owGetErrorNum'\r
+// will further clear the error stack.\r
+//\r
+// For list of error codes, see 'ownet.h'\r
+//\r
+// Returns:   int :  The error code of the top-most error on the stack\r
+//\r
+int owGetErrorNum(void)\r
+{\r
+   int i = owErrorStack[ owErrorPointer ].owErrorNum;\r
+   owErrorStack[ owErrorPointer ].owErrorNum = 0;\r
+   if(!owErrorPointer)\r
+      owErrorPointer = SIZE_OWERROR_STACK - 1;\r
+   else\r
+      owErrorPointer = (owErrorPointer - 1);\r
+   return i;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owClearError' clears all the errors.\r
+//\r
+void owClearError(void)\r
+{\r
+   owErrorStack[ owErrorPointer ].owErrorNum = 0;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owHasErrors' is a boolean test function which tests whether or not\r
+// a valid error is waiting on the stack.\r
+//\r
+// Returns:   TRUE (1) : When there are errors on the stack.\r
+//            FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.\r
+//\r
+int owHasErrors(void)\r
+{\r
+   if(owErrorStack[ owErrorPointer ].owErrorNum)\r
+      return 1; //TRUE\r
+   else\r
+      return 0; //FALSE\r
+}\r
+\r
+#ifdef DEBUG\r
+   //--------------------------------------------------------------------------\r
+   // The 'owRaiseError' is the method for raising an error onto the error\r
+   // stack.\r
+   //\r
+   // Arguments:  int err - the error code you wish to raise.\r
+   //             int lineno - DEBUG only - the line number where it was raised\r
+   //             char* filename - DEBUG only - the file name where it occured.\r
+   //\r
+   void owRaiseError(int err, int lineno, char* filename)\r
+   {\r
+      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;\r
+      owErrorStack[ owErrorPointer ].owErrorNum = err;\r
+      owErrorStack[ owErrorPointer ].lineno = lineno;\r
+      owErrorStack[ owErrorPointer ].filename = filename;\r
+   }\r
+#else\r
+   //--------------------------------------------------------------------------\r
+   // The 'owRaiseError' is the method for raising an error onto the error\r
+   // stack.\r
+   //\r
+   // Arguments:  int err - the error code you wish to raise.\r
+   //\r
+   void owRaiseError(int err)\r
+   {\r
+      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;\r
+      owErrorStack[ owErrorPointer ].owErrorNum = err;\r
+   }\r
+#endif\r
+\r
+\r
+// SMALL_MEMORY_TARGET - embedded microcontrollers, where these\r
+// messaging functions might not make any sense.\r
+#ifndef SMALL_MEMORY_TARGET\r
+   //Array of meaningful error messages to associate with codes.\r
+   //Not used on targets with low memory (i.e. PIC).\r
+   static char *owErrorMsg[125] =\r
+   {\r
+   /*000*/ "No Error Was Set",\r
+   /*001*/ "No Devices found on 1-Wire Network",\r
+   /*002*/ "1-Wire Net Reset Failed",\r
+   /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",\r
+   /*004*/ "Access Failed: Could not select device",\r
+   /*005*/ "DS2480B Adapter Not Detected",\r
+   /*006*/ "DS2480B: Wrong Baud",\r
+   /*007*/ "DS2480B: Bad Response",\r
+   /*008*/ "Open COM Failed",\r
+   /*009*/ "Write COM Failed",\r
+   /*010*/ "Read COM Failed",\r
+   /*011*/ "Data Block Too Large",\r
+   /*012*/ "Block Transfer failed",\r
+   /*013*/ "Program Pulse Failed",\r
+   /*014*/ "Program Byte Failed",\r
+   /*015*/ "Write Byte Failed",\r
+   /*016*/ "Read Byte Failed",\r
+   /*017*/ "Write Verify Failed",\r
+   /*018*/ "Read Verify Failed",\r
+   /*019*/ "Write Scratchpad Failed",\r
+   /*020*/ "Copy Scratchpad Failed",\r
+   /*021*/ "Incorrect CRC Length",\r
+   /*022*/ "CRC Failed",\r
+   /*023*/ "Failed to acquire a necessary system resource",\r
+   /*024*/ "Failed to initialize system resource",\r
+   /*025*/ "Data too long to fit on specified device.",\r
+   /*026*/ "Read exceeds memory bank end.",\r
+   /*027*/ "Write exceeds memory bank end.",\r
+   /*028*/ "Device select failed",\r
+   /*029*/ "Read Scratch Pad verify failed.",\r
+   /*030*/ "Copy scratchpad complete not found",\r
+   /*031*/ "Erase scratchpad complete not found",\r
+   /*032*/ "Address read back from scrachpad was incorrect",\r
+   /*033*/ "Read page with extra-info not supported by this memory bank",\r
+   /*034*/ "Read page packet with extra-info not supported by this memory bank",\r
+   /*035*/ "Length of packet requested exceeds page size",\r
+   /*036*/ "Invalid length in packet",\r
+   /*037*/ "Program pulse required but not available",\r
+   /*038*/ "Trying to access a read-only memory bank",\r
+   /*039*/ "Current bank is not general purpose memory",\r
+   /*040*/ "Read back from write compare is incorrect, page may be locked",\r
+   /*041*/ "Invalid page number for this memory bank",\r
+   /*042*/ "Read page with CRC not supported by this memory bank",\r
+   /*043*/ "Read page with CRC and extra-info not supported by this memory bank",\r
+   /*044*/ "Read back from write incorrect, could not lock page",\r
+   /*045*/ "Read back from write incorrect, could not lock redirect byte",\r
+   /*046*/ "The read of the status was not completed.",\r
+   /*047*/ "Page redirection not supported by this memory bank",\r
+   /*048*/ "Lock Page redirection not supported by this memory bank",\r
+   /*049*/ "Read back byte on EPROM programming did not match.",\r
+   /*050*/ "Can not write to a page that is locked.",\r
+   /*051*/ "Can not lock a redirected page that has already been locked.",\r
+   /*052*/ "Trying to redirect a locked redirected page.",\r
+   /*053*/ "Trying to lock a page that is already locked.",\r
+   /*054*/ "Trying to write to a memory bank that is write protected.",\r
+   /*055*/ "Error due to not matching MAC.",\r
+   /*056*/ "Memory Bank is write protected.",\r
+   /*057*/ "Secret is write protected, can not Load First Secret.",\r
+   /*058*/ "Error in Reading Scratchpad after Computing Next Secret.",\r
+   /*059*/ "Load Error from Loading First Secret.",\r
+   /*060*/ "Power delivery required but not available",\r
+   /*061*/ "Not a valid file name.",\r
+   /*062*/ "Unable to Create a Directory in this part.",\r
+   /*063*/ "That file already exists.",\r
+   /*064*/ "The directory is not empty.",\r
+   /*065*/ "The wrong type of part for this operation.",\r
+   /*066*/ "The max len for this file is too small.",\r
+   /*067*/ "This is not a write once bank.",\r
+   /*068*/ "The file can not be found.",\r
+   /*069*/ "There is not enough space available.",\r
+   /*070*/ "There is not a page to match that bit in the bitmap.",\r
+   /*071*/ "There are no jobs for EPROM parts.",\r
+   /*072*/ "Function not supported to modify attributes.",\r
+   /*073*/ "Handle is not in use.",\r
+   /*074*/ "Tring to read a write only file.",\r
+   /*075*/ "There is no handle available for use.",\r
+   /*076*/ "The directory provided is an invalid directory.",\r
+   /*077*/ "Handle does not exist.",\r
+   /*078*/ "Serial Number did not match with current job.",\r
+   /*079*/ "Can not program EPROM because a non-EPROM part on the network.",\r
+   /*080*/ "Write protect redirection byte is set.",\r
+   /*081*/ "There is an inappropriate directory length.",\r
+   /*082*/ "The file has already been terminated.",\r
+   /*083*/ "Failed to read memory page of iButton part.",\r
+   /*084*/ "Failed to match scratchpad of iButton part.",\r
+   /*085*/ "Failed to erase scratchpad of iButton part.",\r
+   /*086*/ "Failed to read scratchpad of iButton part.",\r
+   /*087*/ "Failed to execute SHA function on SHA iButton.",\r
+   /*088*/ "SHA iButton did not return a status completion byte.",\r
+   /*089*/ "Write data page failed.",\r
+   /*090*/ "Copy secret into secret memory pages failed.",\r
+   /*091*/ "Bind unique secret to iButton failed.",\r
+   /*092*/ "Could not install secret into user token.",\r
+   /*093*/ "Transaction Incomplete: signature did not match.",\r
+   /*094*/ "Transaction Incomplete: could not sign service data.",\r
+   /*095*/ "User token did not provide a valid authentication response.",\r
+   /*096*/ "Failed to answer a challenge on the user token.",\r
+   /*097*/ "Failed to create a challenge on the coprocessor.",\r
+   /*098*/ "Transaction Incomplete: service data was not valid.",\r
+   /*099*/ "Transaction Incomplete: service data was not updated.",\r
+   /*100*/ "Unrecoverable, catastrophic service failure occured.",\r
+   /*101*/ "Load First Secret from scratchpad data failed.",\r
+   /*102*/ "Failed to match signature of user's service data.",\r
+   /*103*/ "Subkey out of range for the DS1991.",\r
+   /*104*/ "Block ID out of range for the DS1991",\r
+   /*105*/ "Password is enabled",\r
+   /*106*/ "Password is invalid",\r
+   /*107*/ "This memory bank has no read only password",\r
+   /*108*/ "This memory bank has no read/write password",\r
+   /*109*/ "1-Wire is shorted",\r
+   /*110*/ "Error communicating with 1-Wire adapter",\r
+   /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",\r
+   /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",\r
+   /*113*/ "Mission can not be stopped while one is not in progress",\r
+   /*114*/ "Error stopping the mission",\r
+   /*115*/ "Port number is outside (0,MAX_PORTNUM) interval",\r
+   /*116*/ "Level of the 1-Wire was not changed",\r
+   /*117*/ "Both the Read Only and Read Write Passwords must be set",\r
+   /*118*/ "Failure to change latch state."\r
+   /*119*/ "Could not open usb port through libusb",\r
+   /*120*/ "Libusb DS2490 port already opened",\r
+   /*121*/ "Failed to set libusb configuration",\r
+   /*122*/ "Failed to claim libusb interface",\r
+   /*123*/ "Failed to set libusb altinterface",\r
+   /*124*/ "No adapter found at this port number"\r
+   };\r
+\r
+   char *owGetErrorMsg(int err)\r
+   {\r
+      return owErrorMsg[err];\r
+   }\r
+\r
+#ifndef __C51__\r
+   //--------------------------------------------------------------------------\r
+   // The 'owPrintErrorMsg' is the method for printing an error from the stack.\r
+   // The destination for the print is specified by the argument, fileno, which\r
+   // can be stderr, stdout, or a log file.  In non-debug mode, the output is\r
+   // of the form:\r
+   // Error num: Error msg\r
+   //\r
+   // In debug-mode, the output is of the form:\r
+   // Error num: filename line#: Error msg\r
+   //\r
+   // NOTE: This function has the side-effect of popping the error off the stack.\r
+   //\r
+   // Arguments:  FILE*: the destination for printing.\r
+   //\r
+   void owPrintErrorMsg(FILE *filenum)\r
+   {\r
+   #ifdef DEBUG\r
+      int l = owErrorStack[ owErrorPointer ].lineno;\r
+      char *f = owErrorStack[ owErrorPointer ].filename;\r
+      int err = owGetErrorNum();\r
+      fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);\r
+   #else\r
+      int err = owGetErrorNum();\r
+      fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);\r
+   #endif\r
+   }\r
+#endif //__C51__\r
+\r
+   // Same as above, except uses default printf output\r
+   void owPrintErrorMsgStd()\r
+   {\r
+   #ifdef DEBUG\r
+      int l = owErrorStack[ owErrorPointer ].lineno;\r
+      char *f = owErrorStack[ owErrorPointer ].filename;\r
+      int err = owGetErrorNum();\r
+      printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);\r
+   #else\r
+      int err = owGetErrorNum();\r
+      printf("Error %d: %s\r\n",err,owErrorMsg[err]);\r
+   #endif\r
+   }\r
+#endif\r
+\r
index a74cd95..7c0c144 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-// ownet.h - Include file for 1-Wire Net library
-//
-// Version: 2.10
-//
-// History: 1.02 -> 1.03 Make sure uchar is not defined twice.
-//          1.03 -> 2.00 Changed 'MLan' to 'ow'.
-//          2.00 -> 2.01 Added error handling. Added circular-include check.
-//          2.01 -> 2.10 Added raw memory error handling and SMALLINT
-//          2.10 -> 3.00 Added memory bank functionality
-//                       Added file I/O operations
-//
-
-#ifndef OWNET_H
-#define OWNET_H
-
-//--------------------------------------------------------------//
-// Common Includes to ownet applications
-//--------------------------------------------------------------//
-#include <stdlib.h>
-
-
-//--------------------------------------------------------------//
-// Target Specific Information
-//--------------------------------------------------------------//
-//--------------------------------------------------------------//
-// Handhelds (PalmOS, WinCE)
-//--------------------------------------------------------------//
-#ifdef __MC68K__
-   //MC68K is the type of processor in the PILOT
-   //Metrowerk's CodeWarrior defines this symbol
-   #include <string.h>
-   #ifndef strcmp
-      #include <StringMgr.h>
-      #define strcmp StrCompare
-   #endif
-   #include <file_struc.h>
-#endif
-
-#ifdef _WIN32_WCE
-   //All of our projects had this flag defined by default (_WIN32_WCE),
-   //but I'm not 100% positive that this is _the_ definitive
-   //flag to use to identify a WinCE system.
-   #include "WinCElnk.h"
-   #ifndef FILE
-      #define FILE int
-      extern int sprintf(char *buffer, char *format,...);
-      extern void fprintf(FILE *fp, char *format,...);
-      extern void printf(char *format,...);
-   #endif
-#endif
-
-#if !defined(_WIN32_WCE) && !defined(__MC68K__)
-   #include <stdio.h>
-#endif
-
-#ifdef __C51__
-   #define FILE int
-   #define exit(c) return
-   typedef unsigned int ushort;
-   typedef unsigned long ulong;
-   #define SMALLINT uchar
-#endif
-
-#ifdef __ICCMAXQ__
-   #define FILE int
-   #define stdout 0
-   #define stdin  1
-   #define stderr 2
-   typedef unsigned int ushort;
-   typedef unsigned long ulong;
-   #define SMALLINT short
-   #define main micro_main
-   #define real_main main
-   #define SMALL_MEMORY_TARGET
-#endif
-
-
-//--------------------------------------------------------------//
-// Typedefs
-//--------------------------------------------------------------//
-#ifndef SMALLINT
-   //
-   // purpose of smallint is for compile-time changing of formal
-   // parameters and return values of functions.  For each target
-   // machine, an integer is alleged to represent the most "simple"
-   // number representable by that architecture.  This should, in
-   // most cases, produce optimal code for that particular arch.
-   // BUT...  The majority of compilers designed for embedded
-   // processors actually keep an int at 16 bits, although the
-   // architecture might only be comfortable with 8 bits.
-   // The default size of smallint will be the same as that of
-   // an integer, but this allows for easy overriding of that size.
-   //
-   // NOTE:
-   // In all cases where a smallint is used, it is assumed that
-   // decreasing the size of this integer to something as low as
-   // a single byte _will_not_ change the functionality of the
-   // application.  e.g. a loop counter that will iterate through
-   // several kilobytes of data should not be SMALLINT.  The most
-   // common place you'll see smallint is for boolean return types.
-   //
-   #define SMALLINT int
-#endif
-
-// setting max baud
-#ifdef _WINDOWS
-   // 0x02 = PARAMSET_19200
-#define MAX_BAUD 0x02
-#else
-   // 0x06 = PARMSET_115200
-#define MAX_BAUD 0x06
-#endif
-
-#ifndef OW_UCHAR
-   #define OW_UCHAR
-   typedef unsigned char uchar;
-   #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))
-      typedef unsigned long ulong;
-      //ushort already defined in sys/types.h
-      #include <sys/types.h>
-   #else
-      #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS)  || defined(_WINDOWS) || defined(__MINGW32__)
-         typedef unsigned short ushort;
-         typedef unsigned long ulong;
-      #endif
-   #endif
-   #ifdef __sun__
-      #include <sys/types.h>
-   #endif
-   #ifdef SDCC
-      //intent of ushort is 2 bytes unsigned.
-      //for ds390 in sdcc, an int, not a short,
-      //is 2 bytes.
-      typedef unsigned int ushort;
-   #endif
-#endif
-
-// general defines
-#define WRITE_FUNCTION 1
-#define READ_FUNCTION  0
-
-// error codes
-// todo: investigate these and replace with new Error Handling library
-#define READ_ERROR    -1
-#define INVALID_DIR   -2
-#define NO_FILE       -3
-#define WRITE_ERROR   -4
-#define WRONG_TYPE    -5
-#define FILE_TOO_BIG  -6
-
-// Misc
-#define FALSE          0
-#define TRUE           1
-
-#ifndef MAX_PORTNUM
-   #define MAX_PORTNUM    16
-#endif
-
-// mode bit flags
-#define MODE_NORMAL                    0x00
-#define MODE_OVERDRIVE                 0x01
-#define MODE_STRONG5                   0x02
-#define MODE_PROGRAM                   0x04
-#define MODE_BREAK                     0x08
-
-// Output flags
-#define LV_ALWAYS          2
-#define LV_OPTIONAL        1
-#define LV_VERBOSE         0
-
-//--------------------------------------------------------------//
-// Error handling
-//--------------------------------------------------------------//
-extern int owGetErrorNum(void);
-extern int owHasErrors(void);
-
-//Clears the stack.
-#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();
-
-#ifdef DEBUG
-   //Raises an exception with extra debug info
-   #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)
-   extern void owRaiseError(int,int,char*);
-   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}
-#else
-   //Raises an exception with just the error code
-   #define OWERROR(err) owRaiseError(err)
-   extern void owRaiseError(int);
-   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}
-#endif
-
-#ifdef SMALL_MEMORY_TARGET
-   #define OWERROR_DUMP(fileno) /*no-op*/;
-#else
-   //Prints the stack out to the given file.
-   #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);
-   extern void owPrintErrorMsg(FILE *);
-   extern void owPrintErrorMsgStd();
-   extern char *owGetErrorMsg(int);
-#endif
-
-#define OWERROR_NO_ERROR_SET                    0
-#define OWERROR_NO_DEVICES_ON_NET               1
-#define OWERROR_RESET_FAILED                    2
-#define OWERROR_SEARCH_ERROR                    3
-#define OWERROR_ACCESS_FAILED                   4
-#define OWERROR_DS2480_NOT_DETECTED             5
-#define OWERROR_DS2480_WRONG_BAUD               6
-#define OWERROR_DS2480_BAD_RESPONSE             7
-#define OWERROR_OPENCOM_FAILED                  8
-#define OWERROR_WRITECOM_FAILED                 9
-#define OWERROR_READCOM_FAILED                  10
-#define OWERROR_BLOCK_TOO_BIG                   11
-#define OWERROR_BLOCK_FAILED                    12
-#define OWERROR_PROGRAM_PULSE_FAILED            13
-#define OWERROR_PROGRAM_BYTE_FAILED             14
-#define OWERROR_WRITE_BYTE_FAILED               15
-#define OWERROR_READ_BYTE_FAILED                16
-#define OWERROR_WRITE_VERIFY_FAILED             17
-#define OWERROR_READ_VERIFY_FAILED              18
-#define OWERROR_WRITE_SCRATCHPAD_FAILED         19
-#define OWERROR_COPY_SCRATCHPAD_FAILED          20
-#define OWERROR_INCORRECT_CRC_LENGTH            21
-#define OWERROR_CRC_FAILED                      22
-#define OWERROR_GET_SYSTEM_RESOURCE_FAILED      23
-#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED     24
-#define OWERROR_DATA_TOO_LONG                   25
-#define OWERROR_READ_OUT_OF_RANGE               26
-#define OWERROR_WRITE_OUT_OF_RANGE              27
-#define OWERROR_DEVICE_SELECT_FAIL              28
-#define OWERROR_READ_SCRATCHPAD_VERIFY          29
-#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND       30
-#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND      31
-#define OWERROR_ADDRESS_READ_BACK_FAILED        32
-#define OWERROR_EXTRA_INFO_NOT_SUPPORTED        33
-#define OWERROR_PG_PACKET_WITHOUT_EXTRA         34
-#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE      35
-#define OWERROR_INVALID_PACKET_LENGTH           36
-#define OWERROR_NO_PROGRAM_PULSE                37
-#define OWERROR_READ_ONLY                       38
-#define OWERROR_NOT_GENERAL_PURPOSE             39
-#define OWERROR_READ_BACK_INCORRECT             40
-#define OWERROR_INVALID_PAGE_NUMBER             41
-#define OWERROR_CRC_NOT_SUPPORTED               42
-#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED    43
-#define OWERROR_READ_BACK_NOT_VALID             44
-#define OWERROR_COULD_NOT_LOCK_REDIRECT         45
-#define OWERROR_READ_STATUS_NOT_COMPLETE        46
-#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED  47
-#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED  48
-#define OWERROR_READBACK_EPROM_FAILED           49
-#define OWERROR_PAGE_LOCKED                     50
-#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN   51
-#define OWERROR_REDIRECTED_PAGE                 52
-#define OWERROR_PAGE_ALREADY_LOCKED             53
-#define OWERROR_WRITE_PROTECTED                 54
-#define OWERROR_NONMATCHING_MAC                 55
-#define OWERROR_WRITE_PROTECT                   56
-#define OWERROR_WRITE_PROTECT_SECRET            57
-#define OWERROR_COMPUTE_NEXT_SECRET             58
-#define OWERROR_LOAD_FIRST_SECRET               59
-#define OWERROR_POWER_NOT_AVAILABLE             60
-#define OWERROR_XBAD_FILENAME                   61
-#define OWERROR_XUNABLE_TO_CREATE_DIR           62
-#define OWERROR_REPEAT_FILE                     63
-#define OWERROR_DIRECTORY_NOT_EMPTY             64
-#define OWERROR_WRONG_TYPE                      65
-#define OWERROR_BUFFER_TOO_SMALL                66
-#define OWERROR_NOT_WRITE_ONCE                  67
-#define OWERROR_FILE_NOT_FOUND                  68
-#define OWERROR_OUT_OF_SPACE                    69
-#define OWERROR_TOO_LARGE_BITNUM                70
-#define OWERROR_NO_PROGRAM_JOB                  71
-#define OWERROR_FUNC_NOT_SUP                    72
-#define OWERROR_HANDLE_NOT_USED                 73
-#define OWERROR_FILE_WRITE_ONLY                 74
-#define OWERROR_HANDLE_NOT_AVAIL                75
-#define OWERROR_INVALID_DIRECTORY               76
-#define OWERROR_HANDLE_NOT_EXIST                77
-#define OWERROR_NONMATCHING_SNUM                78
-#define OWERROR_NON_PROGRAM_PARTS               79
-#define OWERROR_PROGRAM_WRITE_PROTECT           80
-#define OWERROR_FILE_READ_ERR                   81
-#define OWERROR_ADDFILE_TERMINATED              82
-#define OWERROR_READ_MEMORY_PAGE_FAILED         83
-#define OWERROR_MATCH_SCRATCHPAD_FAILED         84
-#define OWERROR_ERASE_SCRATCHPAD_FAILED         85
-#define OWERROR_READ_SCRATCHPAD_FAILED          86
-#define OWERROR_SHA_FUNCTION_FAILED             87
-#define OWERROR_NO_COMPLETION_BYTE              88
-#define OWERROR_WRITE_DATA_PAGE_FAILED          89
-#define OWERROR_COPY_SECRET_FAILED              90
-#define OWERROR_BIND_SECRET_FAILED              91
-#define OWERROR_INSTALL_SECRET_FAILED           92
-#define OWERROR_VERIFY_SIG_FAILED               93
-#define OWERROR_SIGN_SERVICE_DATA_FAILED        94
-#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED     95
-#define OWERROR_ANSWER_CHALLENGE_FAILED         96
-#define OWERROR_CREATE_CHALLENGE_FAILED         97
-#define OWERROR_BAD_SERVICE_DATA                98
-#define OWERROR_SERVICE_DATA_NOT_UPDATED        99
-#define OWERROR_CATASTROPHIC_SERVICE_FAILURE    100
-#define OWERROR_LOAD_FIRST_SECRET_FAILED        101
-#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED  102
-#define OWERROR_KEY_OUT_OF_RANGE                103
-#define OWERROR_BLOCK_ID_OUT_OF_RANGE           104
-#define OWERROR_PASSWORDS_ENABLED               105
-#define OWERROR_PASSWORD_INVALID                106
-#define OWERROR_NO_READ_ONLY_PASSWORD           107
-#define OWERROR_NO_READ_WRITE_PASSWORD          108
-#define OWERROR_OW_SHORTED                      109
-#define OWERROR_ADAPTER_ERROR                   110
-#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED      111
-#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED     112
-#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY  113
-#define OWERROR_HYGRO_STOP_MISSION_ERROR        114
-#define OWERROR_PORTNUM_ERROR                   115
-#define OWERROR_LEVEL_FAILED                    116
-#define OWERROR_PASSWORD_NOT_SET                117
-#define OWERROR_LATCH_NOT_SET                   118
-#define OWERROR_LIBUSB_OPEN_FAILED              119
-#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED    120
-#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR  121
-#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR    122
-#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR   123
-#define OWERROR_LIBUSB_NO_ADAPTER_FOUND         124
-
-// One Wire functions defined in ownetu.c
-SMALLINT  owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
-SMALLINT  owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
-void      owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);
-void      owFamilySearchSetup(int portnum, SMALLINT search_family);
-void      owSkipFamily(int portnum);
-SMALLINT  owAccess(int portnum);
-SMALLINT  owVerify(int portnum, SMALLINT alarm_only);
-SMALLINT  owOverdriveAccess(int portnum);
-
-
-// external One Wire functions defined in owsesu.c
- SMALLINT owAcquire(int portnum, char *port_zstr);
- int      owAcquireEx(char *port_zstr);
- void     owRelease(int portnum);
-
-// external One Wire functions defined in findtype.c
-// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);
-
-// external One Wire functions from link layer owllu.c
-SMALLINT owTouchReset(int portnum);
-SMALLINT owTouchBit(int portnum, SMALLINT sendbit);
-SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);
-SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);
-SMALLINT owReadByte(int portnum);
-SMALLINT owSpeed(int portnum, SMALLINT new_speed);
-SMALLINT owLevel(int portnum, SMALLINT new_level);
-SMALLINT owProgramPulse(int portnum);
-SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);
-SMALLINT owReadBytePower(int portnum);
-SMALLINT owHasPowerDelivery(int portnum);
-SMALLINT owHasProgramPulse(int portnum);
-SMALLINT owHasOverDrive(int portnum);
-SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);
-// external One Wire global from owllu.c
-extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;
-
-// external One Wire functions from transaction layer in owtrnu.c
-SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);
-SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);
-SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,
-                          SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);
-SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
-                       SMALLINT crc_type, SMALLINT do_access);
-
-// link functions
-void      msDelay(int len);
-long      msGettick(void);
-
-// ioutil.c functions prototypes
-int  EnterString(char *msg, char *buf, int min, int max);
-int  EnterNum(char *msg, int numchars, long *value, long min, long max);
-int  EnterHex(char *msg, int numchars, ulong *value);
-int  ToHex(char ch);
-int  getkeystroke(void);
-int  key_abort(void);
-void ExitProg(char *msg, int exit_code);
-int  getData(uchar *write_buff, int max_len, SMALLINT gethex);
-void PrintHex(uchar* buffer, int cnt);
-void PrintChars(uchar* buffer, int cnt);
-void PrintSerialNum(uchar* buffer);
-
-// external functions defined in crcutil.c
-void setcrc16(int portnum, ushort reset);
-ushort docrc16(int portnum, ushort cdata);
-void setcrc8(int portnum, uchar reset);
-uchar docrc8(int portnum, uchar x);
-
-#endif //OWNET_H
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+// ownet.h - Include file for 1-Wire Net library\r
+//\r
+// Version: 2.10\r
+//\r
+// History: 1.02 -> 1.03 Make sure uchar is not defined twice.\r
+//          1.03 -> 2.00 Changed 'MLan' to 'ow'.\r
+//          2.00 -> 2.01 Added error handling. Added circular-include check.\r
+//          2.01 -> 2.10 Added raw memory error handling and SMALLINT\r
+//          2.10 -> 3.00 Added memory bank functionality\r
+//                       Added file I/O operations\r
+//\r
+\r
+#ifndef OWNET_H\r
+#define OWNET_H\r
+\r
+//--------------------------------------------------------------//\r
+// Common Includes to ownet applications\r
+//--------------------------------------------------------------//\r
+#include <stdlib.h>\r
+\r
+\r
+//--------------------------------------------------------------//\r
+// Target Specific Information\r
+//--------------------------------------------------------------//\r
+//--------------------------------------------------------------//\r
+// Handhelds (PalmOS, WinCE)\r
+//--------------------------------------------------------------//\r
+#ifdef __MC68K__\r
+   //MC68K is the type of processor in the PILOT\r
+   //Metrowerk's CodeWarrior defines this symbol\r
+   #include <string.h>\r
+   #ifndef strcmp\r
+      #include <StringMgr.h>\r
+      #define strcmp StrCompare\r
+   #endif\r
+   #include <file_struc.h>\r
+#endif\r
+\r
+#ifdef _WIN32_WCE\r
+   //All of our projects had this flag defined by default (_WIN32_WCE),\r
+   //but I'm not 100% positive that this is _the_ definitive\r
+   //flag to use to identify a WinCE system.\r
+   #include "WinCElnk.h"\r
+   #ifndef FILE\r
+      #define FILE int\r
+      extern int sprintf(char *buffer, char *format,...);\r
+      extern void fprintf(FILE *fp, char *format,...);\r
+      extern void printf(char *format,...);\r
+   #endif\r
+#endif\r
+\r
+#if !defined(_WIN32_WCE) && !defined(__MC68K__)\r
+   #include <stdio.h>\r
+#endif\r
+\r
+#ifdef __C51__\r
+   #define FILE int\r
+   #define exit(c) return\r
+   typedef unsigned int ushort;\r
+   typedef unsigned long ulong;\r
+   #define SMALLINT uchar\r
+#endif\r
+\r
+#ifdef __ICCMAXQ__\r
+   #define FILE int\r
+   #define stdout 0\r
+   #define stdin  1\r
+   #define stderr 2\r
+   typedef unsigned int ushort;\r
+   typedef unsigned long ulong;\r
+   #define SMALLINT short\r
+   #define main micro_main\r
+   #define real_main main\r
+   #define SMALL_MEMORY_TARGET\r
+#endif\r
+\r
+\r
+//--------------------------------------------------------------//\r
+// Typedefs\r
+//--------------------------------------------------------------//\r
+#ifndef SMALLINT\r
+   //\r
+   // purpose of smallint is for compile-time changing of formal\r
+   // parameters and return values of functions.  For each target\r
+   // machine, an integer is alleged to represent the most "simple"\r
+   // number representable by that architecture.  This should, in\r
+   // most cases, produce optimal code for that particular arch.\r
+   // BUT...  The majority of compilers designed for embedded\r
+   // processors actually keep an int at 16 bits, although the\r
+   // architecture might only be comfortable with 8 bits.\r
+   // The default size of smallint will be the same as that of\r
+   // an integer, but this allows for easy overriding of that size.\r
+   //\r
+   // NOTE:\r
+   // In all cases where a smallint is used, it is assumed that\r
+   // decreasing the size of this integer to something as low as\r
+   // a single byte _will_not_ change the functionality of the\r
+   // application.  e.g. a loop counter that will iterate through\r
+   // several kilobytes of data should not be SMALLINT.  The most\r
+   // common place you'll see smallint is for boolean return types.\r
+   //\r
+   #define SMALLINT int\r
+#endif\r
+\r
+// setting max baud\r
+#ifdef _WINDOWS\r
+   // 0x02 = PARAMSET_19200\r
+#define MAX_BAUD 0x02\r
+#else\r
+   // 0x06 = PARMSET_115200\r
+#define MAX_BAUD 0x06\r
+#endif\r
+\r
+#ifndef OW_UCHAR\r
+   #define OW_UCHAR\r
+   typedef unsigned char uchar;\r
+   #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))\r
+      typedef unsigned long ulong;\r
+      //ushort already defined in sys/types.h\r
+      #include <sys/types.h>\r
+   #else\r
+      #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS)  || defined(_WINDOWS) || defined(__MINGW32__)\r
+         typedef unsigned short ushort;\r
+         typedef unsigned long ulong;\r
+      #endif\r
+   #endif\r
+   #ifdef __sun__\r
+      #include <sys/types.h>\r
+   #endif\r
+   #ifdef SDCC\r
+      //intent of ushort is 2 bytes unsigned.\r
+      //for ds390 in sdcc, an int, not a short,\r
+      //is 2 bytes.\r
+      typedef unsigned int ushort;\r
+   #endif\r
+#endif\r
+\r
+// general defines\r
+#define WRITE_FUNCTION 1\r
+#define READ_FUNCTION  0\r
+\r
+// error codes\r
+// todo: investigate these and replace with new Error Handling library\r
+#define READ_ERROR    -1\r
+#define INVALID_DIR   -2\r
+#define NO_FILE       -3\r
+#define WRITE_ERROR   -4\r
+#define WRONG_TYPE    -5\r
+#define FILE_TOO_BIG  -6\r
+\r
+// Misc\r
+#define FALSE          0\r
+#define TRUE           1\r
+\r
+#ifndef MAX_PORTNUM\r
+   #define MAX_PORTNUM    16\r
+#endif\r
+\r
+// mode bit flags\r
+#define MODE_NORMAL                    0x00\r
+#define MODE_OVERDRIVE                 0x01\r
+#define MODE_STRONG5                   0x02\r
+#define MODE_PROGRAM                   0x04\r
+#define MODE_BREAK                     0x08\r
+\r
+// Output flags\r
+#define LV_ALWAYS          2\r
+#define LV_OPTIONAL        1\r
+#define LV_VERBOSE         0\r
+\r
+//--------------------------------------------------------------//\r
+// Error handling\r
+//--------------------------------------------------------------//\r
+extern int owGetErrorNum(void);\r
+extern int owHasErrors(void);\r
+\r
+//Clears the stack.\r
+#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();\r
+\r
+#ifdef DEBUG\r
+   //Raises an exception with extra debug info\r
+   #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)\r
+   extern void owRaiseError(int,int,char*);\r
+   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}\r
+#else\r
+   //Raises an exception with just the error code\r
+   #define OWERROR(err) owRaiseError(err)\r
+   extern void owRaiseError(int);\r
+   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}\r
+#endif\r
+\r
+#ifdef SMALL_MEMORY_TARGET\r
+   #define OWERROR_DUMP(fileno) /*no-op*/;\r
+#else\r
+   //Prints the stack out to the given file.\r
+   #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);\r
+   extern void owPrintErrorMsg(FILE *);\r
+   extern void owPrintErrorMsgStd();\r
+   extern char *owGetErrorMsg(int);\r
+#endif\r
+\r
+#define OWERROR_NO_ERROR_SET                    0\r
+#define OWERROR_NO_DEVICES_ON_NET               1\r
+#define OWERROR_RESET_FAILED                    2\r
+#define OWERROR_SEARCH_ERROR                    3\r
+#define OWERROR_ACCESS_FAILED                   4\r
+#define OWERROR_DS2480_NOT_DETECTED             5\r
+#define OWERROR_DS2480_WRONG_BAUD               6\r
+#define OWERROR_DS2480_BAD_RESPONSE             7\r
+#define OWERROR_OPENCOM_FAILED                  8\r
+#define OWERROR_WRITECOM_FAILED                 9\r
+#define OWERROR_READCOM_FAILED                  10\r
+#define OWERROR_BLOCK_TOO_BIG                   11\r
+#define OWERROR_BLOCK_FAILED                    12\r
+#define OWERROR_PROGRAM_PULSE_FAILED            13\r
+#define OWERROR_PROGRAM_BYTE_FAILED             14\r
+#define OWERROR_WRITE_BYTE_FAILED               15\r
+#define OWERROR_READ_BYTE_FAILED                16\r
+#define OWERROR_WRITE_VERIFY_FAILED             17\r
+#define OWERROR_READ_VERIFY_FAILED              18\r
+#define OWERROR_WRITE_SCRATCHPAD_FAILED         19\r
+#define OWERROR_COPY_SCRATCHPAD_FAILED          20\r
+#define OWERROR_INCORRECT_CRC_LENGTH            21\r
+#define OWERROR_CRC_FAILED                      22\r
+#define OWERROR_GET_SYSTEM_RESOURCE_FAILED      23\r
+#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED     24\r
+#define OWERROR_DATA_TOO_LONG                   25\r
+#define OWERROR_READ_OUT_OF_RANGE               26\r
+#define OWERROR_WRITE_OUT_OF_RANGE              27\r
+#define OWERROR_DEVICE_SELECT_FAIL              28\r
+#define OWERROR_READ_SCRATCHPAD_VERIFY          29\r
+#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND       30\r
+#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND      31\r
+#define OWERROR_ADDRESS_READ_BACK_FAILED        32\r
+#define OWERROR_EXTRA_INFO_NOT_SUPPORTED        33\r
+#define OWERROR_PG_PACKET_WITHOUT_EXTRA         34\r
+#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE      35\r
+#define OWERROR_INVALID_PACKET_LENGTH           36\r
+#define OWERROR_NO_PROGRAM_PULSE                37\r
+#define OWERROR_READ_ONLY                       38\r
+#define OWERROR_NOT_GENERAL_PURPOSE             39\r
+#define OWERROR_READ_BACK_INCORRECT             40\r
+#define OWERROR_INVALID_PAGE_NUMBER             41\r
+#define OWERROR_CRC_NOT_SUPPORTED               42\r
+#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED    43\r
+#define OWERROR_READ_BACK_NOT_VALID             44\r
+#define OWERROR_COULD_NOT_LOCK_REDIRECT         45\r
+#define OWERROR_READ_STATUS_NOT_COMPLETE        46\r
+#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED  47\r
+#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED  48\r
+#define OWERROR_READBACK_EPROM_FAILED           49\r
+#define OWERROR_PAGE_LOCKED                     50\r
+#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN   51\r
+#define OWERROR_REDIRECTED_PAGE                 52\r
+#define OWERROR_PAGE_ALREADY_LOCKED             53\r
+#define OWERROR_WRITE_PROTECTED                 54\r
+#define OWERROR_NONMATCHING_MAC                 55\r
+#define OWERROR_WRITE_PROTECT                   56\r
+#define OWERROR_WRITE_PROTECT_SECRET            57\r
+#define OWERROR_COMPUTE_NEXT_SECRET             58\r
+#define OWERROR_LOAD_FIRST_SECRET               59\r
+#define OWERROR_POWER_NOT_AVAILABLE             60\r
+#define OWERROR_XBAD_FILENAME                   61\r
+#define OWERROR_XUNABLE_TO_CREATE_DIR           62\r
+#define OWERROR_REPEAT_FILE                     63\r
+#define OWERROR_DIRECTORY_NOT_EMPTY             64\r
+#define OWERROR_WRONG_TYPE                      65\r
+#define OWERROR_BUFFER_TOO_SMALL                66\r
+#define OWERROR_NOT_WRITE_ONCE                  67\r
+#define OWERROR_FILE_NOT_FOUND                  68\r
+#define OWERROR_OUT_OF_SPACE                    69\r
+#define OWERROR_TOO_LARGE_BITNUM                70\r
+#define OWERROR_NO_PROGRAM_JOB                  71\r
+#define OWERROR_FUNC_NOT_SUP                    72\r
+#define OWERROR_HANDLE_NOT_USED                 73\r
+#define OWERROR_FILE_WRITE_ONLY                 74\r
+#define OWERROR_HANDLE_NOT_AVAIL                75\r
+#define OWERROR_INVALID_DIRECTORY               76\r
+#define OWERROR_HANDLE_NOT_EXIST                77\r
+#define OWERROR_NONMATCHING_SNUM                78\r
+#define OWERROR_NON_PROGRAM_PARTS               79\r
+#define OWERROR_PROGRAM_WRITE_PROTECT           80\r
+#define OWERROR_FILE_READ_ERR                   81\r
+#define OWERROR_ADDFILE_TERMINATED              82\r
+#define OWERROR_READ_MEMORY_PAGE_FAILED         83\r
+#define OWERROR_MATCH_SCRATCHPAD_FAILED         84\r
+#define OWERROR_ERASE_SCRATCHPAD_FAILED         85\r
+#define OWERROR_READ_SCRATCHPAD_FAILED          86\r
+#define OWERROR_SHA_FUNCTION_FAILED             87\r
+#define OWERROR_NO_COMPLETION_BYTE              88\r
+#define OWERROR_WRITE_DATA_PAGE_FAILED          89\r
+#define OWERROR_COPY_SECRET_FAILED              90\r
+#define OWERROR_BIND_SECRET_FAILED              91\r
+#define OWERROR_INSTALL_SECRET_FAILED           92\r
+#define OWERROR_VERIFY_SIG_FAILED               93\r
+#define OWERROR_SIGN_SERVICE_DATA_FAILED        94\r
+#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED     95\r
+#define OWERROR_ANSWER_CHALLENGE_FAILED         96\r
+#define OWERROR_CREATE_CHALLENGE_FAILED         97\r
+#define OWERROR_BAD_SERVICE_DATA                98\r
+#define OWERROR_SERVICE_DATA_NOT_UPDATED        99\r
+#define OWERROR_CATASTROPHIC_SERVICE_FAILURE    100\r
+#define OWERROR_LOAD_FIRST_SECRET_FAILED        101\r
+#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED  102\r
+#define OWERROR_KEY_OUT_OF_RANGE                103\r
+#define OWERROR_BLOCK_ID_OUT_OF_RANGE           104\r
+#define OWERROR_PASSWORDS_ENABLED               105\r
+#define OWERROR_PASSWORD_INVALID                106\r
+#define OWERROR_NO_READ_ONLY_PASSWORD           107\r
+#define OWERROR_NO_READ_WRITE_PASSWORD          108\r
+#define OWERROR_OW_SHORTED                      109\r
+#define OWERROR_ADAPTER_ERROR                   110\r
+#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED      111\r
+#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED     112\r
+#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY  113\r
+#define OWERROR_HYGRO_STOP_MISSION_ERROR        114\r
+#define OWERROR_PORTNUM_ERROR                   115\r
+#define OWERROR_LEVEL_FAILED                    116\r
+#define OWERROR_PASSWORD_NOT_SET                117\r
+#define OWERROR_LATCH_NOT_SET                   118\r
+#define OWERROR_LIBUSB_OPEN_FAILED              119\r
+#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED    120\r
+#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR  121\r
+#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR    122\r
+#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR   123\r
+#define OWERROR_LIBUSB_NO_ADAPTER_FOUND         124\r
+\r
+// One Wire functions defined in ownetu.c\r
+SMALLINT  owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only);\r
+SMALLINT  owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only);\r
+void      owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);\r
+void      owFamilySearchSetup(int portnum, SMALLINT search_family);\r
+void      owSkipFamily(int portnum);\r
+SMALLINT  owAccess(int portnum);\r
+SMALLINT  owVerify(int portnum, SMALLINT alarm_only);\r
+SMALLINT  owOverdriveAccess(int portnum);\r
+\r
+\r
+// external One Wire functions defined in owsesu.c\r
+ SMALLINT owAcquire(int portnum, char *port_zstr);\r
+ int      owAcquireEx(char *port_zstr);\r
+ void     owRelease(int portnum);\r
+\r
+// external One Wire functions defined in findtype.c\r
+// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);\r
+\r
+// external One Wire functions from link layer owllu.c\r
+SMALLINT owTouchReset(int portnum);\r
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit);\r
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);\r
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);\r
+SMALLINT owReadByte(int portnum);\r
+SMALLINT owSpeed(int portnum, SMALLINT new_speed);\r
+SMALLINT owLevel(int portnum, SMALLINT new_level);\r
+SMALLINT owProgramPulse(int portnum);\r
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);\r
+SMALLINT owReadBytePower(int portnum);\r
+SMALLINT owHasPowerDelivery(int portnum);\r
+SMALLINT owHasProgramPulse(int portnum);\r
+SMALLINT owHasOverDrive(int portnum);\r
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);\r
+// external One Wire global from owllu.c\r
+extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;\r
+\r
+// external One Wire functions from transaction layer in owtrnu.c\r
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);\r
+SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);\r
+SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,\r
+                          SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);\r
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,\r
+                       SMALLINT crc_type, SMALLINT do_access);\r
+\r
+// link functions\r
+void      msDelay(int len);\r
+long      msGettick(void);\r
+\r
+// ioutil.c functions prototypes\r
+int  EnterString(char *msg, char *buf, int min, int max);\r
+int  EnterNum(char *msg, int numchars, long *value, long min, long max);\r
+int  EnterHex(char *msg, int numchars, ulong *value);\r
+int  ToHex(char ch);\r
+int  getkeystroke(void);\r
+int  key_abort(void);\r
+void ExitProg(char *msg, int exit_code);\r
+int  getData(uchar *write_buff, int max_len, SMALLINT gethex);\r
+void PrintHex(uchar* buffer, int cnt);\r
+void PrintChars(uchar* buffer, int cnt);\r
+void PrintSerialNum(uchar* buffer);\r
+\r
+// external functions defined in crcutil.c\r
+void setcrc16(int portnum, ushort reset);\r
+ushort docrc16(int portnum, ushort cdata);\r
+void setcrc8(int portnum, uchar reset);\r
+uchar docrc8(int portnum, uchar x);\r
+\r
+#endif //OWNET_H\r
index 7555714..7fa329a 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-//  TMEXLnk.C - Link module to call on TMEX low-level functions to
-//              excersize the general 1-Wire Net functions.
-//              (Requires TMEX 3.11 or newer)
-//
-//  Version: 3.00
-//
-//  History: 1.00 -> 1.01  Return values in owLevel corrected.
-//                         Added function msDelay.
-//           1.02 -> 1.03  Add msGettick, always return owLevel success
-//                         to hide adapters (DS9097E) that do not have
-//                         power delivery capabilities.
-//           1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
-//                         multiple ports.
-//           2.10 -> 3.00  Added owReadBitPower and owWriteBytePower
-
-#include "ownet.h"
-#include <windows.h>
-
-// external TMEX variables
-extern long SessionHandle[MAX_PORTNUM];
-extern uchar StateBuffer[MAX_PORTNUM][5120];
-extern short far pascal TMTouchByte(long, short);
-extern short far pascal TMTouchReset(long);
-extern short far pascal TMTouchBit(long, short);
-extern short far pascal TMProgramPulse(long);
-extern short far pascal TMOneWireCom(long, short, short);
-extern short far pascal TMOneWireLevel(long, short, short, short);
-
-// globals
-SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes
-
-//--------------------------------------------------------------------------
-// Reset all of the devices on the 1-Wire Net and return the result.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-// Returns: TRUE(1):  presense pulse(s) detected, device(s) reset
-//          FALSE(0): no presense pulses detected
-//
-SMALLINT owTouchReset(int portnum)
-{
-   int result;
-
-   // Assume valid Session
-   result = TMTouchReset(SessionHandle[portnum]);
-
-   // success if the normal or alarm presence
-   if ((result == 1) || (result == 2))
-      return TRUE;
-   else
-      return FALSE;
-}
-
-
-//--------------------------------------------------------------------------
-// Send 1 bit of communication to the 1-Wire Net and return the
-// result 1 bit read from the 1-Wire Net.  The parameter 'sendbit'
-// least significant bit is used and the least significant bit
-// of the result is the return bit.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-// 'sendbit'     - the least significant bit is the bit to send
-//
-// Returns: 0:   0 bit read from sendbit
-//          1:   1 bit read from sendbit
-//
-SMALLINT owTouchBit(int portnum, SMALLINT sendbit)
-{
-   // Assume valid Session
-   return TMTouchBit(SessionHandle[portnum],(short)sendbit);
-}
-
-//--------------------------------------------------------------------------
-// Send 8 bits of communication to the 1-Wire Net and verify that the
-// 8 bits read from the 1-Wire Net is the same (write operation).
-// The parameter 'sendbyte' least significant 8 bits are used.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'sendbyte'   - 8 bits to send (least significant byte)
-//
-// Returns:  TRUE: bytes written and echo was the same
-//           FALSE: echo was not the same
-//
-SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)
-{
-   // Assume valid Session
-   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
-}
-
-//--------------------------------------------------------------------------
-// Send 8 bits of communication to the MicroLAN and verify that the
-// 8 bits read from the MicroLAN is the same (write operation).
-// The parameter 'sendbyte' least significant 8 bits are used.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'sendbyte'   - 8 bits to send (least significant byte)
-//
-// Returns:  TRUE: bytes written and echo was the same
-//           FALSE: echo was not the same
-//
-SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)
-{
-   return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;
-}
-
-//--------------------------------------------------------------------------
-// Send 8 bits of read communication to the 1-Wire Net and and return the
-// result 8 bits read from the 1-Wire Net.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-// Returns:  TRUE:  8 bytes read from 1-Wire Net
-//           FALSE: the 8 bytes were not read
-//
-SMALLINT owReadByte(int portnum)
-{
-   return owTouchByte(portnum,0xFF);
-}
-
-//--------------------------------------------------------------------------
-// Set the 1-Wire Net communucation speed.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'new_speed'  - new speed defined as
-//                MODE_NORMAL     0x00
-//                MODE_OVERDRIVE  0x01
-//
-// Returns:  current 1-Wire Net speed
-//
-SMALLINT owSpeed(int portnum, SMALLINT new_speed)
-{
-   return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed);
-}
-
-//--------------------------------------------------------------------------
-// Set the 1-Wire Net line level.  The values for new_level are
-// as follows:
-//
-// 'portnum'   - number 0 to MAX_PORTNUM-1.  This number is provided to
-//               indicate the symbolic port number.
-// 'new_level' - new level defined as
-//                MODE_NORMAL     0x00
-//                MODE_STRONG5    0x02
-//                MODE_PROGRAM    0x04
-//                MODE_BREAK      0x08 (not supported)
-//
-// Returns:  current 1-Wire Net level
-//
-SMALLINT owLevel(int portnum, SMALLINT new_level)
-{
-   int rslt;
-   int docheck = FALSE;
-
-   // check for DS2480 bug
-   if (((SessionHandle[portnum] & 0x0F0) == 0x050) &&
-       (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1))
-      docheck = TRUE;
-
-   switch (new_level)
-   {
-      case MODE_NORMAL:
-         rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0);
-         // test code for DS2480 bug
-         if (docheck)
-            TMTouchBit(SessionHandle[portnum],1);
-         break;
-      case MODE_STRONG5:
-         rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0);
-         break;
-      case MODE_PROGRAM:
-         rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0);
-         break;
-      case MODE_BREAK:
-         rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0);
-         break;
-      default:
-         rslt = 0;
-   }
-
-   // Assume TMEX can do it so always return NewLevel
-   return new_level;
-}
-
-//--------------------------------------------------------------------------
-// This procedure creates a fixed 480 microseconds 12 volt pulse
-// on the 1-Wire Net for programming EPROM iButtons.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-// Returns:  TRUE  successful
-//           FALSE program voltage not available
-//
-SMALLINT owProgramPulse(int portnum)
-{
-   return TMProgramPulse(SessionHandle[portnum]);
-}
-
-//--------------------------------------------------------------------------
-//  Description:
-//     Delay for at least 'len' ms
-//
-void msDelay(int len)
-{
-   Sleep(len);
-}
-
-//--------------------------------------------------------------------------
-// Get the current millisecond tick count.  Does not have to represent
-// an actual time, it just needs to be an incrementing timer.
-//
-long msGettick(void)
-{
-   return GetTickCount();
-}
-
-//--------------------------------------------------------------------------
-// Send 8 bits of communication to the 1-Wire Net and verify that the
-// 8 bits read from the 1-Wire Net is the same (write operation).  
-// The parameter 'sendbyte' least significant 8 bits are used.  After the
-// 8 bits are sent change the level of the 1-Wire net.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-// 'sendbyte' - 8 bits to send (least significant byte)
-//
-// Returns:  TRUE: bytes written and echo was the same
-//           FALSE: echo was not the same 
-//
-SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)
-{
-   // prime for power delivery after byte
-   TMOneWireLevel(SessionHandle[portnum],0,1,2);
-
-   // send the byte and start strong pullup
-   if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte)
-   {
-      TMOneWireLevel(SessionHandle[portnum],0,0,0);
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-//--------------------------------------------------------------------------
-// Read 8 bits of communication to the 1-Wire Net and verify that the
-// 8 bits read from the 1-Wire Net is the same (write operation).  
-// The parameter 'sendbyte' least significant 8 bits are used.  After the
-// 8 bits are read change the level of the 1-Wire net.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-// 'sendbyte' - 8 bits to send (least significant byte)
-//
-// Returns:  TRUE: bytes written and echo was the same
-//           FALSE: echo was not the same 
-//
-SMALLINT owReadBytePower(int portnum)
-{
-   SMALLINT sendbyte = 0xFF;
-
-   // prime for power delivery after byte
-   TMOneWireLevel(SessionHandle[portnum],0,1,2);
-
-   // send the byte and start strong pullup
-   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
-}
-
-//--------------------------------------------------------------------------
-// Send 1 bit of communication to the 1-Wire Net and verify that the
-// response matches the 'applyPowerResponse' bit and apply power delivery
-// to the 1-Wire net.  Note that some implementations may apply the power
-// first and then turn it off if the response is incorrect.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-// 'applyPowerResponse' - 1 bit response to check, if correct then start
-//                        power delivery 
-//
-// Returns:  TRUE: bit written and response correct, strong pullup now on
-//           FALSE: response incorrect
-//
-SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)
-{
-   // prime for power delivery after bit
-   TMOneWireLevel(SessionHandle[portnum],0,1,1);
-
-   // send the byte and start strong pullup
-   if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse)
-   {
-      TMOneWireLevel(SessionHandle[portnum],0,0,0);
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-//--------------------------------------------------------------------------
-// This procedure indicates wether the adapter can deliver power.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-//
-// Returns:  TRUE  because all userial adapters have over drive. 
-//
-SMALLINT owHasPowerDelivery(int portnum)
-{
-   return TRUE;
-}
-
-//--------------------------------------------------------------------------
-// This procedure indicates wether the adapter can deliver power.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-//
-// Returns:  TRUE  because all userial adapters have over drive. 
-//
-SMALLINT owHasOverDrive(int portnum)
-{
-   return TRUE;
-}
-
-//--------------------------------------------------------------------------
-// This procedure creates a fixed 480 microseconds 12 volt pulse 
-// on the 1-Wire Net for programming EPROM iButtons.
-//
-// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
-//              OpenCOM to indicate the port number.
-//
-// Returns:  TRUE  program volatage available
-//           FALSE program voltage not available  
-SMALLINT owHasProgramPulse(int portnum)
-{
-   return TMProgramPulse(SessionHandle[portnum]);
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+//  TMEXLnk.C - Link module to call on TMEX low-level functions to\r
+//              excersize the general 1-Wire Net functions.\r
+//              (Requires TMEX 3.11 or newer)\r
+//\r
+//  Version: 3.00\r
+//\r
+//  History: 1.00 -> 1.01  Return values in owLevel corrected.\r
+//                         Added function msDelay.\r
+//           1.02 -> 1.03  Add msGettick, always return owLevel success\r
+//                         to hide adapters (DS9097E) that do not have\r
+//                         power delivery capabilities.\r
+//           1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for\r
+//                         multiple ports.\r
+//           2.10 -> 3.00  Added owReadBitPower and owWriteBytePower\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern uchar StateBuffer[MAX_PORTNUM][5120];\r
+extern short far pascal TMTouchByte(long, short);\r
+extern short far pascal TMTouchReset(long);\r
+extern short far pascal TMTouchBit(long, short);\r
+extern short far pascal TMProgramPulse(long);\r
+extern short far pascal TMOneWireCom(long, short, short);\r
+extern short far pascal TMOneWireLevel(long, short, short, short);\r
+\r
+// globals\r
+SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes\r
+\r
+//--------------------------------------------------------------------------\r
+// Reset all of the devices on the 1-Wire Net and return the result.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+// Returns: TRUE(1):  presense pulse(s) detected, device(s) reset\r
+//          FALSE(0): no presense pulses detected\r
+//\r
+SMALLINT owTouchReset(int portnum)\r
+{\r
+   int result;\r
+\r
+   // Assume valid Session\r
+   result = TMTouchReset(SessionHandle[portnum]);\r
+\r
+   // success if the normal or alarm presence\r
+   if ((result == 1) || (result == 2))\r
+      return TRUE;\r
+   else\r
+      return FALSE;\r
+}\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 1 bit of communication to the 1-Wire Net and return the\r
+// result 1 bit read from the 1-Wire Net.  The parameter 'sendbit'\r
+// least significant bit is used and the least significant bit\r
+// of the result is the return bit.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+// 'sendbit'     - the least significant bit is the bit to send\r
+//\r
+// Returns: 0:   0 bit read from sendbit\r
+//          1:   1 bit read from sendbit\r
+//\r
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit)\r
+{\r
+   // Assume valid Session\r
+   return TMTouchBit(SessionHandle[portnum],(short)sendbit);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation).\r
+// The parameter 'sendbyte' least significant 8 bits are used.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'sendbyte'   - 8 bits to send (least significant byte)\r
+//\r
+// Returns:  TRUE: bytes written and echo was the same\r
+//           FALSE: echo was not the same\r
+//\r
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)\r
+{\r
+   // Assume valid Session\r
+   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the MicroLAN and verify that the\r
+// 8 bits read from the MicroLAN is the same (write operation).\r
+// The parameter 'sendbyte' least significant 8 bits are used.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'sendbyte'   - 8 bits to send (least significant byte)\r
+//\r
+// Returns:  TRUE: bytes written and echo was the same\r
+//           FALSE: echo was not the same\r
+//\r
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)\r
+{\r
+   return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of read communication to the 1-Wire Net and and return the\r
+// result 8 bits read from the 1-Wire Net.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+// Returns:  TRUE:  8 bytes read from 1-Wire Net\r
+//           FALSE: the 8 bytes were not read\r
+//\r
+SMALLINT owReadByte(int portnum)\r
+{\r
+   return owTouchByte(portnum,0xFF);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the 1-Wire Net communucation speed.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'new_speed'  - new speed defined as\r
+//                MODE_NORMAL     0x00\r
+//                MODE_OVERDRIVE  0x01\r
+//\r
+// Returns:  current 1-Wire Net speed\r
+//\r
+SMALLINT owSpeed(int portnum, SMALLINT new_speed)\r
+{\r
+   return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the 1-Wire Net line level.  The values for new_level are\r
+// as follows:\r
+//\r
+// 'portnum'   - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//               indicate the symbolic port number.\r
+// 'new_level' - new level defined as\r
+//                MODE_NORMAL     0x00\r
+//                MODE_STRONG5    0x02\r
+//                MODE_PROGRAM    0x04\r
+//                MODE_BREAK      0x08 (not supported)\r
+//\r
+// Returns:  current 1-Wire Net level\r
+//\r
+SMALLINT owLevel(int portnum, SMALLINT new_level)\r
+{\r
+   int rslt;\r
+   int docheck = FALSE;\r
+\r
+   // check for DS2480 bug\r
+   if (((SessionHandle[portnum] & 0x0F0) == 0x050) &&\r
+       (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1))\r
+      docheck = TRUE;\r
+\r
+   switch (new_level)\r
+   {\r
+      case MODE_NORMAL:\r
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+         // test code for DS2480 bug\r
+         if (docheck)\r
+            TMTouchBit(SessionHandle[portnum],1);\r
+         break;\r
+      case MODE_STRONG5:\r
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0);\r
+         break;\r
+      case MODE_PROGRAM:\r
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0);\r
+         break;\r
+      case MODE_BREAK:\r
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0);\r
+         break;\r
+      default:\r
+         rslt = 0;\r
+   }\r
+\r
+   // Assume TMEX can do it so always return NewLevel\r
+   return new_level;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure creates a fixed 480 microseconds 12 volt pulse\r
+// on the 1-Wire Net for programming EPROM iButtons.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+// Returns:  TRUE  successful\r
+//           FALSE program voltage not available\r
+//\r
+SMALLINT owProgramPulse(int portnum)\r
+{\r
+   return TMProgramPulse(SessionHandle[portnum]);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+//  Description:\r
+//     Delay for at least 'len' ms\r
+//\r
+void msDelay(int len)\r
+{\r
+   Sleep(len);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Get the current millisecond tick count.  Does not have to represent\r
+// an actual time, it just needs to be an incrementing timer.\r
+//\r
+long msGettick(void)\r
+{\r
+   return GetTickCount();\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation).  \r
+// The parameter 'sendbyte' least significant 8 bits are used.  After the\r
+// 8 bits are sent change the level of the 1-Wire net.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns:  TRUE: bytes written and echo was the same\r
+//           FALSE: echo was not the same \r
+//\r
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)\r
+{\r
+   // prime for power delivery after byte\r
+   TMOneWireLevel(SessionHandle[portnum],0,1,2);\r
+\r
+   // send the byte and start strong pullup\r
+   if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte)\r
+   {\r
+      TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+      return FALSE;\r
+   }\r
+\r
+   return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Read 8 bits of communication to the 1-Wire Net and verify that the\r
+// 8 bits read from the 1-Wire Net is the same (write operation).  \r
+// The parameter 'sendbyte' least significant 8 bits are used.  After the\r
+// 8 bits are read change the level of the 1-Wire net.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+// 'sendbyte' - 8 bits to send (least significant byte)\r
+//\r
+// Returns:  TRUE: bytes written and echo was the same\r
+//           FALSE: echo was not the same \r
+//\r
+SMALLINT owReadBytePower(int portnum)\r
+{\r
+   SMALLINT sendbyte = 0xFF;\r
+\r
+   // prime for power delivery after byte\r
+   TMOneWireLevel(SessionHandle[portnum],0,1,2);\r
+\r
+   // send the byte and start strong pullup\r
+   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Send 1 bit of communication to the 1-Wire Net and verify that the\r
+// response matches the 'applyPowerResponse' bit and apply power delivery\r
+// to the 1-Wire net.  Note that some implementations may apply the power\r
+// first and then turn it off if the response is incorrect.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+// 'applyPowerResponse' - 1 bit response to check, if correct then start\r
+//                        power delivery \r
+//\r
+// Returns:  TRUE: bit written and response correct, strong pullup now on\r
+//           FALSE: response incorrect\r
+//\r
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)\r
+{\r
+   // prime for power delivery after bit\r
+   TMOneWireLevel(SessionHandle[portnum],0,1,1);\r
+\r
+   // send the byte and start strong pullup\r
+   if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse)\r
+   {\r
+      TMOneWireLevel(SessionHandle[portnum],0,0,0);\r
+      return FALSE;\r
+   }\r
+\r
+   return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure indicates wether the adapter can deliver power.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+//\r
+// Returns:  TRUE  because all userial adapters have over drive. \r
+//\r
+SMALLINT owHasPowerDelivery(int portnum)\r
+{\r
+   return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure indicates wether the adapter can deliver power.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+//\r
+// Returns:  TRUE  because all userial adapters have over drive. \r
+//\r
+SMALLINT owHasOverDrive(int portnum)\r
+{\r
+   return TRUE;\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// This procedure creates a fixed 480 microseconds 12 volt pulse \r
+// on the 1-Wire Net for programming EPROM iButtons.\r
+//\r
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//              OpenCOM to indicate the port number.\r
+//\r
+// Returns:  TRUE  program volatage available\r
+//           FALSE program voltage not available  \r
+SMALLINT owHasProgramPulse(int portnum)\r
+{\r
+   return TMProgramPulse(SessionHandle[portnum]);\r
 }
\ No newline at end of file
index 5f328c7..3f9b77d 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
-//              for network functions.
-//
-//  Version: 3.00
-//
-//
-
-#include "ownet.h"
-#include <windows.h>
-
-uchar StateBuffer[MAX_PORTNUM][5120];
-
-// external TMEX variables
-extern long SessionHandle[MAX_PORTNUM];
-extern short far pascal TMSearch(long session_handle, void *start_buffer, 
-                                 short ResetSearch,  short PerformReset, 
-                                 short SrchCmd);
-extern short pascal TMFirst(long, void *);
-extern short pascal TMNext(long, void *);
-extern short pascal TMAccess(long, void *);
-extern short pascal TMStrongAccess(long, void *);
-extern short pascal TMStrongAlarmAccess(long, void *);
-extern short pascal TMOverAccess(long, void *);
-extern short pascal TMRom(long, void *, short *);
-extern short pascal TMFirstAlarm(long, void *);
-extern short pascal TMNextAlarm(long, void *);
-extern short pascal TMFamilySearchSetup(long, void *, short);
-extern short pascal TMSkipFamily(long, void *);
-extern short pascal TMAutoOverDrive(long, void *, short);
-
-
-//--------------------------------------------------------------------------
-// The 'owFirst' finds the first device on the 1-Wire Net  This function
-// contains one parameter 'alarm_only'.  When
-// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
-// sent instead of the normal search command 0xF0.
-// Using the find alarm command 0xEC will limit the search to only
-// 1-Wire devices that are in an 'alarm' state.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
-//                perform reset before search.
-// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
-//                sent instead of the normal search command 0xF0
-//
-// Returns:   TRUE (1) : when a 1-Wire device was found and it's
-//                        Serial Number placed in the global SerialNum[portnum]
-//            FALSE (0): There are no devices on the 1-Wire Net.
-//
-SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
-{
-   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, 
-                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
-}
-
-//--------------------------------------------------------------------------
-// The 'owNext' function does a general search.  This function
-// continues from the previos search state. The search state
-// can be reset by using the 'owFirst' function.
-// This function contains one parameter 'alarm_only'.
-// When 'alarm_only' is TRUE (1) the find alarm command
-// 0xEC is sent instead of the normal search command 0xF0.
-// Using the find alarm command 0xEC will limit the search to only
-// 1-Wire devices that are in an 'alarm' state.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
-//                perform reset before search.
-// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
-//                sent instead of the normal search command 0xF0
-//
-// Returns:   TRUE (1) : when a 1-Wire device was found and it's
-//                       Serial Number placed in the global SerialNum[portnum]
-//            FALSE (0): when no new device was found.  Either the
-//                       last search was the last device or there
-//                       are no devices on the 1-Wire Net.
-//
-SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
-{
-   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, 
-                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
-}
-
-//--------------------------------------------------------------------------
-// The 'owSerialNum' function either reads or sets the SerialNum buffer
-// that is used in the search functions 'owFirst' and 'owNext'.
-// This function contains two parameters, 'serialnum_buf' is a pointer
-// to a buffer provided by the caller.  'serialnum_buf' should point to
-// an array of 8 unsigned chars.  The second parameter is a flag called
-// 'do_read' that is TRUE (1) if the operation is to read and FALSE
-// (0) if the operation is to set the internal SerialNum buffer from
-// the data in the provided buffer.
-//
-// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                   indicate the symbolic port number.
-// 'serialnum_buf' - buffer to that contains the serial number to set
-//                   when do_read = FALSE (0) and buffer to get the serial
-//                   number when do_read = TRUE (1).
-// 'do_read'       - flag to indicate reading (1) or setting (0) the current
-//                   serial number.
-//
-void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)
-{
-   short ROM[8],i;
-
-   // check if reading or writing
-   if (do_read)
-   {
-      ROM[0] = 0;
-   }
-   else
-   {
-      for (i = 0; i < 8; i++)
-         ROM[i] = serialnum_buf[i];
-   }
-
-   // call TMEX to read or set the current device
-   TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);
-
-   // place in 'serialnum_buf'
-   if (do_read)
-   {
-      for (i = 0; i < 8; i++)
-         serialnum_buf[i] = (uchar)ROM[i];
-   }
-}
-
-//--------------------------------------------------------------------------
-// Setup the search algorithm to find a certain family of devices
-// the next time a search function is called 'owNext'.
-//
-// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number was provided to
-//                   OpenCOM to indicate the port number.
-// 'search_family' - family code type to set the search algorithm to find
-//                   next.
-//
-void owFamilySearchSetup(int portnum, SMALLINT search_family)
-{
-   TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], 
-                       (short)search_family);
-}
-
-//--------------------------------------------------------------------------
-// Set the current search state to skip the current family code.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-void owSkipFamily(int portnum)
-{
-   TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);
-}
-
-//--------------------------------------------------------------------------
-// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial
-// Number command followed by the current SerialNum code. After this
-// function is complete the 1-Wire device is ready to accept device-specific
-// commands.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-// Returns:   TRUE (1) : reset indicates present and device is ready
-//                       for commands.
-//            FALSE (0): reset does not indicate presence or echos 'writes'
-//                       are not correct.
-//
-SMALLINT owAccess(int portnum)
-{
-   return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
-
-//----------------------------------------------------------------------
-// The function 'owVerify' verifies that the current device
-// is in contact with the 1-Wire Net.
-// Using the find alarm command 0xEC will verify that the device
-// is in contact with the 1-Wire Net and is in an 'alarm' state.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-// 'alarm_only'  - TRUE (1) the find alarm command 0xEC
-//                 is sent instead of the normal search
-//                 command 0xF0.
-//
-// Returns:   TRUE (1) : when the 1-Wire device was verified
-//                       to be on the 1-Wire Net
-//                       with alarm_only == FALSE
-//                       or verified to be on the 1-Wire Net
-//                       AND in an alarm state when
-//                       alarm_only == TRUE.
-//            FALSE (0): the 1-Wire device was not on the
-//                       1-Wire Net or if alarm_only
-//                       == TRUE, the device may be on the
-//                       1-Wire Net but in a non-alarm state.
-//
-SMALLINT owVerify(int portnum, SMALLINT alarm_only)
-{
-   if (alarm_only)
-      return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-   else
-      return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
-
-//----------------------------------------------------------------------
-// Perform a overdrive MATCH command to select the 1-Wire device with
-// the address in the ID data register.
-//
-// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                 indicate the symbolic port number.
-//
-// Returns:  TRUE: If the device is present on the 1-Wire Net and
-//                 can do overdrive then the device is selected.
-//           FALSE: Device is not present or not capable of overdrive.
-//
-//  *Note: This function could be converted to send DS2480
-//         commands in one packet.
-//
-SMALLINT owOverdriveAccess(int portnum)
-{
-   return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
-}
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API\r
+//              for network functions.\r
+//\r
+//  Version: 3.00\r
+//\r
+//\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+uchar StateBuffer[MAX_PORTNUM][5120];\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern short far pascal TMSearch(long session_handle, void *start_buffer, \r
+                                 short ResetSearch,  short PerformReset, \r
+                                 short SrchCmd);\r
+extern short pascal TMFirst(long, void *);\r
+extern short pascal TMNext(long, void *);\r
+extern short pascal TMAccess(long, void *);\r
+extern short pascal TMStrongAccess(long, void *);\r
+extern short pascal TMStrongAlarmAccess(long, void *);\r
+extern short pascal TMOverAccess(long, void *);\r
+extern short pascal TMRom(long, void *, short *);\r
+extern short pascal TMFirstAlarm(long, void *);\r
+extern short pascal TMNextAlarm(long, void *);\r
+extern short pascal TMFamilySearchSetup(long, void *, short);\r
+extern short pascal TMSkipFamily(long, void *);\r
+extern short pascal TMAutoOverDrive(long, void *, short);\r
+\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owFirst' finds the first device on the 1-Wire Net  This function\r
+// contains one parameter 'alarm_only'.  When\r
+// 'alarm_only' is TRUE (1) the find alarm command 0xEC is\r
+// sent instead of the normal search command 0xF0.\r
+// Using the find alarm command 0xEC will limit the search to only\r
+// 1-Wire devices that are in an 'alarm' state.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not\r
+//                perform reset before search.\r
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is\r
+//                sent instead of the normal search command 0xF0\r
+//\r
+// Returns:   TRUE (1) : when a 1-Wire device was found and it's\r
+//                        Serial Number placed in the global SerialNum[portnum]\r
+//            FALSE (0): There are no devices on the 1-Wire Net.\r
+//\r
+SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)\r
+{\r
+   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, \r
+                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owNext' function does a general search.  This function\r
+// continues from the previos search state. The search state\r
+// can be reset by using the 'owFirst' function.\r
+// This function contains one parameter 'alarm_only'.\r
+// When 'alarm_only' is TRUE (1) the find alarm command\r
+// 0xEC is sent instead of the normal search command 0xF0.\r
+// Using the find alarm command 0xEC will limit the search to only\r
+// 1-Wire devices that are in an 'alarm' state.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not\r
+//                perform reset before search.\r
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is\r
+//                sent instead of the normal search command 0xF0\r
+//\r
+// Returns:   TRUE (1) : when a 1-Wire device was found and it's\r
+//                       Serial Number placed in the global SerialNum[portnum]\r
+//            FALSE (0): when no new device was found.  Either the\r
+//                       last search was the last device or there\r
+//                       are no devices on the 1-Wire Net.\r
+//\r
+SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)\r
+{\r
+   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, \r
+                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owSerialNum' function either reads or sets the SerialNum buffer\r
+// that is used in the search functions 'owFirst' and 'owNext'.\r
+// This function contains two parameters, 'serialnum_buf' is a pointer\r
+// to a buffer provided by the caller.  'serialnum_buf' should point to\r
+// an array of 8 unsigned chars.  The second parameter is a flag called\r
+// 'do_read' that is TRUE (1) if the operation is to read and FALSE\r
+// (0) if the operation is to set the internal SerialNum buffer from\r
+// the data in the provided buffer.\r
+//\r
+// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                   indicate the symbolic port number.\r
+// 'serialnum_buf' - buffer to that contains the serial number to set\r
+//                   when do_read = FALSE (0) and buffer to get the serial\r
+//                   number when do_read = TRUE (1).\r
+// 'do_read'       - flag to indicate reading (1) or setting (0) the current\r
+//                   serial number.\r
+//\r
+void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)\r
+{\r
+   short ROM[8],i;\r
+\r
+   // check if reading or writing\r
+   if (do_read)\r
+   {\r
+      ROM[0] = 0;\r
+   }\r
+   else\r
+   {\r
+      for (i = 0; i < 8; i++)\r
+         ROM[i] = serialnum_buf[i];\r
+   }\r
+\r
+   // call TMEX to read or set the current device\r
+   TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);\r
+\r
+   // place in 'serialnum_buf'\r
+   if (do_read)\r
+   {\r
+      for (i = 0; i < 8; i++)\r
+         serialnum_buf[i] = (uchar)ROM[i];\r
+   }\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Setup the search algorithm to find a certain family of devices\r
+// the next time a search function is called 'owNext'.\r
+//\r
+// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number was provided to\r
+//                   OpenCOM to indicate the port number.\r
+// 'search_family' - family code type to set the search algorithm to find\r
+//                   next.\r
+//\r
+void owFamilySearchSetup(int portnum, SMALLINT search_family)\r
+{\r
+   TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], \r
+                       (short)search_family);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Set the current search state to skip the current family code.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+void owSkipFamily(int portnum)\r
+{\r
+   TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial\r
+// Number command followed by the current SerialNum code. After this\r
+// function is complete the 1-Wire device is ready to accept device-specific\r
+// commands.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+// Returns:   TRUE (1) : reset indicates present and device is ready\r
+//                       for commands.\r
+//            FALSE (0): reset does not indicate presence or echos 'writes'\r
+//                       are not correct.\r
+//\r
+SMALLINT owAccess(int portnum)\r
+{\r
+   return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+// The function 'owVerify' verifies that the current device\r
+// is in contact with the 1-Wire Net.\r
+// Using the find alarm command 0xEC will verify that the device\r
+// is in contact with the 1-Wire Net and is in an 'alarm' state.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+// 'alarm_only'  - TRUE (1) the find alarm command 0xEC\r
+//                 is sent instead of the normal search\r
+//                 command 0xF0.\r
+//\r
+// Returns:   TRUE (1) : when the 1-Wire device was verified\r
+//                       to be on the 1-Wire Net\r
+//                       with alarm_only == FALSE\r
+//                       or verified to be on the 1-Wire Net\r
+//                       AND in an alarm state when\r
+//                       alarm_only == TRUE.\r
+//            FALSE (0): the 1-Wire device was not on the\r
+//                       1-Wire Net or if alarm_only\r
+//                       == TRUE, the device may be on the\r
+//                       1-Wire Net but in a non-alarm state.\r
+//\r
+SMALLINT owVerify(int portnum, SMALLINT alarm_only)\r
+{\r
+   if (alarm_only)\r
+      return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+   else\r
+      return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r
+\r
+//----------------------------------------------------------------------\r
+// Perform a overdrive MATCH command to select the 1-Wire device with\r
+// the address in the ID data register.\r
+//\r
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                 indicate the symbolic port number.\r
+//\r
+// Returns:  TRUE: If the device is present on the 1-Wire Net and\r
+//                 can do overdrive then the device is selected.\r
+//           FALSE: Device is not present or not capable of overdrive.\r
+//\r
+//  *Note: This function could be converted to send DS2480\r
+//         commands in one packet.\r
+//\r
+SMALLINT owOverdriveAccess(int portnum)\r
+{\r
+   return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);\r
+}\r
index 793d650..fea8798 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-//  owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX.
-//               (Requires TMEX 3.11 or newer)
-//
-//  Version: 2.01
-//
-//  History: 1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
-//                         multiple ports.
-//           2.00 -> 2.01  Added support for owError library.
-//
-
-#include <stdio.h>
-#include <windows.h>
-#include "ownet.h"
-
-// external function prototypes
-extern long  far pascal TMExtendedStartSession(short, short, void far *);
-extern short far pascal TMEndSession(long);
-extern short far pascal TMClose(long);
-extern short far pascal TMSetup(long);
-extern short far pascal TMReadDefaultPort(short far *, short far *);
-
-short PortNum=1,PortType=2;
-long  SessionHandle[MAX_PORTNUM];
-SMALLINT handle_init = FALSE;
-
-//---------------------------------------------------------------------------
-// Attempt to acquire a 1-Wire net using a com port and a DS2480 based
-// adapter.
-//
-// 'port_zstr'     - zero terminated port name.  For this platform
-//                   use format {port number, port type}.
-//
-// Returns: port number and -1 if not successful in setting up the port.
-//
-int owAcquireEx(char *port_zstr)
-{
-   int portnum;
-   int string_counter, counter, i, lenmax;
-   char portnum_str[15];
-   char porttype_str[15];
-   void *tmex_options = NULL;
-
-   if(!handle_init)
-   {
-      for(i=0; i<MAX_PORTNUM; i++)
-         SessionHandle[i] = 0;
-      handle_init = TRUE;
-   }
-
-   // check to find first available handle slot
-   for(portnum = 0; portnum<MAX_PORTNUM; portnum++)
-   {
-      if(!SessionHandle[portnum])
-         break;
-   }
-   OWASSERT( portnum<MAX_PORTNUM, OWERROR_PORTNUM_ERROR, -1 );
-
-   // convert the string in port_zstr to be the port number and port type
-   if(port_zstr)
-   {
-      lenmax = strlen(port_zstr);
-      if (lenmax > 12)
-         lenmax = 12;
-      string_counter = 1;
-      counter = 0;
-      do
-      {
-         portnum_str[counter] = port_zstr[string_counter];
-
-         counter++;
-         string_counter++;
-      }
-      while((port_zstr[string_counter] != ',') && (string_counter <= lenmax));
-
-      portnum_str[counter] = '\0';
-
-      string_counter++;
-      counter = 0;
-
-      do
-      {
-         porttype_str[counter] = port_zstr[string_counter];
-
-         counter++;
-         string_counter++;
-      }
-      while((port_zstr[string_counter] != '}') && (string_counter <= lenmax));
-
-      porttype_str[counter] = '\0';
-
-      PortNum = atoi(portnum_str);
-      PortType = atoi(porttype_str);
-   }
-
-   // open a session
-   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options);
-
-   // check the session handle
-   if (SessionHandle[portnum] <= 0)
-   {
-      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);
-      SessionHandle[portnum] = 0;
-      return -1;
-   }
-
-   // setup the port
-   if (TMSetup(SessionHandle[portnum]) != 1)
-   {
-      TMClose(SessionHandle[portnum]);
-      TMEndSession(SessionHandle[portnum]);
-      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);
-      SessionHandle[portnum] = 0;
-      return -1;
-   }
-
-   return portnum;
-}
-
-//---------------------------------------------------------------------------
-// Attempt to acquire a 1-Wire net using a com port and a DS2480 based
-// adapter.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'port_zstr'  - zero terminated port name.  For this platform
-//                use format COMX where X is the port number.
-//
-// Returns: TRUE - success, COM port opened
-//
-SMALLINT owAcquire(int portnum, char *port_zstr)
-{
-   int i;
-
-   if(!handle_init)
-   {
-      for(i=0; i<MAX_PORTNUM; i++)
-         SessionHandle[i] = 0;
-      handle_init = TRUE;
-   }
-
-   OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !SessionHandle[portnum],
-             OWERROR_PORTNUM_ERROR, FALSE );
-
-   // read the default PortNum and PortType
-   TMReadDefaultPort(&PortNum,&PortType);
-
-   // convert the string in port_zstr to be the port number
-   PortNum = atoi(port_zstr);
-
-   // open a session
-   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL);
-
-   // check the session handle
-   if (SessionHandle[portnum] <= 0)
-   {
-      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);
-      SessionHandle[portnum] = 0;
-      return FALSE;
-   }
-
-   // setup the port
-   if (TMSetup(SessionHandle[portnum]) != 1)
-   {
-      TMClose(SessionHandle[portnum]);
-      TMEndSession(SessionHandle[portnum]);
-      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);
-      SessionHandle[portnum] = 0;
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-//---------------------------------------------------------------------------
-// Release the previously acquired a 1-Wire net.
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-//
-void owRelease(int portnum)
-{
-   TMClose(SessionHandle[portnum]);
-   TMEndSession(SessionHandle[portnum]);
-   SessionHandle[portnum] = 0;
-}
-
+//---------------------------------------------------------------------------\r
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+//  owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX.\r
+//               (Requires TMEX 3.11 or newer)\r
+//\r
+//  Version: 2.01\r
+//\r
+//  History: 1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for\r
+//                         multiple ports.\r
+//           2.00 -> 2.01  Added support for owError library.\r
+//\r
+\r
+#include <stdio.h>\r
+#include <windows.h>\r
+#include "ownet.h"\r
+\r
+// external function prototypes\r
+extern long  far pascal TMExtendedStartSession(short, short, void far *);\r
+extern short far pascal TMEndSession(long);\r
+extern short far pascal TMClose(long);\r
+extern short far pascal TMSetup(long);\r
+extern short far pascal TMReadDefaultPort(short far *, short far *);\r
+\r
+short PortNum=1,PortType=2;\r
+long  SessionHandle[MAX_PORTNUM];\r
+SMALLINT handle_init = FALSE;\r
+\r
+//---------------------------------------------------------------------------\r
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
+// adapter.\r
+//\r
+// 'port_zstr'     - zero terminated port name.  For this platform\r
+//                   use format {port number, port type}.\r
+//\r
+// Returns: port number and -1 if not successful in setting up the port.\r
+//\r
+int owAcquireEx(char *port_zstr)\r
+{\r
+   int portnum;\r
+   int string_counter, counter, i, lenmax;\r
+   char portnum_str[15];\r
+   char porttype_str[15];\r
+   void *tmex_options = NULL;\r
+\r
+   if(!handle_init)\r
+   {\r
+      for(i=0; i<MAX_PORTNUM; i++)\r
+         SessionHandle[i] = 0;\r
+      handle_init = TRUE;\r
+   }\r
+\r
+   // check to find first available handle slot\r
+   for(portnum = 0; portnum<MAX_PORTNUM; portnum++)\r
+   {\r
+      if(!SessionHandle[portnum])\r
+         break;\r
+   }\r
+   OWASSERT( portnum<MAX_PORTNUM, OWERROR_PORTNUM_ERROR, -1 );\r
+\r
+   // convert the string in port_zstr to be the port number and port type\r
+   if(port_zstr)\r
+   {\r
+      lenmax = strlen(port_zstr);\r
+      if (lenmax > 12)\r
+         lenmax = 12;\r
+      string_counter = 1;\r
+      counter = 0;\r
+      do\r
+      {\r
+         portnum_str[counter] = port_zstr[string_counter];\r
+\r
+         counter++;\r
+         string_counter++;\r
+      }\r
+      while((port_zstr[string_counter] != ',') && (string_counter <= lenmax));\r
+\r
+      portnum_str[counter] = '\0';\r
+\r
+      string_counter++;\r
+      counter = 0;\r
+\r
+      do\r
+      {\r
+         porttype_str[counter] = port_zstr[string_counter];\r
+\r
+         counter++;\r
+         string_counter++;\r
+      }\r
+      while((port_zstr[string_counter] != '}') && (string_counter <= lenmax));\r
+\r
+      porttype_str[counter] = '\0';\r
+\r
+      PortNum = atoi(portnum_str);\r
+      PortType = atoi(porttype_str);\r
+   }\r
+\r
+   // open a session\r
+   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options);\r
+\r
+   // check the session handle\r
+   if (SessionHandle[portnum] <= 0)\r
+   {\r
+      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
+      SessionHandle[portnum] = 0;\r
+      return -1;\r
+   }\r
+\r
+   // setup the port\r
+   if (TMSetup(SessionHandle[portnum]) != 1)\r
+   {\r
+      TMClose(SessionHandle[portnum]);\r
+      TMEndSession(SessionHandle[portnum]);\r
+      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
+      SessionHandle[portnum] = 0;\r
+      return -1;\r
+   }\r
+\r
+   return portnum;\r
+}\r
+\r
+//---------------------------------------------------------------------------\r
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based\r
+// adapter.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'port_zstr'  - zero terminated port name.  For this platform\r
+//                use format COMX where X is the port number.\r
+//\r
+// Returns: TRUE - success, COM port opened\r
+//\r
+SMALLINT owAcquire(int portnum, char *port_zstr)\r
+{\r
+   int i;\r
+\r
+   if(!handle_init)\r
+   {\r
+      for(i=0; i<MAX_PORTNUM; i++)\r
+         SessionHandle[i] = 0;\r
+      handle_init = TRUE;\r
+   }\r
+\r
+   OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !SessionHandle[portnum],\r
+             OWERROR_PORTNUM_ERROR, FALSE );\r
+\r
+   // read the default PortNum and PortType\r
+   TMReadDefaultPort(&PortNum,&PortType);\r
+\r
+   // convert the string in port_zstr to be the port number\r
+   PortNum = atoi(port_zstr);\r
+\r
+   // open a session\r
+   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL);\r
+\r
+   // check the session handle\r
+   if (SessionHandle[portnum] <= 0)\r
+   {\r
+      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);\r
+      SessionHandle[portnum] = 0;\r
+      return FALSE;\r
+   }\r
+\r
+   // setup the port\r
+   if (TMSetup(SessionHandle[portnum]) != 1)\r
+   {\r
+      TMClose(SessionHandle[portnum]);\r
+      TMEndSession(SessionHandle[portnum]);\r
+      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);\r
+      SessionHandle[portnum] = 0;\r
+      return FALSE;\r
+   }\r
+\r
+   return TRUE;\r
+}\r
+\r
+//---------------------------------------------------------------------------\r
+// Release the previously acquired a 1-Wire net.\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+//\r
+void owRelease(int portnum)\r
+{\r
+   TMClose(SessionHandle[portnum]);\r
+   TMEndSession(SessionHandle[portnum]);\r
+   SessionHandle[portnum] = 0;\r
+}\r
+\r
index 31d2cf7..4a4b926 100644 (file)
-//---------------------------------------------------------------------------
-// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
-// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name of Dallas Semiconductor
-// shall not be used except as stated in the Dallas Semiconductor
-// Branding Policy.
-//---------------------------------------------------------------------------
-//
-//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
-//              for transport functions.
-//
-//  Version: 3.00
-//
-
-#include "ownet.h"
-#include <windows.h>
-
-// external TMEX variables
-extern long SessionHandle[MAX_PORTNUM];
-extern short far pascal TMBlockIO(long, uchar *, short);
-extern short far pascal TMBlockStream(long, uchar *, short);
-
-//--------------------------------------------------------------------------
-// The 'owBlock' transfers a block of data to and from the
-// 1-Wire Net with an optional reset at the begining of communication.
-// The result is returned in the same buffer.
-//
-// 'do_reset' - cause a owTouchReset to occure at the begining of
-//              communication TRUE(1) or not FALSE(0)
-// 'tran_buf' - pointer to a block of unsigned
-//              chars of length 'TranferLength' that will be sent
-//              to the 1-Wire Net
-// 'tran_len' - length in bytes to transfer
-// Supported devices: all
-//
-// Returns:   TRUE (1) : The optional reset returned a valid
-//                       presence (do_reset == TRUE) or there
-//                       was no reset required.
-//            FALSE (0): The reset did not return a valid prsence
-//                       (do_reset == TRUE).
-//
-//  The maximum tran_len is 64
-//
-SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len)
-{
-   short rslt;
-
-   // check for a block too big
-   if (tran_len > 192)
-   {
-      OWERROR(OWERROR_BLOCK_TOO_BIG);
-      return FALSE;
-   }
-
-   // check if need to do a owTouchReset first
-   if (do_reset)
-      rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len);
-   else
-      rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len);
-
-   return (rslt == tran_len);
-}
-
-//--------------------------------------------------------------------------
-// Write a byte to an EPROM 1-Wire device.
-//
-// Supported devices: crc_type=0(CRC8)
-//                        DS1982
-//                    crc_type=1(CRC16)
-//                        DS1985, DS1986, DS2407
-//
-// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
-//                indicate the symbolic port number.
-// 'write_byte' - byte to program
-// 'addr'       - address of byte to program
-// 'write_cmd'  - command used to write (0x0F reg mem, 0x55 status)
-// 'crc_type'   - CRC used (0 CRC8, 1 CRC16)
-// 'do_access'  - Flag to access device for each byte
-//                (0 skip access, 1 do the access)
-//                WARNING, only use do_access=0 if programing the NEXT
-//                byte immediatly after the previous byte.
-//
-// Returns: >=0   success, this is the resulting byte from the program
-//                effort
-//          -1    error, device not connected or program pulse voltage
-//                not available
-//
-SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
-                       SMALLINT crc_type, SMALLINT do_access)
-{
-   ushort lastcrc16;
-   uchar lastcrc8;
-
-   // optionally access the device
-   if (do_access)
-   {
-      if (!owAccess(portnum))
-      {
-         OWERROR(OWERROR_ACCESS_FAILED);
-         return -1;
-      }
-
-      // send the write command
-      if (!owWriteByte(portnum,write_cmd))
-      {
-         OWERROR(OWERROR_WRITE_BYTE_FAILED);
-         return -1;
-      }
-
-      // send the address
-      if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8))
-      {
-         OWERROR(OWERROR_WRITE_BYTE_FAILED);
-         return -1;
-      }
-   }
-
-   // send the data to write
-   if (!owWriteByte(portnum,write_byte))
-   {
-      OWERROR(OWERROR_WRITE_BYTE_FAILED);
-      return -1;
-   }
-
-   // read the CRC
-   if (crc_type == 0)
-   {
-      // calculate CRC8
-      if (do_access)
-      {
-         setcrc8(portnum,0);
-         docrc8(portnum,(uchar)write_cmd);
-         docrc8(portnum,(uchar)(addr & 0xFF));
-         docrc8(portnum,(uchar)(addr >> 8));
-      }
-      else
-         setcrc8(portnum,(uchar)(addr & 0xFF));
-
-      docrc8(portnum,(uchar)write_byte);
-      // read and calculate the read crc
-      lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum));
-      // crc should now be 0x00
-      if (lastcrc8 != 0)
-      {
-         OWERROR(OWERROR_CRC_FAILED);
-         return -1;
-      }
-   }
-   else
-   {
-      // CRC16
-      if (do_access)
-      {
-         setcrc16(portnum,0);
-         docrc16(portnum,(ushort)write_cmd);
-         docrc16(portnum,(ushort)(addr & 0xFF));
-         docrc16(portnum,(ushort)(addr >> 8));
-      }
-      else
-         setcrc16(portnum,(ushort)addr);
-      docrc16(portnum,(ushort)write_byte);
-      // read and calculate the read crc
-      docrc16(portnum,(ushort)owReadByte(portnum));
-      lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum));
-      // crc should now be 0xB001
-      if (lastcrc16 != 0xB001)
-         return -1;
-   }
-
-   // send the program pulse
-   if (!owProgramPulse(portnum))
-   {
-      OWERROR(OWERROR_PROGRAM_PULSE_FAILED);
-      return -1;
-   }
-
-   // read back and return the resulting byte
-   return owReadByte(portnum);
-}
-
-
+//---------------------------------------------------------------------------\r
+// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a\r
+// copy of this software and associated documentation files (the "Software"),\r
+// to deal in the Software without restriction, including without limitation\r
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+// and/or sell copies of the Software, and to permit persons to whom the\r
+// Software is furnished to do so, subject to the following conditions:\r
+//\r
+// The above copyright notice and this permission notice shall be included\r
+// in all copies or substantial portions of the Software.\r
+//\r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES\r
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r
+// OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+// Except as contained in this notice, the name of Dallas Semiconductor\r
+// shall not be used except as stated in the Dallas Semiconductor\r
+// Branding Policy.\r
+//---------------------------------------------------------------------------\r
+//\r
+//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API\r
+//              for transport functions.\r
+//\r
+//  Version: 3.00\r
+//\r
+\r
+#include "ownet.h"\r
+#include <windows.h>\r
+\r
+// external TMEX variables\r
+extern long SessionHandle[MAX_PORTNUM];\r
+extern short far pascal TMBlockIO(long, uchar *, short);\r
+extern short far pascal TMBlockStream(long, uchar *, short);\r
+\r
+//--------------------------------------------------------------------------\r
+// The 'owBlock' transfers a block of data to and from the\r
+// 1-Wire Net with an optional reset at the begining of communication.\r
+// The result is returned in the same buffer.\r
+//\r
+// 'do_reset' - cause a owTouchReset to occure at the begining of\r
+//              communication TRUE(1) or not FALSE(0)\r
+// 'tran_buf' - pointer to a block of unsigned\r
+//              chars of length 'TranferLength' that will be sent\r
+//              to the 1-Wire Net\r
+// 'tran_len' - length in bytes to transfer\r
+// Supported devices: all\r
+//\r
+// Returns:   TRUE (1) : The optional reset returned a valid\r
+//                       presence (do_reset == TRUE) or there\r
+//                       was no reset required.\r
+//            FALSE (0): The reset did not return a valid prsence\r
+//                       (do_reset == TRUE).\r
+//\r
+//  The maximum tran_len is 64\r
+//\r
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len)\r
+{\r
+   short rslt;\r
+\r
+   // check for a block too big\r
+   if (tran_len > 192)\r
+   {\r
+      OWERROR(OWERROR_BLOCK_TOO_BIG);\r
+      return FALSE;\r
+   }\r
+\r
+   // check if need to do a owTouchReset first\r
+   if (do_reset)\r
+      rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len);\r
+   else\r
+      rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len);\r
+\r
+   return (rslt == tran_len);\r
+}\r
+\r
+//--------------------------------------------------------------------------\r
+// Write a byte to an EPROM 1-Wire device.\r
+//\r
+// Supported devices: crc_type=0(CRC8)\r
+//                        DS1982\r
+//                    crc_type=1(CRC16)\r
+//                        DS1985, DS1986, DS2407\r
+//\r
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to\r
+//                indicate the symbolic port number.\r
+// 'write_byte' - byte to program\r
+// 'addr'       - address of byte to program\r
+// 'write_cmd'  - command used to write (0x0F reg mem, 0x55 status)\r
+// 'crc_type'   - CRC used (0 CRC8, 1 CRC16)\r
+// 'do_access'  - Flag to access device for each byte\r
+//                (0 skip access, 1 do the access)\r
+//                WARNING, only use do_access=0 if programing the NEXT\r
+//                byte immediatly after the previous byte.\r
+//\r
+// Returns: >=0   success, this is the resulting byte from the program\r
+//                effort\r
+//          -1    error, device not connected or program pulse voltage\r
+//                not available\r
+//\r
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,\r
+                       SMALLINT crc_type, SMALLINT do_access)\r
+{\r
+   ushort lastcrc16;\r
+   uchar lastcrc8;\r
+\r
+   // optionally access the device\r
+   if (do_access)\r
+   {\r
+      if (!owAccess(portnum))\r
+      {\r
+         OWERROR(OWERROR_ACCESS_FAILED);\r
+         return -1;\r
+      }\r
+\r
+      // send the write command\r
+      if (!owWriteByte(portnum,write_cmd))\r
+      {\r
+         OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+         return -1;\r
+      }\r
+\r
+      // send the address\r
+      if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8))\r
+      {\r
+         OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+         return -1;\r
+      }\r
+   }\r
+\r
+   // send the data to write\r
+   if (!owWriteByte(portnum,write_byte))\r
+   {\r
+      OWERROR(OWERROR_WRITE_BYTE_FAILED);\r
+      return -1;\r
+   }\r
+\r
+   // read the CRC\r
+   if (crc_type == 0)\r
+   {\r
+      // calculate CRC8\r
+      if (do_access)\r
+      {\r
+         setcrc8(portnum,0);\r
+         docrc8(portnum,(uchar)write_cmd);\r
+         docrc8(portnum,(uchar)(addr & 0xFF));\r
+         docrc8(portnum,(uchar)(addr >> 8));\r
+      }\r
+      else\r
+         setcrc8(portnum,(uchar)(addr & 0xFF));\r
+\r
+      docrc8(portnum,(uchar)write_byte);\r
+      // read and calculate the read crc\r
+      lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum));\r
+      // crc should now be 0x00\r
+      if (lastcrc8 != 0)\r
+      {\r
+         OWERROR(OWERROR_CRC_FAILED);\r
+         return -1;\r
+      }\r
+   }\r
+   else\r
+   {\r
+      // CRC16\r
+      if (do_access)\r
+      {\r
+         setcrc16(portnum,0);\r
+         docrc16(portnum,(ushort)write_cmd);\r
+         docrc16(portnum,(ushort)(addr & 0xFF));\r
+         docrc16(portnum,(ushort)(addr >> 8));\r
+      }\r
+      else\r
+         setcrc16(portnum,(ushort)addr);\r
+      docrc16(portnum,(ushort)write_byte);\r
+      // read and calculate the read crc\r
+      docrc16(portnum,(ushort)owReadByte(portnum));\r
+      lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum));\r
+      // crc should now be 0xB001\r
+      if (lastcrc16 != 0xB001)\r
+         return -1;\r
+   }\r
+\r
+   // send the program pulse\r
+   if (!owProgramPulse(portnum))\r
+   {\r
+      OWERROR(OWERROR_PROGRAM_PULSE_FAILED);\r
+      return -1;\r
+   }\r
+\r
+   // read back and return the resulting byte\r
+   return owReadByte(portnum);\r
+}\r
+\r
+\r