#include "../common/I2C/USI_TWI_Master.h"
#include "../common/I2C/SHT2x.h"
#include "../common/I2C/BMP280.h"
-
+#include "../common/calibr.h"
extern void OWINIT();
extern void EXTERN_SLEEP();
#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) {
+ #else
+ ISR(WDT_vect) {
+
#endif
//sleep_disable(); // Disable Sleep on Wakeup
wdcounter++;
ACSR|=(1<<ACD); //Disable Comparator
ADCSRB|=(1<<ACME); //Disable Analog multiplexer
MCUCR &=~(1<<PUD); //All Pins Pullup...
- MCUCR |=(1<<BODS);
+ //MCUCR &=~(1<<BODS);
WDTCSR |= ((1<<WDCE) ); // Enable the WD Change Bit//| (1<<WDE)
MCUSR=0;
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);
+ //SHT2x_MeasurePoll(HUMIDITY, &sRH);
// --- measure temperature with "Polling Mode" (no hold master) ---
- SHT2x_MeasurePoll(TEMP, &sT);
+ //SHT2x_MeasurePoll(TEMP, &sT);
//-- calculate humidity and temperature --
- temperatureC = SHT2x_CalcTemperatureC(sT);
- humidityRH = SHT2x_CalcRH(sRH);
-
+ //temperatureC = SHT2x_CalcTemperatureC(sT);
+ //humidityRH = SHT2x_CalcRH(sRH);
+ bmp280Init();
gcontrol=1;
sei();
while(1) {
- if ((gcontrol==2)||(gcontrol==3)) {
+ if (gcontrol) {
wdcounter=3;
- gcontrol=0;
- }
- if (wdcounter>3) {
+
+ }
+
+ if (wdcounter>2) {
SHT2x_MeasurePoll(HUMIDITY, &sRH);
// --- measure temperature with "Polling Mode" (no hold master) ---
SHT2x_MeasurePoll(TEMP, &sT);
//-- calculate humidity and temperature --
- temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
- humidityRH = SHT2x_CalcRH(sRH)*10.0;
- double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
- am2302_hum=0.318*hhum +76.0;
- am2302_temp=temperatureC*25.6;
+ temperatureC = SHT2x_CalcTemperatureC(sT);
+ humidityRH = SHT2x_CalcRH(sRH);
+ humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;
+ temperatureC=temperatureC*10.0-4.5;
+ if (testSW()) {
+ am2302_hum= humidityRH*10.0;
+ am2302_temp=temperatureC*25.6;
+ am2302_temp=am2302_temp-20;
+ config_info2[5]=8;
+
+ }else{
+
+ double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+ //am2302_hum=0.318*hhum +76.0;
+ am2302_hum=0.31*hhum +80;
+ am2302_temp=temperatureC*25.6;
+ am2302_temp=am2302_temp-20;
+ config_info2[5]=7;
+ }
wdcounter=0;
}
//pack.temp++;
alarmflag=af;
sei();
+ gcontrol=0;
EXTERN_SLEEP();
}
-
+ if (gcontrol) {
+ gcontrol=0;
+
+ }
#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)