-
-// 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"
-
-
-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 owid1[8]={0x28, 0xA6, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x68};/**/
-uint8_t owid2[8]={0x26, 0xA7, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x20};/**/
-uint8_t config_info1[16]={0x01,0x02 ,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 double V,ktemp;
-
-uint16_t ADmess() {
- ADMUX=0b10101101;
- ADCSRA|=(1<<ADSC);
- while ((ADCSRA&(1<<ADSC)));
- return ADC;
-}
-
-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-(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
- 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);
-
- gcontrol=1;
- sei();
- ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
- //DDRB|=(1<<PINB1);
-
- 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;
- while(1) {
- if ((gcontrol==2)||(gcontrol==3)) {
- wdcounter=1;
- gcontrol=0;
-
- }
-
- if (wdcounter>0) {
- if (par==0) {
- //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-2;
- 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;
- }
- }
- ares[par]=ADmess();
- par++;
- if (par>15) par=0;
- wdcounter=0;
- }
-
- if (gcontrol==1) {
- gcontrol=0;
- 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;
- uint16_t htemp;
- ktemp=gettemp_rs(V);
- //htemp=(ktemp*16)/10;
- htemp=(ktemp*16+temperatureC*1.6)/10;
-
- uint16_t w=htemp;
- 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/SHT2x.h"\r
+\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
+\r
+\r
+\r
+uint8_t owid1[8]={0x28, 0xA6, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x68};/**/\r
+uint8_t owid2[8]={0x26, 0xA7, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x20};/**/\r
+uint8_t config_info1[16]={0x01,0x02 ,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
+volatile double V,ktemp;\r
+\r
+uint16_t ADmess() {\r
+ ADMUX=0b10101101;\r
+ ADCSRA|=(1<<ADSC);\r
+ while ((ADCSRA&(1<<ADSC)));\r
+ return ADC;\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-(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
+ if (testSW()) {\r
+ config_info2[5]=8;\r
+ }else{\r
+ config_info2[5]=7;\r
+ }\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
+ gcontrol=1;\r
+ sei();\r
+ ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);\r
+ //DDRB|=(1<<PINB1);\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
+ while(1) {\r
+ if ((gcontrol==2)||(gcontrol==3)) {\r
+ wdcounter=1;\r
+ gcontrol=0;\r
+ \r
+ }\r
+ \r
+ if (wdcounter>0) {\r
+ if (par==0) {\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-2;\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
+ }else{\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
+ }\r
+ ares[par]=ADmess();\r
+ par++;\r
+ if (par>15) par=0;\r
+ wdcounter=0;\r
+ }\r
+ \r
+ if (gcontrol==1) {\r
+ gcontrol=0;\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
+ uint16_t htemp;\r
+ ktemp=gettemp_rs(V);\r
+ //htemp=(ktemp*16)/10;\r
+ htemp=(ktemp*16+temperatureC*1.6)/10;\r
+\r
+ uint16_t w=htemp;\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
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423", "DS2423.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", "DS2423.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
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Atmel Studio Solution File, Format Version 11.00
-Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2423", "DS2423.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", "DS2423.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
-
-// Copyright (c) 2016, 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]={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;
-
-typedef union {
- uint32_t c32[4];
- uint8_t c8[16];
-} counters_t;
-
-volatile counters_t counters;
-
-volatile uint8_t istat;
-
-#define PCINT_VECTOR PCINT0_vect
-#define PIN_REG PINA
-#define PIN_DDR DDRA
-#define PIN_CH0 (1<<PINA3)
-#define PIN_CH1 (1<<PINA4)
-#define PIN_CH2 (1<<PINA1)
-#define PIN_CH3 (1<<PINA2)
-#define LPIN_CH2 (1<<PINB0)
-#define LDD_CH2 DDRB
-#define LPORT_CH2 PORTB
-#define LPIN_CH3 (1<<PINA5)
-#define LDD_CH3 DDRA
-#define LPORT_CH3 PORTA
-#define LPIN_CH0 (1<<PINA7)
-#define LDD_CH0 DDRA
-#define LPORT_CH0 PORTA
-#define LPIN_CH1 (1<<PINB1)
-#define LDD_CH1 DDRB
-#define LPORT_CH1 PORTB
-#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)
-
-
-
-ISR(PCINT0_vect) {
- if (((PIN_REG&PIN_CH0)==0)&&((istat&PIN_CH0)==PIN_CH0)) { counters.c32[0]++; LPORT_CH2|=LPIN_CH2;}
- if (((PIN_REG&PIN_CH1)==0)&&((istat&PIN_CH1)==PIN_CH1)) { counters.c32[1]++; LPORT_CH2|=LPIN_CH2;}
- if (((PIN_REG&PIN_CH2)==0)&&((istat&PIN_CH2)==PIN_CH2)) { counters.c32[2]++; LPORT_CH2|=LPIN_CH2;}
- if (((PIN_REG&PIN_CH3)==0)&&((istat&PIN_CH3)==PIN_CH3)) { counters.c32[3]++; LPORT_CH2|=LPIN_CH2;}
-
- if (((PORT_EE&PIN_EE)==0)&&((istat&PIN_EE)==PIN_EE)) {
-
- _delay_ms(50);
- if (((PORT_EE&PIN_EE)==0)) {
-
-
-
- LPORT_CH1|=LPIN_CH1;
- EEARH=0;
- 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);
- }
- _delay_ms(250);
- LPORT_CH1&=~LPIN_CH1;
-
- }
- GIFR|=(1<<PCIF0);
- }
- if ((((PINA&(1<<PINA6)))==0)&&((istat&(1<<PINA6))==(1<<PINA6))) {
- _delay_ms(100);
- if (((PINA&(1<<PINA6)))==0) {
- LPORT_CH3|=LPIN_CH3;
- _delay_ms(100);
-
- counters.c32[0]=0;
- counters.c32[2]=0;
- counters.c32[1]=0;
- counters.c32[3]=0;
- LPORT_CH3&=~LPIN_CH3;
- }
- GIFR|=(1<<PCIF0);
-
- }
- istat=PIN_REG;
-
-}
-
-
-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...
-
- PORTB|=0xFF-(1<<PINB2); //Make PullUp an all Pins but not OW_PIN
- PORTA|=0xFF;
- PORTA&=~((1<<PINA1)|(1<<PINA2)|(1<<PINA3)|(1<<PINA4));
-
- GIMSK|=(1<<PCIE0);
- PCMSK0=(1<<PCINT1)|(1<<PCINT2)|(1<<PCINT3)|(1<<PCINT4);
- //Spannungsdetektor
- DDRA&=~(1<<PINA0);
- PCMSK0|=(1<<PCINT0);
- PORTA&=~(1<<PINA0);
- //Taster
- DDRA&=~(1<<PINA6);
- PCMSK0|=(1<<PCINT6);
- PORTA|=(1<<PINA6); //Pullup
-
-
-
- LDD_CH0|=LPIN_CH0;
- LPORT_CH0&=~LPIN_CH0;
- LDD_CH1|=LPIN_CH1;
- LPORT_CH1&=~LPIN_CH1;
- LDD_CH2|=LPIN_CH2;
- LPORT_CH2&=~LPIN_CH2;
- LDD_CH3|=LPIN_CH3;
- LPORT_CH3&=~LPIN_CH3;
-
-
-
- LPORT_CH0|=LPIN_CH0;
- _delay_ms(500);
- LPORT_CH0&=~LPIN_CH0;
-
- istat=PINA;
- 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;
- }
-
-
- sei();
- while(1) {
- if (LPORT_CH2&LPIN_CH2) {
- _delay_ms(50);
- LPORT_CH2&=~LPIN_CH2;
- }
- //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) 2016, 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
+\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
+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
+#define PCINT_VECTOR PCINT0_vect\r
+#define PIN_REG PINA\r
+#define PIN_DDR DDRA\r
+#define PIN_CH0 (1<<PINA3)\r
+#define PIN_CH1 (1<<PINA4)\r
+#define PIN_CH2 (1<<PINA1)\r
+#define PIN_CH3 (1<<PINA2)\r
+#define LPIN_CH2 (1<<PINB0)\r
+#define LDD_CH2 DDRB\r
+#define LPORT_CH2 PORTB\r
+#define LPIN_CH3 (1<<PINA5)\r
+#define LDD_CH3 DDRA\r
+#define LPORT_CH3 PORTA\r
+#define LPIN_CH0 (1<<PINA7)\r
+#define LDD_CH0 DDRA\r
+#define LPORT_CH0 PORTA\r
+#define LPIN_CH1 (1<<PINB1)\r
+#define LDD_CH1 DDRB\r
+#define LPORT_CH1 PORTB\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
+\r
+\r
+ISR(PCINT0_vect) {\r
+ if (((PIN_REG&PIN_CH0)==0)&&((istat&PIN_CH0)==PIN_CH0)) { counters.c32[0]++; LPORT_CH2|=LPIN_CH2;}\r
+ if (((PIN_REG&PIN_CH1)==0)&&((istat&PIN_CH1)==PIN_CH1)) { counters.c32[1]++; LPORT_CH2|=LPIN_CH2;}\r
+ if (((PIN_REG&PIN_CH2)==0)&&((istat&PIN_CH2)==PIN_CH2)) { counters.c32[2]++; LPORT_CH2|=LPIN_CH2;}\r
+ if (((PIN_REG&PIN_CH3)==0)&&((istat&PIN_CH3)==PIN_CH3)) { counters.c32[3]++; LPORT_CH2|=LPIN_CH2;}\r
+\r
+ if (((PORT_EE&PIN_EE)==0)&&((istat&PIN_EE)==PIN_EE)) {\r
+ \r
+ _delay_ms(50);\r
+ if (((PORT_EE&PIN_EE)==0)) {\r
+\r
+ \r
+\r
+ LPORT_CH1|=LPIN_CH1;\r
+ EEARH=0;\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
+ _delay_ms(250);\r
+ LPORT_CH1&=~LPIN_CH1;\r
+\r
+ }\r
+ GIFR|=(1<<PCIF0);\r
+ }\r
+ if ((((PINA&(1<<PINA6)))==0)&&((istat&(1<<PINA6))==(1<<PINA6))) {\r
+ _delay_ms(100);\r
+ if (((PINA&(1<<PINA6)))==0) {\r
+ LPORT_CH3|=LPIN_CH3;\r
+ _delay_ms(100);\r
+\r
+ counters.c32[0]=0;\r
+ counters.c32[2]=0;\r
+ counters.c32[1]=0;\r
+ counters.c32[3]=0;\r
+ LPORT_CH3&=~LPIN_CH3;\r
+ }\r
+ GIFR|=(1<<PCIF0);\r
+\r
+ }\r
+ istat=PIN_REG;\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
+ 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
+ PORTB|=0xFF-(1<<PINB2); //Make PullUp an all Pins but not OW_PIN\r
+ PORTA|=0xFF; \r
+ PORTA&=~((1<<PINA1)|(1<<PINA2)|(1<<PINA3)|(1<<PINA4));\r
+ \r
+ GIMSK|=(1<<PCIE0);\r
+ PCMSK0=(1<<PCINT1)|(1<<PCINT2)|(1<<PCINT3)|(1<<PCINT4);\r
+ //Spannungsdetektor\r
+ DDRA&=~(1<<PINA0);\r
+ PCMSK0|=(1<<PCINT0);\r
+ PORTA&=~(1<<PINA0);\r
+ //Taster\r
+ DDRA&=~(1<<PINA6);\r
+ PCMSK0|=(1<<PCINT6);\r
+ PORTA|=(1<<PINA6); //Pullup\r
+\r
+\r
+\r
+ LDD_CH0|=LPIN_CH0;\r
+ LPORT_CH0&=~LPIN_CH0;\r
+ LDD_CH1|=LPIN_CH1;\r
+ LPORT_CH1&=~LPIN_CH1;\r
+ LDD_CH2|=LPIN_CH2;\r
+ LPORT_CH2&=~LPIN_CH2;\r
+ LDD_CH3|=LPIN_CH3;\r
+ LPORT_CH3&=~LPIN_CH3;\r
+\r
+\r
+\r
+ LPORT_CH0|=LPIN_CH0;\r
+ _delay_ms(500);\r
+ LPORT_CH0&=~LPIN_CH0;\r
+ \r
+ istat=PINA;\r
+ EEARH=0;\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
+ \r
+ sei();\r
+ while(1) {\r
+ if (LPORT_CH2&LPIN_CH2) {\r
+ _delay_ms(50);\r
+ LPORT_CH2&=~LPIN_CH2;\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
-
-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_DHT22", "DS2438_DHT22.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}") = "DS2438_DHT22", "DS2438_DHT22.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
-// Copyright (c) 2016, 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/HDC1080.h"
-#include "../common/calibr.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();
- HDC1080_Init();
- HDC1080_Readf(&temperatureC,&humidityRH);
-
- sei();
-
- while(1) {
- if (gcontrol) {
- wdcounter=3;
- gcontrol=0;
- }
- if (wdcounter>2) {
- //PORTB|=(1<<PINB1); //Dauer 440ms
- HDC1080_Readf(&temperatureC,&humidityRH);
-
- humidityRH = calibr_hum(temperatureC,-0.2,humidityRH)*10.0;
- temperatureC-=0.2;
- temperatureC*=10.0;
- if (testSW()) {
- am2302_hum= humidityRH;
- am2302_temp=temperatureC*25.6;
- //am2302_temp=am2302_temp-45;
- config_info[5]=12;
-
- }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) 2016, 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/HDC1080.h"\r
+#include "../common/calibr.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
+ HDC1080_Init();\r
+ HDC1080_Readf(&temperatureC,&humidityRH);\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
+ HDC1080_Readf(&temperatureC,&humidityRH);\r
+\r
+ humidityRH = calibr_hum(temperatureC,-0.2,humidityRH)*10.0;\r
+ temperatureC-=0.2;\r
+ temperatureC*=10.0;\r
+ if (testSW()) {\r
+ am2302_hum= humidityRH;\r
+ am2302_temp=temperatureC*25.6;\r
+ //am2302_temp=am2302_temp-45;\r
+ config_info[5]=12; \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
-
-// 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"
-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, 0x06,0x09, 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;
-uint32_t P;
-int32_t t;
-
-
-
-
-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);
-
- 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);
- 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=0;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
+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, 0x06,0x09, 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
+uint32_t P;\r
+int32_t t;\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
+ 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
+ \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
+ 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=0;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
-
-// 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
-
-// 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/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, 0x06,0x09,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();
- 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);
-
- 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=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/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, 0x06,0x09,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
+ 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
+\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=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
-
-// 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
-
-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
-
-// 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 "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/MAX1164x.h"
-#include "../common/I2C/SHT2x.h"
-#include "../common/calibr.h"
-#include "../common/I2C/BMP280.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, 0x08,1, 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=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;
-
-
-}
-
-volatile uint16_t _temp;
-volatile uint16_t _hum;
-
-
-uint8_t userRegister[1];
-int16_t sRH,sT;
-double temperatureC,humidityRH,hhum;
-double l;
-
-double R0;
-uint16_t mr;
-uint8_t startup=10;
-double ip;
-
-uint32_t bmp_P;
-int32_t bmp_t;
-
-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
-
-uint16_t weekmaxarr[8];
-
-
-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;
-
-
-typedef struct {
- int16_t current; //6
- uint16_t R0;
- //uint16_t VS;
- uint8_t cmode;
- int16_t ip;
- //uint8_t free;
- uint16_t tol_s8;
- uint16_t tol_d;
- uint16_t r_day_max;
- uint16_t r_week_max;
-} pack2_t;
-volatile pack2_t pack2;
-
-
-//Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte
-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;
-}
-
-#define EEPROM_R0 0
-#define EEPROM_R0d 2
-#define EEPROM_R0w 4
-#define EEPROM_dol 6
-
-
-uint16_t readEEPROM(uint8_t addr,uint16_t def) {
- uint16_t hr;
- while(EECR & (1<<EEPE));
- EEARL=addr+1;
- EECR |= (1<<EERE);
- hr=EEDR;
- if (hr!=0xFF) {
- hr=hr<<8;
- while(EECR & (1<<EEPE));
- EEARL=addr;
- EECR |= (1<<EERE);
- hr|=EEDR;
- return hr;
- }
- return def;
-}
-
-void writeEEPROM(uint8_t addr,uint16_t val) {
- while(EECR & (1<<EEPE));
- EECR = (0<<EEPM1)|(0<<EEPM0);
- EEARL = addr;
- EEDR = val&0xFF;
- EECR |= (1<<EEMPE);
- EECR |= (1<<EEPE);
- while(EECR & (1<<EEPE));
- EECR = (0<<EEPM1)|(0<<EEPM0);
- EEARL = addr+1;
- EEDR = val>>8;
- EECR |= (1<<EEMPE);
- EECR |= (1<<EEPE);
-}
-
-
-
-
-
-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();
- DDRB|=(1<<PINB1);//Ausgang und 1
- DDRA|=(1<<PINA0);
-
- 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;
- 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;
-
- pack2.cmode=0;
- pack2.R0=readEEPROM(EEPROM_R0,1);
- R0=pack2.R0/100.0;
-
- pack2.r_day_max=readEEPROM(EEPROM_R0d,1);
- pack2.r_week_max=readEEPROM(EEPROM_R0w,1);
- pack2.tol_d=readEEPROM(EEPROM_dol,0);
- pack2.tol_s8=0; //Tag faengt mit Einschalten an
- for(uint8_t i=0;i<7;i++) {
- weekmaxarr[i]=pack2.r_week_max;
- }
-
- USI_TWI_Master_Initialise();
- bmp280Init();
- SHT2x_SoftReset();
- SHT2x_ReadUserRegister(userRegister);
- SHT2x_WriteUserRegister(userRegister); //write changed user reg
- 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();
-
-
- while(1) {
-
- /*if (pack1.config==0x1F) {
- pack1.config=0x7F;
- R0=1;
- pack2.R0=0;
- writeEEPROM(EEPROM_R0,0);
- }
- if (pack1.config==0x05) {
- pack1.config=0x7F;
- pack2.r_day_max=1;
- pack2.r_week_max=1;
- pack2.tol_d=0;
- pack2.tol_s8=0; //Tag faengt mit Einschalten an
- R0=1;
- writeEEPROM(EEPROM_R0,0xFF);
- writeEEPROM(EEPROM_R0d,0xFF); //Maximum des Tages
- writeEEPROM(EEPROM_R0w,0xFF); //Maximum der Letzten 7 Tage
- writeEEPROM(EEPROM_dol,0xFF); //Anzahl der Betriebstage
- for(uint8_t i=0;i<7;i++) {
- weekmaxarr[i]=1;
- }
- } */
- if (wdcounter>0) {
- pack2.tol_s8++;
- if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang
- pack2.tol_s8=0;
- pack2.tol_d++; //rund 180 Jahre :-)
- pack2.r_week_max=0;
- weekmaxarr[7]=pack2.r_day_max;
- for(uint8_t i=0;i<7;i++) {
- weekmaxarr[i]=weekmaxarr[i+1];
- if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i];
- }
- if (pack2.tol_d>7) {
- pack2.R0=pack2.r_week_max;
- } else {
- pack2.R0=pack2.r_day_max;
- }
- //R0=pack2.R0/100.0-0.5*(pack2.R0/100.0-R0);
- R0=R0-(R0-pack2.R0/100.0)*0.5 ;
- pack2.R0=R0*100;
- writeEEPROM(EEPROM_R0,pack2.R0);
- writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages
- writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage
- writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage
- pack2.r_day_max=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);
- pack2.ip=ip*1000;
- //humidityRH=calibr_hum(temperatureC,-0.45,humidityRH);
- //temperatureC =temperatureC -0.45;
- _hum= humidityRH*100.0;
- _temp=(temperatureC*100.0)+32767;
- //PORTB&=~(1<<PINB1);
- mr=0;
-//Kritische Sektion !___Ein Breakpoint in dieser Section kann den TGS8100 zerstoeren!___________________________
- PORTB&=~(1<<PINB1); //Auf 0 Ziehen
- _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 (pack2.cmode) { //cmode=0 V 0..2 V cmode=1 V 1.5..3.5V
- //l+=1.5; //Spannung real
- mr+=6000;
- }
- //if (l>1.8) {
- if (mr>7200) {
- if (pack2.cmode==0) {
- MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1);
- pack2.cmode=1;
- }
- }
- //if (l<1.6) {
- if (mr<6400) {
- if (pack2.cmode==1) {
- MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);
- pack2.cmode=0;
- }
-
-
- }
- //pack2.VS=mr*5/2;
- l=mr/4000.0;
- l=( 3/l- 1) *30;
- pack2.current=l*100;
-
- l=l/ip;
-
- if (startup==0){
- if (l>R0) {
- R0=l;
- pack2.R0=R0*100;
- writeEEPROM(EEPROM_R0,pack2.R0);
-
- }
- if (l*100>pack2.r_day_max) {
- pack2.r_day_max=l*100;
- }
- } else if (l<R0) l=R0; //negative Werte am Anfang verhintern
- l=R0/l;
- l=log(l);
- l=l*160*4; //fuer DS18B20
- bmp280ConvertIntP1(&bmp_P);
- bmp_P=bmp_P/3; // /100.0*32.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) {
- cli();pack.A=_temp;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) {
- cli();pack.B=_hum;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) {
- 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) {
- cli();pack.D=bmp_P;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);
- }
-
-
-#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 "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/MAX1164x.h"\r
+#include "../common/I2C/SHT2x.h"\r
+#include "../common/calibr.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]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/\r
+uint8_t config_info[16]={0x01,14, 0x04,0x08, 0x08,1, 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=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
+volatile uint16_t _temp;\r
+volatile uint16_t _hum;\r
+\r
+\r
+uint8_t userRegister[1];\r
+int16_t sRH,sT;\r
+double temperatureC,humidityRH,hhum;\r
+double l;\r
+\r
+double R0;\r
+uint16_t mr;\r
+uint8_t startup=10;\r
+double ip;\r
+\r
+uint32_t bmp_P;\r
+int32_t bmp_t;\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
+\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
+typedef struct {\r
+ int16_t current; //6\r
+ uint16_t R0;\r
+ //uint16_t VS;\r
+ uint8_t cmode;\r
+ int16_t ip;\r
+ //uint8_t free;\r
+ uint16_t tol_s8;\r
+ uint16_t tol_d;\r
+ uint16_t r_day_max;\r
+ uint16_t r_week_max;\r
+} pack2_t;\r
+volatile pack2_t pack2;\r
+\r
+\r
+//Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte\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
+#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
+\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
+ OWINIT();\r
+ DDRB|=(1<<PINB1);//Ausgang und 1\r
+ DDRA|=(1<<PINA0);\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
+ 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
+\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
+ USI_TWI_Master_Initialise();\r
+ bmp280Init();\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
+ \r
+\r
+ while(1) {\r
+\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.0-R0);\r
+ R0=R0-(R0-pack2.R0/100.0)*0.5 ;\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);\r
+ //temperatureC =temperatureC -0.45;\r
+ _hum= humidityRH*100.0;\r
+ _temp=(temperatureC*100.0)+32767;\r
+ //PORTB&=~(1<<PINB1);\r
+ mr=0;\r
+//Kritische Sektion !___Ein Breakpoint in dieser Section kann den TGS8100 zerstoeren!___________________________\r
+ PORTB&=~(1<<PINB1); //Auf 0 Ziehen\r
+ _delay_us(150);\r
+ mr+=MAX1164x_read();\r
+ _delay_us(150);\r
+ mr+=MAX1164x_read();\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
+ //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
+ } else if (l<R0) l=R0; //negative Werte am Anfang verhintern\r
+ l=R0/l;\r
+ l=log(l);\r
+ l=l*160*4; //fuer DS18B20\r
+ bmp280ConvertIntP1(&bmp_P);\r
+ bmp_P=bmp_P/3; // /100.0*32.0;\r
+ wdcounter=0;\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
+ cli();pack.A=_temp;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
+ cli();pack.B=_hum;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
+ 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
+ cli();pack.D=bmp_P;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
+ \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
-// Copyright (c) 2016, 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.
-
-//---------- 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 "HDC1080.h"
-typedef enum{
- I2C_ADR_W = 128, // sensor I2C address + write bit
- I2C_ADR_R = 129 // sensor I2C address + read bit
-}etI2cHeader;
-
-uint8_t HDC1080_Init() {
- volatile uint8_t error=0;
- I2c_StartCondition();
- error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
- error |= I2c_WriteByte (0x02); // Config
- error |= I2c_WriteByte (0x0); // 14 bit
- error |= I2c_WriteByte (0x0); //
- I2c_StopCondition();
- return error;
-
-}
-
-uint8_t HDC1080_Readf(double * temperature, double * hum) {
- int16_t t;
- uint16_t h;
- uint8_t error=0;
- error=HDC1080_Readi(&t,&h);
- *temperature=(double)t/65536.0*165.0-40.0;
- *hum=(double)h/65536.0*100;
- return error;
-
-}
-uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum) {
- volatile uint8_t error=0;
- I2c_StartCondition();
- error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
- error |= I2c_WriteByte (0x0); //
- I2c_StopCondition();
- _delay_ms(10);
- I2c_StartCondition();
- error |= I2c_WriteByte (I2C_ADR_R); //I2C address
- *temperature=0;
- *temperature |= I2c_ReadByte(ACK)<<8;
- *temperature |= I2c_ReadByte(ACK);
- I2c_StopCondition();
-
- I2c_StartCondition();
- error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr
- error |= I2c_WriteByte (0x01); //
- I2c_StopCondition();
- _delay_ms(10);
- I2c_StartCondition();
- error |= I2c_WriteByte (I2C_ADR_R); //I2C address
- *hum=0;
- *hum|= I2c_ReadByte(ACK)<<8;
- *hum|= I2c_ReadByte(NO_ACK);
- I2c_StopCondition();
- return error;
- }
-
-/*
-
-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(void)
-//===========================================================================
-{
- 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;
-}
+// Copyright (c) 2016, 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
+//---------- 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 "HDC1080.h"\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 HDC1080_Init() {\r
+ volatile uint8_t error=0;\r
+ I2c_StartCondition();\r
+ error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+ error |= I2c_WriteByte (0x02); // Config\r
+ error |= I2c_WriteByte (0x0); // 14 bit\r
+ error |= I2c_WriteByte (0x0); // \r
+ I2c_StopCondition();\r
+ return error;\r
+\r
+}\r
+\r
+uint8_t HDC1080_Readf(double * temperature, double * hum) { \r
+ int16_t t;\r
+ uint16_t h;\r
+ uint8_t error=0;\r
+ error=HDC1080_Readi(&t,&h);\r
+ *temperature=(double)t/65536.0*165.0-40.0;\r
+ *hum=(double)h/65536.0*100;\r
+ return error;\r
+\r
+}\r
+uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum) {\r
+ volatile uint8_t error=0;\r
+ I2c_StartCondition();\r
+ error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+ error |= I2c_WriteByte (0x0); //\r
+ I2c_StopCondition();\r
+ _delay_ms(10);\r
+ I2c_StartCondition();\r
+ error |= I2c_WriteByte (I2C_ADR_R); //I2C address\r
+ *temperature=0;\r
+ *temperature |= I2c_ReadByte(ACK)<<8;\r
+ *temperature |= I2c_ReadByte(ACK); \r
+ I2c_StopCondition();\r
+\r
+ I2c_StartCondition();\r
+ error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr\r
+ error |= I2c_WriteByte (0x01); //\r
+ I2c_StopCondition();\r
+ _delay_ms(10);\r
+ I2c_StartCondition();\r
+ error |= I2c_WriteByte (I2C_ADR_R); //I2C address\r
+ *hum=0;\r
+ *hum|= I2c_ReadByte(ACK)<<8; \r
+ *hum|= I2c_ReadByte(NO_ACK); \r
+ I2c_StopCondition();\r
+ return error;\r
+ }\r
+\r
+/*\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
*/
\ No newline at end of file
-#ifndef HDC1080_H
-#define HDC1080_H
-// Copyright (c) 2016, 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.
-
-
-uint8_t HDC1080_Init();
-
-uint8_t HDC1080_Readf(double * temperature, double * hum);
-uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum);
-
-
-#endif
+#ifndef HDC1080_H\r
+#define HDC1080_H\r
+// Copyright (c) 2016, 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
+uint8_t HDC1080_Init();\r
+\r
+uint8_t HDC1080_Readf(double * temperature, double * hum);\r
+uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum);\r
+\r
+\r
+#endif\r
-
-// 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
-#!/usr/bin/python
-# 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.
-
-
-
-
-import time
-import subprocess
-import sys
-
-def owcom(dev,send,rc):
- res=[]
- f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)
- f.write("".join(map(chr, send)))
- if (rc!=0):
- res=map(ord,f.read(rc))
- f.close()
- return res
-
-
-def crc8(arr):
- lscrc=0x0;
- for v in arr:
- bit=1;
- while bit<256:
- if (v&bit)==bit:
- lb=1
- else:
- lb=0
- if (lscrc&1)!=lb:
- lscrc=(lscrc>>1)^0x8c
- else:
- lscrc=(lscrc>>1)
- bit=bit*2
- return lscrc
-
-def testnr(s):
- for c in s.lower()[:]:
- if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):
- return False
- return True
-
-def addid(id,val):
- for i in range(7):
- id[i+1]=id[i+1]+val
- if id[i+1]>254:
- id[i+1]=id[i+1]-254
- val=1
- else:
- return id
- return id
-#
-
-print "Open Hex File ...",
-fi=open(sys.argv[1],"r")
-data=[]
-for l in fi.readlines():
- sys.stdout.write(".")
- sys.stdout.flush()
- bc=int(l[1:3],16)
- fw=int(l[3:7],16)
- ty=int(l[7:9],16)
- chsm=bc+(fw>>8)+(fw&0xFF)+ty
- for i in range(bc):
- p=9+(i*2)
- d=int(l[p:p+2],16)
- chsm=(chsm+d)&0xFF
- data.append(d)
- chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF
- if (chsm!=0):
- print "Error Checksum...."
- exit()
- #print bc,fw,ty,chsm
-fi.close()
-print
-
-l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
-dc=0
-dl=[]
-for g in (l.split("\n")):
- if len(g)>2:
- if testnr(g[0:2]):
- dl.append(g)
- dc=dc+1
- print dc,") ",g
-if dc==0:
- print "No 1-Wire Device found"
- exit(0)
-n=int(raw_input("No. of Device: "))
-n=n-1
-if (n>dc-1)or(n<0):
- exit(0)
-s=dl[n]
-sys.stdout.write('Go to Flashmode....')
-sys.stdout.flush()
-owcom(s,[0x88],0)
-owcom(s,[0x88],0)
-owcom(s,[0x88],0)
-for i in range (20):
- l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
- dc=0
- dl=[]
- sys.stdout.write(".")
- sys.stdout.flush()
- for g in (l.split("\n")):
- if (g[0:15]=="a3-55aa55aa55aa"):
- break
- if (g[0:15]!="a3-55aa55aa55aa"):
- time.sleep(1)
-if (g[0:15]=="a3-55aa55aa55aa"):
- print "found"
-else:
- print "ERROR Enter Flashmode!"
- exit()
-f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
-f.write(s)
-f.close()
-time.sleep(5)
-s="a3-55aa55aa55aa"
-prog=data
-l=len(prog)
-if (l>7616):
- print "Code to big ... Max 7616 Byte (119 Pages)"
- exit()
-pages= l/64
-for i in range(64-(l%64)):
- #print i
- prog.append(0xFF)
-pages= len(prog)/64
-if (pages>119):
- print "Code to big ... Max 7616 Byte (119 Pages)"
- exit()
-
-
-print "Programm Page (of ", pages,")"
-
-for i in range(pages):
- sys.stdout.write("%i " % (i+1) )
- sys.stdout.flush()
-
- h=i*64;
- hl=h&0xFF
- hh=h>>8
- #print hh, hl
- mem=[hl,hh]+prog[h:h+64]
- erroc=0
- while (1):
- owcom(s,[0x0F]+mem,0)
- rmem=owcom(s,[0xAA],66)
- if (rmem!=mem):
- print rmem
- erroc=erroc+1
- if erroc>5:
- print "WRITING ERROR ... "
- exit()
- continue
- owcom(s,[0x55],0)
- time.sleep(0.05)
- owcom(s,[0xB8,hl,hh],0)
- time.sleep(0.05)
- rmem=owcom(s,[0xAA],66)
- if (rmem!=mem):
- print "error in flash"
- print mem
- print rmem
- erroc=erroc+1
- if erroc>5:
- print "WRITING ERROR ... "
- exit()
- continue
- #for v in rmem:
- # print "%02X " % (v),
- break
-print "\nReset AVR"
-owcom(s,[0x89],0)
-time.sleep(1)
-f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
-f.write("a3-55aa55aa55aa")
-f.close()
-
-
-
-
-
-
-#mem=[0x00,0x2]
-#for i in range (64):
-# mem.append(i)
-#owcom(s,[0x0F]+mem,0)
-#rmem=owcom(s,[0xAA],70)
-#print rmem
-#owcom(s,[0x55],0)
-#time.sleep(0.05)
-#owcom(s,[0xB8,0x00,0x02],0)
-#time.sleep(0.05)
-#rmem=owcom(s,[0xAA],70)
-#print rmem
-#for v in rmem:
-# print "%02X " % (v)
-
-
-
+#!/usr/bin/python\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
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+ res=[]\r
+ f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+ f.write("".join(map(chr, send)))\r
+ if (rc!=0):\r
+ res=map(ord,f.read(rc))\r
+ f.close()\r
+ return res\r
+ \r
+\r
+def crc8(arr):\r
+ lscrc=0x0;\r
+ for v in arr:\r
+ bit=1;\r
+ while bit<256:\r
+ if (v&bit)==bit:\r
+ lb=1\r
+ else:\r
+ lb=0\r
+ if (lscrc&1)!=lb:\r
+ lscrc=(lscrc>>1)^0x8c \r
+ else:\r
+ lscrc=(lscrc>>1)\r
+ bit=bit*2\r
+ return lscrc\r
+ \r
+def testnr(s):\r
+ for c in s.lower()[:]:\r
+ if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+ return False\r
+ return True\r
+ \r
+def addid(id,val):\r
+ for i in range(7):\r
+ id[i+1]=id[i+1]+val\r
+ if id[i+1]>254:\r
+ id[i+1]=id[i+1]-254\r
+ val=1\r
+ else:\r
+ return id\r
+ return id\r
+#\r
+\r
+print "Open Hex File ...",\r
+fi=open(sys.argv[1],"r")\r
+data=[]\r
+for l in fi.readlines():\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ bc=int(l[1:3],16)\r
+ fw=int(l[3:7],16)\r
+ ty=int(l[7:9],16)\r
+ chsm=bc+(fw>>8)+(fw&0xFF)+ty\r
+ for i in range(bc):\r
+ p=9+(i*2)\r
+ d=int(l[p:p+2],16)\r
+ chsm=(chsm+d)&0xFF\r
+ data.append(d)\r
+ chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF\r
+ if (chsm!=0):\r
+ print "Error Checksum...."\r
+ exit()\r
+ #print bc,fw,ty,chsm\r
+fi.close()\r
+print\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in (l.split("\n")):\r
+ if len(g)>2:\r
+ if testnr(g[0:2]):\r
+ dl.append(g)\r
+ dc=dc+1\r
+ print dc,") ",g\r
+if dc==0:\r
+ print "No 1-Wire Device found"\r
+ exit(0)\r
+n=int(raw_input("No. of Device: "))\r
+n=n-1\r
+if (n>dc-1)or(n<0):\r
+ exit(0)\r
+s=dl[n]\r
+sys.stdout.write('Go to Flashmode....')\r
+sys.stdout.flush()\r
+owcom(s,[0x88],0)\r
+owcom(s,[0x88],0)\r
+owcom(s,[0x88],0)\r
+for i in range (20):\r
+ l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+ dc=0\r
+ dl=[]\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ for g in (l.split("\n")):\r
+ if (g[0:15]=="a3-55aa55aa55aa"):\r
+ break\r
+ if (g[0:15]!="a3-55aa55aa55aa"):\r
+ time.sleep(1)\r
+if (g[0:15]=="a3-55aa55aa55aa"):\r
+ print "found"\r
+else:\r
+ print "ERROR Enter Flashmode!" \r
+ exit()\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+f.write(s)\r
+f.close()\r
+time.sleep(5)\r
+s="a3-55aa55aa55aa"\r
+prog=data\r
+l=len(prog)\r
+if (l>7616):\r
+ print "Code to big ... Max 7616 Byte (119 Pages)"\r
+ exit()\r
+pages= l/64\r
+for i in range(64-(l%64)):\r
+ #print i\r
+ prog.append(0xFF)\r
+pages= len(prog)/64\r
+if (pages>119):\r
+ print "Code to big ... Max 7616 Byte (119 Pages)"\r
+ exit()\r
+\r
+\r
+print "Programm Page (of ", pages,")"\r
+ \r
+for i in range(pages):\r
+ sys.stdout.write("%i " % (i+1) )\r
+ sys.stdout.flush()\r
+\r
+ h=i*64;\r
+ hl=h&0xFF\r
+ hh=h>>8\r
+ #print hh, hl\r
+ mem=[hl,hh]+prog[h:h+64]\r
+ erroc=0\r
+ while (1):\r
+ owcom(s,[0x0F]+mem,0) \r
+ rmem=owcom(s,[0xAA],66)\r
+ if (rmem!=mem):\r
+ print rmem\r
+ erroc=erroc+1\r
+ if erroc>5:\r
+ print "WRITING ERROR ... "\r
+ exit()\r
+ continue\r
+ owcom(s,[0x55],0) \r
+ time.sleep(0.05)\r
+ owcom(s,[0xB8,hl,hh],0)\r
+ time.sleep(0.05)\r
+ rmem=owcom(s,[0xAA],66)\r
+ if (rmem!=mem):\r
+ print "error in flash"\r
+ print mem\r
+ print rmem\r
+ erroc=erroc+1\r
+ if erroc>5:\r
+ print "WRITING ERROR ... "\r
+ exit()\r
+ continue\r
+ #for v in rmem:\r
+ # print "%02X " % (v),\r
+ break\r
+print "\nReset AVR"\r
+owcom(s,[0x89],0)\r
+time.sleep(1)\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+f.write("a3-55aa55aa55aa")\r
+f.close() \r
+ \r
+ \r
+\r
+\r
+\r
+\r
+#mem=[0x00,0x2]\r
+#for i in range (64):\r
+# mem.append(i)\r
+#owcom(s,[0x0F]+mem,0)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#owcom(s,[0x55],0)\r
+#time.sleep(0.05)\r
+#owcom(s,[0xB8,0x00,0x02],0)\r
+#time.sleep(0.05)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#for v in rmem:\r
+# print "%02X " % (v)\r
+ \r
+\r
+ \r
+++ /dev/null
-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
+++ /dev/null
-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
+++ /dev/null
-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 "
-
-gplist=[]
-
-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
-
-voc_marker=[]
-
-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=[]
- 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)
- dev.append(config[1:])
- 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
-
-def getProperties(dev,voc):
- pl=[]
- if dev[0][0]==0x26:
- pl=["Temperatur","Spannung","Luftfeuchte","Strom"]
- if dev[1][0]!=0xFF:
- pl=[]
- for i in range(4):
- name=getName(dev[1][i*2])
- if len(name)!=0:
- pl.append(name[0])
- if voc!=0:
- #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
- pl.append("R0")
- pl.append("VS")
- pl.append("Corr")
- pl.append("cmode")
- pl.append("RS")
- pl.append("RSR0")
- pl.append("VOC1")
- pl.append("VOC2")
- if dev[0][0]==0x28:
- pl=["Temperatur"]
- if dev[1][0]!=0xFF:
- pl=[]
- for i in range(4):
- name=getName(dev[1][i*2])
- if len(name)!=0:
- pl.append(name[0])
- return pl
-
-def getValues(dev,voc):
- pl=[]
- #print(id2string(dev[0]),voc)
- if dev[0][0]==0x26:
- vnok=1
- 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)
- curr=sb[7]+sb[8]*256
- if (sb[8] & 0x80):
- curr=-(curr&0x7FFF)
- 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:
- print(cvals)
- vnok=0
- 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 gp_makefile(name,i):
- f=open("gpscript%i.dem" %(i),"w")
- #f.write("set decimalsign ','\n")
- f.write('set decimalsign locale\n')
- f.write('set timefmt "%d.%m.%Y %H:%M:%S"\n')
- f.write('set xdata time\n')
- f.write('set datafile separator "\\t" \n')
- f.write('set terminal png size 1024,600\n')
- f.write('set format x "%d.%m\\n%H:%M"\n')
- f.write("set output '%s'\n" % (name))
- f.write("set grid ytics\n")
- f.write("set terminal postscript landscape\n")
- f.write('set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#FFFFFF" behind\n')
- #set output 'Temperatur.ps'
- return f
-
-
-def gnuplot():
- rl=["Temperatur","Luftfeuchte","Druck","VOC","Beleuchtungsstaerke"]
- rlf=[]
- rls=[]
- rllc=[]
- for i in range(len(rl)):
- rlf.append("") #begin of plotline
- rls.append('') #plotline
- rllc.append('') #lineconfig
- li=0
- for c in gplist:
- for i in range(len(rl)):
- if c[0]==rl[i]:
- li=li+1
- cl=c[2].split(",")
- rls[i]=rls[i]+" %s using 1:%i with linespoints ls %i title \"%s\" ," % (rlf[i],c[1],li,cl[0])
- rllc[i]=rllc[i]+ "set style line %i %s\n" % (li,cl[1])
- rlf[i]='""'
- for i in range(len(rl)):
- f=gp_makefile(rl[i]+".ps",i)
- f.write(rllc[i])
- f.write('plot "log22.txt" '+rls[i]+"\n")
- f.write("set output '%s'\n" % (rl[i]+"_l.ps"))
- f.write('plot "< tail -n 100 log22.txt" '+rls[i]+"\n")
- f.close()
- p = subprocess.Popen(["gnuplot","gpscript%i.dem" %(i)], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p.wait();
- cmd="convert -size 2048x1600 -depth 8 %s.ps -rotate 90 -resize 1024x800 -depth 8 %s.png" %(rl[i],rl[i])
- p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p.wait();
- cmd="convert -size 2048x1600 -depth 8 %s_l.ps -rotate 90 -resize 1024x800 -depth 8 %s_l.png" %(rl[i],rl[i])
- print cmd.split(" ")
- p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p.wait();
- shutil.copyfile(rl[i]+".png","/var/www/html/"+rl[i]+".png")
- shutil.copyfile(rl[i]+"_l.png","/var/www/html/"+rl[i]+"_l.png")
-
-devlist=owList()
-print(voc_marker)
-tline1="\t"
-tline2="time\t"
-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])
-
-i=0
-col=1
-
-
-devlist1=[]
-devlistn=[]
-voc_marker1=[]
-
-for d in devwholist:
- i=0
- print(d)
- for dd in devlist:
- if id2string(dd[0])==d:
- print("->",id2string(dd[0]))
- devlist1.append(dd)
- devlist.remove(dd)
- voc_marker1.append(voc_marker[i])
- del voc_marker[i]
- break
- i=i+1
-for d in devlist:
- devlist1.append(d)
-
-devlist=devlist1
-voc_marker=voc_marker1
-
-
-print devlist
-
-print voc_marker
-
-
-
-for d in devlist:
- print(d[0])
- prop=getProperties(d,voc_marker[i])
- if len(prop)>0:
- tline1=tline1+id2string(d[0])
- for p in prop:
- tline2=tline2+p+"\t"
- tline1=tline1+"\t"
- col=col+1
- dn=id2string(d[0])
- if dn in devdict:
- dn=devdict[dn]
- gplist.append((p,col,dn))
- if (len(d)>2):
- print("->",d[2])
- prop=getProperties(d[2:],voc_marker[i])
- tline1=tline1+id2string(d[2])
- for p in prop:
- tline2=tline2+p+"\t"
- tline1=tline1+"\t"
- col=col+1
- dn=id2string(d[2])
- if dn in devdict:
- dn=devdict[dn]
- gplist.append((p,col,dn))
- i=i+1
-
-#if os.path.exists("log22.txt"):
-# lt = time.localtime()
-# ts=time.strftime("%Y%m%d%H%M%S", lt)
-# os.rename("log22.txt","log22_"+ts+".txt")
-
-f=open("log22h.txt","a")
-f.write(tline1+"\n")
-f.write(tline2+"\n")
-f.close()
-print(tline1)
-print(tline2)
-
-while (1):
- lt = time.localtime()
- vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
- i=0
- for d in devlist:
- #print(d[0])
- vals=getValues(d,voc_marker[i])
- for v in vals:
- vline=vline+"%0.5f\t" % (v)
- if (len(d)>2):
- vals=getValues(d[2:],voc_marker[i])
- for v in vals:
- vline=vline+"%0.5f\t" % (v)
- i=i+1
- print(vline)
- f=open("log22.txt","a")
- f.write(vline.replace('.',',').replace('#','.')+"\n")
- #f.write(vline+"\n")
- f.close()
- gnuplot()
- time.sleep(90)
-
-
-
-
-id=[0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67]
-print("VDD\tVAD\tTemp\tHum\tR0\tVS\tCorr\tcm\tRS\tRSR0\tVOC1\tVOC2");
-print(owComStr(id,"85FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
-#print(owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF"))
-
-while(0):
- sbl=owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
- #owCom(id,[0x4E,0x00,0x0F],0)
- #owCom(id,[0xB4],0)
- #time.sleep(0.1)
- #owCom(id,[0x44],0)
- #time.sleep(0.1)
- #owCom(id,[0xB8],0)
- #sb=owCom(id,[0xBE,0x00],11)
- sb=sbl[4]
- VDD=(sb[5]+sb[6]*256)/100.0
- #owCom(id,[0x4E,0x00,0x00],0)
- #owCom(id,[0xB4],0)
- #time.sleep(0.1)
- #owCom(id,[0xB8],0)
- #sb=owCom(id,[0xBE,0x00],11)
- sb=sbl[7]
- VAD=(sb[5]+sb[6]*256)/100.0
- Temp=(sb[3]+sb[4]*256)/256.0
- #sb=owCom(id,[0xBE,0x03],11)
- sb=sbl[8]
- 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
- Hum=(VAD/VDD-0.16)/0.0062
- Hum=(Hum)/(1.0546-0.00216*(Temp))
- f=open("log.txt","a")
- print("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
- f.write("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f\n" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
- f.close()
- time.sleep(30)
-
-#cmd="owtools.exe usb1 DC 6705160084D9A326 BE00FFFFFFFFFFFFFFFFFFFF"
-#print(owCom([0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67],[0xBE,0x00],11))
-
-
-
+++ /dev/null
-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
+++ /dev/null
-//============================================================================
-// Name : owtools.cpp
-// Author :
-// Version :
-// Copyright : Your copyright notice
-// Description : Hello World in C++, Ansi-style
-//============================================================================
-
-#include <iostream>
-#include <queue>
-using namespace std;
-extern "C" {
-#include <ownet.h>
-}
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-
-
-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, "DS2490-%s\0",s);
- //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;
-}
+++ /dev/null
-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
--- /dev/null
+#!/usr/bin/python\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
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+ res=[]\r
+ f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+ f.write("".join(map(chr, send)))\r
+ if (rc!=0):\r
+ res=map(ord,f.read(rc))\r
+ f.close()\r
+ return res\r
+ \r
+\r
+def crc8(arr):\r
+ lscrc=0x0;\r
+ for v in arr:\r
+ bit=1;\r
+ while bit<256:\r
+ if (v&bit)==bit:\r
+ lb=1\r
+ else:\r
+ lb=0\r
+ if (lscrc&1)!=lb:\r
+ lscrc=(lscrc>>1)^0x8c \r
+ else:\r
+ lscrc=(lscrc>>1)\r
+ bit=bit*2\r
+ return lscrc\r
+ \r
+def testnr(s):\r
+ for c in s.lower()[:]:\r
+ if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+ return False\r
+ return True\r
+ \r
+def addid(id,val):\r
+ for i in range(7):\r
+ id[i+1]=id[i+1]+val\r
+ if id[i+1]>254:\r
+ id[i+1]=id[i+1]-254\r
+ val=1\r
+ else:\r
+ return id\r
+ return id\r
+#\r
+\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in (l.split("\n")):\r
+ if len(g)>2:\r
+ if testnr(g[0:2]):\r
+ if (g[0:2]=="26"):\r
+ dl.append(g)\r
+ dc=dc+1\r
+ print dc,") ",g\r
+if dc==0:\r
+ print "No 26 1-Wire Device found"\r
+ exit(0)\r
+n=int(raw_input("No. of Device (28-Device will get automatically): "))\r
+n=n-1\r
+if (n>dc-1)or(n<0):\r
+ exit(0)\r
+s=dl[n]\r
+config=owcom(s,[0x85],17)\r
+print(config)\r
+s2="%02x-%02x%02x%02x%02x%02x%02x" % (config[9],config[15],config[14],config[13],config[12],config[11],config[10])\r
+print("Second Device: %s" %( s2))\r
+f=open("/sys/bus/w1/devices/%s/w1_slave" %(s2),"rb",0)\r
+res=f.read().split(" ")\r
+f.close()\r
+Press=((int(res[0],16)+int(res[1],16)*256)/16.0*3.2+700)\r
+owcom(s,[0x4E,0x00,0x01],0)\r
+owcom(s,[0x44],0)\r
+time.sleep(1)\r
+owcom(s,[0xB4],0)\r
+time.sleep(1)\r
+\r
+p=owcom(s,[0xBE,0x00],10)\r
+print (p)\r
+T=((p[1]+p[2]*256)/256.0)\r
+if (config[5]==8):\r
+ RH=((p[3]+p[4]*256)/100.0)\r
+if (config[5]==7):\r
+ RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); \r
+\r
+print("Temperatur: %f °C" %(T));\r
+print("Luftfeuchte: %f %%" %(RH));\r
+print("Druck (absolut): %f hPa" %(Press));\r
+h=float(raw_input("Höhe über Meerespiegel in m: "))\r
+P0=Press/((1-h/44330)**5.255)\r
+print("Druck (normalisiert): %f hPa" %(P0));\r
--- /dev/null
+#!/usr/bin/python\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
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+ res=[]\r
+ f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+ f.write("".join(map(chr, send)))\r
+ if (rc!=0):\r
+ res=map(ord,f.read(rc))\r
+ f.close()\r
+ return res\r
+ \r
+\r
+def crc8(arr):\r
+ lscrc=0x0;\r
+ for v in arr:\r
+ bit=1;\r
+ while bit<256:\r
+ if (v&bit)==bit:\r
+ lb=1\r
+ else:\r
+ lb=0\r
+ if (lscrc&1)!=lb:\r
+ lscrc=(lscrc>>1)^0x8c \r
+ else:\r
+ lscrc=(lscrc>>1)\r
+ bit=bit*2\r
+ return lscrc\r
+ \r
+def testnr(s):\r
+ for c in s.lower()[:]:\r
+ if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+ return False\r
+ return True\r
+ \r
+def addid(id,val):\r
+ for i in range(7):\r
+ id[i+1]=id[i+1]+val\r
+ if id[i+1]>254:\r
+ id[i+1]=id[i+1]-254\r
+ val=1\r
+ else:\r
+ return id\r
+ return id\r
+#\r
+\r
+\r
+\r
+#start search\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("-1")\r
+f.close() \r
+\r
+\r
+print "Open Hex File ...",\r
+fi=open(sys.argv[1],"r")\r
+data=[]\r
+for l in fi.readlines():\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ bc=int(l[1:3],16)\r
+ fw=int(l[3:7],16)\r
+ ty=int(l[7:9],16)\r
+ chsm=bc+(fw>>8)+(fw&0xFF)+ty\r
+ for i in range(bc):\r
+ p=9+(i*2)\r
+ d=int(l[p:p+2],16)\r
+ chsm=(chsm+d)&0xFF\r
+ data.append(d)\r
+ chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF\r
+ if (chsm!=0):\r
+ print "Error Checksum...."\r
+ exit()\r
+ #print bc,fw,ty,chsm\r
+fi.close()\r
+print\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in (l.split("\n")):\r
+ if len(g)>2:\r
+ if testnr(g[0:2]):\r
+ if (g[0:2]!="28"):\r
+ dl.append(g)\r
+ dc=dc+1\r
+ print dc,") ",g\r
+if dc==0:\r
+ print "No 1-Wire Device found"\r
+ exit(0)\r
+n=int(raw_input("No. of Device: "))\r
+n=n-1\r
+if (n>dc-1)or(n<0):\r
+ exit(0)\r
+s=dl[n]\r
+if (s!="a3-55aa55aa55aa"):\r
+ sys.stdout.write('Go to Flashmode....')\r
+ sys.stdout.flush()\r
+ owcom(s,[0x88],0)\r
+ owcom(s,[0x88],0)\r
+ owcom(s,[0x88],0)\r
+ for i in range (20):\r
+ l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+ dc=0\r
+ dl=[]\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ for g in (l.split("\n")):\r
+ if (g[0:15]=="a3-55aa55aa55aa"):\r
+ break\r
+ if (g[0:15]!="a3-55aa55aa55aa"):\r
+ time.sleep(1)\r
+ if (g[0:15]=="a3-55aa55aa55aa"):\r
+ print "found"\r
+ else:\r
+ print "ERROR Enter Flashmode!" \r
+ exit()\r
+ f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+ f.write(s)\r
+ f.close()\r
+ time.sleep(5)\r
+\r
+#stop search\r
+print("Disable Device Search (Wait 15s)")\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("0")\r
+f.close() \r
+time.sleep(15)\r
+\r
+s="a3-55aa55aa55aa"\r
+prog=data\r
+l=len(prog)\r
+if (l>7551):\r
+ print "Code to big ... Max 7552 Byte (118 Pages)"\r
+ exit()\r
+pages= l/64\r
+for i in range(64-(l%64)):\r
+ #print i\r
+ prog.append(0xFF)\r
+pages= len(prog)/64\r
+if (pages>118):\r
+ print "Code to big ... Max 7552 Byte (118 Pages)"\r
+ exit()\r
+\r
+\r
+print "Programm Page (of ", pages,")"\r
+ \r
+for i in range(pages):\r
+ sys.stdout.write("%i " % (i+1) )\r
+ sys.stdout.flush()\r
+\r
+ h=i*64;\r
+ hl=h&0xFF\r
+ hh=h>>8\r
+ #print hh, hl\r
+ mem=[hl,hh]+prog[h:h+64]\r
+ erroc=0\r
+ while (1):\r
+ owcom(s,[0x0F]+mem,0) \r
+ rmem=owcom(s,[0xAA],66)\r
+ if (rmem!=mem):\r
+ print rmem\r
+ erroc=erroc+1\r
+ if erroc>5:\r
+ print "WRITING ERROR ... "\r
+ exit()\r
+ continue\r
+ owcom(s,[0x55],0) \r
+ time.sleep(0.05)\r
+ owcom(s,[0xB8,hl,hh],0)\r
+ time.sleep(0.05)\r
+ rmem=owcom(s,[0xAA],66)\r
+ if (rmem!=mem):\r
+ print "error in flash"\r
+ print mem\r
+ print rmem\r
+ erroc=erroc+1\r
+ if erroc>5:\r
+ print "WRITING ERROR ... "\r
+ exit()\r
+ continue\r
+ #for v in rmem:\r
+ # print "%02X " % (v),\r
+ break\r
+print "\nReset AVR"\r
+owcom(s,[0x89],0)\r
+time.sleep(1)\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+f.write("a3-55aa55aa55aa")\r
+f.close() \r
+\r
+print("Enable Device Search")\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("-1")\r
+f.close() \r
+ \r
+ \r
+\r
+\r
+\r
+\r
+#mem=[0x00,0x2]\r
+#for i in range (64):\r
+# mem.append(i)\r
+#owcom(s,[0x0F]+mem,0)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#owcom(s,[0x55],0)\r
+#time.sleep(0.05)\r
+#owcom(s,[0xB8,0x00,0x02],0)\r
+#time.sleep(0.05)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#for v in rmem:\r
+# print "%02X " % (v)\r
+ \r
+\r
+ \r
--- /dev/null
+#!/usr/bin/python\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
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+ res=[]\r
+ f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+ f.write("".join(map(chr, send)))\r
+ if (rc!=0):\r
+ res=map(ord,f.read(rc))\r
+ f.close()\r
+ return res\r
+ \r
+\r
+def crc8(arr):\r
+ lscrc=0x0;\r
+ for v in arr:\r
+ bit=1;\r
+ while bit<256:\r
+ if (v&bit)==bit:\r
+ lb=1\r
+ else:\r
+ lb=0\r
+ if (lscrc&1)!=lb:\r
+ lscrc=(lscrc>>1)^0x8c \r
+ else:\r
+ lscrc=(lscrc>>1)\r
+ bit=bit*2\r
+ return lscrc\r
+ \r
+def testnr(s):\r
+ for c in s.lower()[:]:\r
+ if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+ return False\r
+ return True\r
+ \r
+def addid(id,val):\r
+ for i in range(7):\r
+ id[i+1]=id[i+1]+val\r
+ if id[i+1]>254:\r
+ id[i+1]=id[i+1]-254\r
+ val=1\r
+ else:\r
+ return id\r
+ return id\r
+#\r
+\r
+\r
+\r
+#start search\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("-1")\r
+f.close() \r
+\r
+\r
+print "Open Hex File ...",\r
+fi=open(sys.argv[1],"r")\r
+data=[]\r
+for l in fi.readlines():\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ bc=int(l[1:3],16)\r
+ fw=int(l[3:7],16)\r
+ ty=int(l[7:9],16)\r
+ chsm=bc+(fw>>8)+(fw&0xFF)+ty\r
+ for i in range(bc):\r
+ p=9+(i*2)\r
+ d=int(l[p:p+2],16)\r
+ chsm=(chsm+d)&0xFF\r
+ data.append(d)\r
+ chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF\r
+ if (chsm!=0):\r
+ print "Error Checksum...."\r
+ exit()\r
+ #print bc,fw,ty,chsm\r
+fi.close()\r
+print\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in (l.split("\n")):\r
+ if len(g)>2:\r
+ if testnr(g[0:2]):\r
+ if (g[0:2]!="28"):\r
+ dl.append(g)\r
+ dc=dc+1\r
+ print dc,") ",g\r
+if dc==0:\r
+ print "No 1-Wire Device found"\r
+ exit(0)\r
+n=int(raw_input("No. of Device: "))\r
+n=n-1\r
+if (n>dc-1)or(n<0):\r
+ exit(0)\r
+s=dl[n]\r
+if (s!="a3-55aa55aa55aa"):\r
+ sys.stdout.write('Go to Flashmode....')\r
+ sys.stdout.flush()\r
+ owcom(s,[0x88],0)\r
+ owcom(s,[0x88],0)\r
+ owcom(s,[0x88],0)\r
+ for i in range (20):\r
+ l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+ dc=0\r
+ dl=[]\r
+ sys.stdout.write(".")\r
+ sys.stdout.flush()\r
+ for g in (l.split("\n")):\r
+ if (g[0:15]=="a3-55aa55aa55aa"):\r
+ break\r
+ if (g[0:15]!="a3-55aa55aa55aa"):\r
+ time.sleep(1)\r
+ if (g[0:15]=="a3-55aa55aa55aa"):\r
+ print "found"\r
+ else:\r
+ print "ERROR Enter Flashmode!" \r
+ exit()\r
+ f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+ f.write(s)\r
+ f.close()\r
+ time.sleep(5)\r
+\r
+#stop search\r
+print("Disable Device Search (Wait 15s)")\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("0")\r
+f.close() \r
+time.sleep(15)\r
+\r
+s="a3-55aa55aa55aa"\r
+prog=data\r
+l=len(prog)\r
+if (l>7551):\r
+ print "Code to big ... Max 7552 Byte (118 Pages)"\r
+ exit()\r
+pages= l/64\r
+for i in range(64-(l%64)):\r
+ #print i\r
+ prog.append(0xFF)\r
+pages= len(prog)/64\r
+if (pages>118):\r
+ print "Code to big ... Max 7552 Byte (118 Pages)"\r
+ exit()\r
+\r
+\r
+print "Programm Page (of ", pages,")"\r
+ \r
+for i in range(pages):\r
+ sys.stdout.write("%i " % (i+1) )\r
+ sys.stdout.flush()\r
+\r
+ h=i*64;\r
+ hl=h&0xFF\r
+ hh=h>>8\r
+ #print hh, hl\r
+ mem=[hl,hh]+prog[h:h+64]\r
+ erroc=0\r
+ while (1):\r
+ owcom(s,[0x0F]+mem,0) \r
+ rmem=owcom(s,[0xAA],66)\r
+ if (rmem!=mem):\r
+ print rmem\r
+ erroc=erroc+1\r
+ if erroc>5:\r
+ print "WRITING ERROR ... "\r
+ exit()\r
+ continue\r
+ #for v in rmem:\r
+ # print "%02X " % (v),\r
+ break\r
+print "\nReset AVR"\r
+owcom(s,[0x89],0)\r
+time.sleep(1)\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)\r
+f.write("a3-55aa55aa55aa")\r
+f.close() \r
+\r
+print("Enable Device Search")\r
+f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)\r
+f.write("-1")\r
+f.close() \r
+ \r
+ \r
+\r
+\r
+\r
+\r
+#mem=[0x00,0x2]\r
+#for i in range (64):\r
+# mem.append(i)\r
+#owcom(s,[0x0F]+mem,0)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#owcom(s,[0x55],0)\r
+#time.sleep(0.05)\r
+#owcom(s,[0xB8,0x00,0x02],0)\r
+#time.sleep(0.05)\r
+#rmem=owcom(s,[0xAA],70)\r
+#print rmem\r
+#for v in rmem:\r
+# print "%02X " % (v)\r
+ \r
+\r
+ \r
--- /dev/null
+#!/usr/bin/python\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
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+ res=[]\r
+ f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+ f.write("".join(map(chr, send)))\r
+ if (rc!=0):\r
+ res=map(ord,f.read(rc))\r
+ f.close()\r
+ return res\r
+ \r
+\r
+def crc8(arr):\r
+ lscrc=0x0;\r
+ for v in arr:\r
+ bit=1;\r
+ while bit<256:\r
+ if (v&bit)==bit:\r
+ lb=1\r
+ else:\r
+ lb=0\r
+ if (lscrc&1)!=lb:\r
+ lscrc=(lscrc>>1)^0x8c \r
+ else:\r
+ lscrc=(lscrc>>1)\r
+ bit=bit*2\r
+ return lscrc\r
+ \r
+def testnr(s):\r
+ for c in s.lower()[:]:\r
+ if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+ return False\r
+ return True\r
+ \r
+def addid(id,val):\r
+ for i in range(7):\r
+ id[i+1]=id[i+1]+val\r
+ if id[i+1]>254:\r
+ id[i+1]=id[i+1]-254\r
+ val=1\r
+ else:\r
+ return id\r
+ return id\r
+#\r
+\r
+def readDS18B20(s):\r
+ f=open("/sys/bus/w1/devices/%s/w1_slave" %(s),"rb",0)\r
+ res=f.read().split(" ")\r
+ f.close()\r
+ T=((int(res[0],16)+int(res[1],16)*256)/16.0)\r
+ print("Temperatur: %f °C" %(T)); \r
+\r
+def readDS2438(s):\r
+ owcom(s,[0x4E,0x00,0x01],0)\r
+ owcom(s,[0x44],0)\r
+ time.sleep(1)\r
+ owcom(s,[0xB4],0)\r
+ time.sleep(1)\r
+ owcom(s,[0xB8,0x00],0)\r
+ crc=1\r
+ while crc:\r
+ p=owcom(s,[0xBE,0x00],9)\r
+ crc=crc8(p)\r
+ #print (p)\r
+ T=((p[1]+p[2]*256)/256.0)\r
+ RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); \r
+ print("Temperatur: %f °C" %(T));\r
+ print("Luftfeuchte: %f %%" %(RH));\r
+ \r
+\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in (l.split("\n")):\r
+ if len(g)>2:\r
+ if testnr(g[0:2]):\r
+ if (g[0:2]=="26"):\r
+ print dc,") ",g\r
+ readDS2438(g)\r
+ dl.append(g)\r
+ dc=dc+1\r
+ if (g[0:2]=="28"):\r
+ print dc,") ",g\r
+ readDS18B20(g)\r
+ dl.append(g)\r
+ dc=dc+1\r
+++ /dev/null
-\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