#define DELAY_FAKTOR 13 // setup clock-frequency #define ACK 1 // define acknowledge #define NAK 0 // define not-acknowledge typedef unsigned char byte; volatile unsigned int variable[MAX_VAR]; unsigned char rh_low; unsigned char rh_high; unsigned char temp_low; unsigned char temp_high; unsigned char checksum_03; unsigned int rh_ee03= 0; unsigned int temp_ee03= 0; float rh = 0; float temperature = 0; unsigned char status, dummy; char check_ack(void); void send_ack(void); void send_nak(void); void E2Bus_start(void); // send start condition void E2Bus_stop(void); // send stop condition void E2Bus_send(unsigned char); void set_SDA(void); void clear_SDA(void); unsigned read_SDA(void); void set_SCL(void); void clear_SCL(void); unsigned char E2Bus_read(void); // read one byte from E2-Bus //void delayn(unsigned int value); void windrichtung(void); // Floh: // Variablen-Array // zum Abspeichern verschiedener Werte // und zum Einfügen in die Webseite %VA@00 bis %VA@19 // VA4-7 -> Analogwert von PORTA4-7 // VA9 -> Manueller Betrieb ein/aus // VA10-13 -> Schalttemperaturen // VA14-17 -> Schaltzeiten ein/aus hh,mm,hh,mm // VA18 -> Schaltwert analog // VA-Ende -> Counter unsigned int var_array[MAX_VAR_ARRAY] = {10,50,30,0,0,0,0,0,0,0,15,15,15,15,12,0,12,0,750,0}; // Floh: // Die Uhrzeit wird zentral in main.c berechnet (s.u.) // Die anderen Programmteile lesen nur noch hh,mm,ss aus. // -> httpd.h/c, cmd.h/c' unsigned char hh; unsigned char mm; unsigned char ss; char str[13]; char wstr[20]; char tempstr[3]; char feustr[3]; float adc_koma[5]; unsigned int adc_int, ssz, messzeit; unsigned char ssmerk; unsigned int z1, z1kmh, merken=0, off, ssmerke; int16_t ow_array[12] = {200,200,200,200,0,0,0,0,0,0,0,0}; // 4 Sensoren // Floh: // Das periodische Auslesen der 1-Wire-Sensoren erfolgt in main.c (s.u.) // Die anderen Programmteile lesen nur noch "ow_array" aus. // -> httpd.h/c, cmd.h/c // Floh // Schaltbedingungen uint8_t schalten; unsigned int off; unsigned int off; void windrichtung(void) { unsigned int admerk; admerk = var_array[4]+0x0F; switch(admerk&0x1E0) /* &0xF0) */ { case 0x00:str[0+off] = 'N';str[1+off] = ' ';str[2+off] = ' ';break; case 0x20:str[0+off] = 'N';str[1+off] = 'N';str[2+off] = 'O';break; case 0x40:str[0+off] = 'N';str[1+off] = 'O';str[2+off] = ' ';break; case 0x60:str[0+off] = 'O';str[1+off] = 'N';str[2+off] = 'O';break; case 0x80:str[0+off] = 'O';str[1+off] = ' ';str[2+off] = ' ';break; case 0xA0:str[0+off] = 'O';str[1+off] = 'S';str[2+off] = 'O';break; case 0xC0:str[0+off] = 'S';str[1+off] = 'O';str[2+off] = ' ';break; case 0xE0:str[0+off] = 'S';str[1+off] = 'S';str[2+off] = 'O';break; case 0x100:str[0+off] = 'S';str[1+off] = ' ';str[2+off] = ' ';break; case 0x120:str[0+off] = 'S';str[1+off] = 'S';str[2+off] = 'W';break; case 0x140:str[0+off] = 'S';str[1+off] = 'W';str[2+off] = ' ';break; case 0x160:str[0+off] = 'W';str[1+off] = 'S';str[2+off] = 'W';break; case 0x180:str[0+off] = 'W';str[1+off] = ' ';str[2+off] = ' ';break; case 0x1A0:str[0+off] = 'W';str[1+off] = 'N';str[2+off] = 'W';break; case 0x1C0:str[0+off] = 'N';str[1+off] = 'W';str[2+off] = ' ';break; case 0x1E0:str[0+off] = 'N';str[1+off] = 'N';str[2+off] = 'W';break; } ADCSRA&=~(1<calculate temperature temperature=((float)temp_ee03/100) - 273.15; // overwrite default (error) value } } E2Bus_stop(); } dtostrf(temperature,2,1,tempstr); return temperature; } float RH_read(void) { rh = -1; // default value (error code) E2Bus_start(); E2Bus_send(0x81); // MW1-low request if (check_ack()==ACK) { rh_low = E2Bus_read(); send_ack(); checksum_03 = E2Bus_read(); send_nak(); // terminate communication E2Bus_stop(); if (((0x81 + rh_low) % 256) == checksum_03) // checksum OK? { E2Bus_start(); E2Bus_send(0x91); // MW1-high request check_ack(); rh_high = E2Bus_read(); send_ack(); checksum_03 = E2Bus_read(); send_nak(); // terminate communication E2Bus_stop(); if (((0x91 + rh_high) % 256) == checksum_03) // checksum OK? { rh_ee03=rh_low+256*(unsigned int)rh_high; // yes-> calculate humidity value rh=(float)rh_ee03/100; // overwrite default (error) value } } E2Bus_stop(); } dtostrf(rh,2,1,feustr); rh =0x30; return rh; } unsigned char EE03_status(void) { unsigned char stat_ee03; E2Bus_start(); // start condition for E2-Bus E2Bus_send(0x71); // main command for STATUS request if (check_ack()==ACK) { stat_ee03 = E2Bus_read(); // read status byte send_ack(); checksum_03 = E2Bus_read(); // read checksum send_nak(); // send NAK ... E2Bus_stop(); // ... and stop condition to terminate if (((stat_ee03 + 0x71) % 256) == checksum_03) // checksum OK? return stat_ee03; } return 0xFF; // in error case return 0xFF } void E2Bus_start(void) // send Start condition to E2 Interface { set_SDA(); set_SCL(); _delay_us(30*DELAY_FAKTOR); clear_SDA(); _delay_us(30*DELAY_FAKTOR); } /*-------------------------------------------------------------------------*/ void E2Bus_stop(void) // send Stop condition to E2 Interface { clear_SCL(); _delay_us(20*DELAY_FAKTOR); clear_SDA(); _delay_us(20*DELAY_FAKTOR); set_SCL(); _delay_us(20*DELAY_FAKTOR); set_SDA(); _delay_us(20*DELAY_FAKTOR); } /*-------------------------------------------------------------------------*/ void E2Bus_send(unsigned char value) // send Byte to E2 Interface { unsigned char i; unsigned char maske = 0x80; for (i=8;i>0;i--) { clear_SCL(); _delay_us(10*DELAY_FAKTOR); if ((value & maske) != 0) { set_SDA(); } else { clear_SDA(); } _delay_us(20*DELAY_FAKTOR); set_SCL(); maske >>= 1; _delay_us(30*DELAY_FAKTOR); clear_SCL(); } set_SDA(); } /*-------------------------------------------------------------------------*/ unsigned char E2Bus_read(void) // read Byte from E2 Interface { unsigned char data_in = 0x00; unsigned char maske = 0x80; for (maske=0x80;maske>0;maske >>=1) { clear_SCL(); _delay_us(30*DELAY_FAKTOR); set_SCL(); _delay_us(15*DELAY_FAKTOR); if (read_SDA()) { data_in |= maske; } _delay_us(15*DELAY_FAKTOR); clear_SCL(); } return data_in; } /*-------------------------------------------------------------------------*/ char check_ack(void) // check for acknowledge { unsigned input; _delay_us(30*DELAY_FAKTOR); set_SCL(); _delay_us(15*DELAY_FAKTOR); input = read_SDA(); _delay_us(15*DELAY_FAKTOR); if(input == 1) return NAK; else return ACK; } /*-------------------------------------------------------------------------*/ void send_ack(void) // send acknowledge { _delay_us(15*DELAY_FAKTOR); clear_SDA(); _delay_us(15*DELAY_FAKTOR); set_SCL(); _delay_us(30*DELAY_FAKTOR); set_SDA(); } /*-------------------------------------------------------------------------*/ void send_nak(void) // send NOT-acknowledge { _delay_us(15*DELAY_FAKTOR); clear_SDA(); _delay_us(15*DELAY_FAKTOR); set_SCL(); _delay_us(30*DELAY_FAKTOR); set_SCL(); } /*-------------------------------------------------------------------------*/ /* void delayn(unsigned int value) // delay- routine { while (--value != 0); } */ /*-------------------------------------------------------------------------*/ // adapt this code for your target processor !!! void set_SDA(void) { SDA = 1; } // set port-pin (SDA) void clear_SDA(void) { SDA = 0; } // clear port-pin (SDA) unsigned read_SDA(void) {return SDA;} // read SDA-pin status void set_SCL(void) { SCL = 1; } // set port-pin (SCL) void clear_SCL(void) { SCL = 0; } // clear port-pin (SCL) //---------------------------------------------------------------------------- // Hier startet das Hauptprogramm // ****************************** int main(void) { //Konfiguration der Ausgänge bzw. Eingänge //definition erfolgt in der config.h DDRA = 0x0E; //DDRA = OUTA; //DDRC = OUTC; // -> LCD // DDRC = 0xFF; DDRC = OUTC; DDRD = OUTD; // PORTC = 0xFF; // Floh: // Pullups einschalten PORTA=0x0F; // PORTA = (1 << PORTA0) | (1 << PORTA1) | (1 << PORTA2) | (1 << PORTA3) | (1 << PORTA4) | (1 << PORTA5) | (1 << PORTA6); unsigned long a; usart_init(BAUDRATE); // setup the UART stack_init(); httpd_init(); telnetd_init(); ETH_INT_ENABLE; sei(); #if USE_NTP ntp_init(); ntp_request(); #endif //USE_NTP wol_init(); dummy = EE03_status(); //Hauptschlfeife // ************* while(1) { if(messzeit+1 <= ssz) {TW_START; TW_STATUS; erich = ~erich; temperature = Temp_read(); rh = RH_read(); // read humidity // temperature = Temp_read(); // read temperature status = EE03_status(); // read status; start a new measurement analyse status and measured values messzeit = ssz; } . . . . . . . }