X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=DS2438_DHT22%2FDS2438_DHT22.c;h=a182bed90e65f679873c0c821c56f8b44a4fd979;hp=6d4a5a0203567fabbf5a6c39ec650432c514bef0;hb=0f5b4d994ac87afdd294f6fc79692bcf92e337de;hpb=c612a6c03106176eb24430e254ea8a1dfd8e1343 diff --git a/DS2438_DHT22/DS2438_DHT22.c b/DS2438_DHT22/DS2438_DHT22.c index 6d4a5a0..a182bed 100644 --- a/DS2438_DHT22/DS2438_DHT22.c +++ b/DS2438_DHT22/DS2438_DHT22.c @@ -32,19 +32,21 @@ #define F_CPU 8000000UL -//#define FP_CALC #include #include #include #include #include +#include -extern void OWINIT(); +extern void OWINIT(); +extern void EXTERN_SLEEP(); -uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/ +uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/ uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - + + extern uint8_t mode; extern uint8_t gcontrol; @@ -55,11 +57,8 @@ volatile uint8_t wdcounter; typedef union { -#if defined(__AVR_ATtiny25__) - volatile uint8_t bytes[16]; -#else + volatile uint8_t bytes[64]; -#endif struct { uint8_t status; //1 int16_t temp; //2 @@ -68,8 +67,6 @@ typedef union { 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 @@ -77,27 +74,15 @@ typedef union { uint8_t page6[8]; //49 uint8_t page7[8]; //57 //uint8_t crc; //65 -#endif }; } pack_t; volatile pack_t pack; -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - -#define DDR_SENSOR DDRB -#define PORT_SENSOR PORTB -#define PIN_SENSOR PINB -#define SENSOR PB4 -#endif -#if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) #define DDR_SENSOR DDRA #define PORT_SENSOR PORTA #define PIN_SENSOR PINA #define SENSOR PINA2 -#endif - - #define SENSOR_sda_out DDR_SENSOR |= (1 << SENSOR) #define SENSOR_sda_in DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup @@ -112,53 +97,64 @@ volatile uint16_t am2302_hum; uint8_t am_wait(uint8_t _time,uint8_t _signal){ TCNT1=0; while(TCNT1==0); - if (_signal) - while((SENSOR_is_hi)&&(TCNT1<_time)) {} + if (_signal) + while((SENSOR_is_hi)&&(TCNT1<_time)) {} else - while((SENSOR_is_low)&&(TCNT1<_time)) {} - - if (TCNT1>=_time) {return 1;} + while((SENSOR_is_low)&&(TCNT1<_time)) {} + + if (TCNT1>=_time) {return 1;} return 0; } -volatile uint8_t am2302_mode=0; +volatile uint8_t am2302_mode=0; volatile uint8_t timeout=0; + + + +uint8_t userRegister[1]; +int16_t sRH,sT; +volatile double temperatureC,humidityRH; +volatile double l; + #if defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__) || defined(__AVR_ATtiny84A__) ISR(WATCHDOG_vect) { -#else + #else ISR(WDT_vect) { -#endif - sleep_disable(); // Disable Sleep on Wakeup - am2302_mode++; + #endif + 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 - } - - -uint8_t am2302_1() { +int testSW(void) { + uint8_t r; + DDRB&=~(1< 5V also all *5 + config_info[5]=7; + } + else { + + lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]); + config_info[5]=12; + } + lam2302_temp=lam2302_temp*25.6; rSREG=SREG; cli(); am2302_hum=lam2302_hum; @@ -231,179 +215,87 @@ uint8_t am2302_1() { } -uint8_t am2302_2() { //4mhz - int16_t lam2302_temp; - uint16_t lam2302_hum; - uint8_t rSREG; - uint8_t sensor_data[5]; - #if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - TCCR1=(1< bit=1 else bit=0 - sensor_byte |= 1; - if (am_wait(45,1)) return 6;// 30us - 75us = 45us - } - } - sensor_data[i] = sensor_byte; - } - - // checksum - if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4]) - { - // debug output - //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff )); - PORTB&=~(1<2) { + wdcounter=0; + SENSON + } + gcontrol=0; + } + if (wdcounter==2) { + err=am2302(); + if (err!=0) { + pack.page3[pn]=err; + pn=pn+1;if (pn>31) pn=1; + } + SENSOFF + wdcounter=3; + } + if (wdcounter>=16) { + wdcounter=0; + SENSON + } + + - - uint8_t i; - uint8_t err; -#if defined(__AVR_ATtiny25__) - for(i=0;i<16;i++) pack.bytes[i]=0; -#else - uint8_t pn=1; - for(i=0;i<64;i++) pack.bytes[i]=0; -#endif - //pack.bytes[0]=1; - //pack.bytes[1]=2; - SENSON - _delay_ms(4000); - err =am2302_1(); - sei(); - while(1) { - alarmflag=1; - if (am2302_mode==2) { - err=am2302_1(); - if (err!=0) { -#if defined(__AVR_ATtiny25__) -#else - pack.page3[pn]=err; - pn=pn+1;if (pn>31) pn=1; -#endif + if (((TIMSK0 & (1<=8) { - am2302_mode=0; - SENSON - } -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1<