- New Device compinations
[owSlave2.git] / DS18B20_BMP280_DS2438_SHT / DS18B20_DS2438.c
index 4aec172..b4b62d0 100644 (file)
@@ -1,4 +1,3 @@
-
 // Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
 // All rights reserved.
 //
@@ -44,7 +43,7 @@
 
 
 extern void OWINIT();
-
+extern void EXTERN_SLEEP();
 
 
 uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
@@ -60,7 +59,7 @@ extern uint8_t mode;
 extern uint8_t gcontrol;
 extern uint8_t reset_indicator;
 extern uint8_t alarmflag;
-volatile uint8_t wdcounter;
+volatile uint8_t wdcounter=3;
 
 
 #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
@@ -134,6 +133,26 @@ volatile int16_t am2302_temp;
 volatile uint16_t am2302_hum;
 
 
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+       __asm__ __volatile__ ("nop");
+       PORTB|=(1<<PORTB0); //Pullup
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       r=PINB&(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       PORTB&=~(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+       
+       
+}
+
 uint8_t userRegister[1];
 int16_t sRH,sT;
 volatile double temperatureC,humidityRH;
@@ -143,6 +162,10 @@ volatile double l;
 
 int main(void){
     PRR|=(1<<PRADC);  // adc for save Power
+       PORTA=0xFF;
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+       
        pack1.temp=0x0550;
        pack1.config=0x7F;
        pack1.TH=75;
@@ -154,12 +177,21 @@ int main(void){
        PORTB=0xFF;
        OWINIT();
 
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
        MCUCR &=~(1<<PUD); //All Pins Pullup...
        MCUCR |=(1<<BODS);
 
+       
        WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
        WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~1 seconds
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+       if (testSW()) {
+               config_info2[5]=8;
+               }else{
+               config_info2[5]=7;
+       }
+       
 
        MCUSR=0;
        USI_TWI_Master_Initialise();
@@ -179,7 +211,11 @@ int main(void){
        gcontrol=1;
        sei();
     while(1)   {
-               if (wdcounter>0) {
+               if ((gcontrol==2)||(gcontrol==3)) {
+                       wdcounter=3;
+                       gcontrol=0;
+               }               
+               if (wdcounter>3) {
                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
@@ -207,12 +243,9 @@ int main(void){
                                //pack.temp++;
                                alarmflag=af;
                                sei();
-                               gcontrol=0;
-               }
-               if ((gcontrol==2)||(gcontrol==3)) {
-                       gcontrol=0;
-                       
+                               EXTERN_SLEEP(); 
                }
+               
 
                
 #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)