/* verbose output rom-search follows read-scratchpad in one loop */
uint8_t DS18X20_read_meas_all_verbose( void )
{
	uint8_t id[OW_ROMCODE_SIZE], sp[DS18X20_SP_SIZE], diff;
	uint8_t i;
	uint16_t meas;
	int16_t decicelsius;
	char s[10];
	uint8_t subzero, cel, cel_frac_bits;

	for( diff = OW_SEARCH_FIRST; diff != OW_LAST_DEVICE; )
	{
		diff = ow_rom_search( diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
			uart_puts_P( "No Sensor found\r" );
			return OW_PRESENCE_ERR; // <--- early exit!
		}

		if( diff == OW_DATA_ERR ) {
			uart_puts_P( "Bus Error\r" );
			return OW_DATA_ERR;     // <--- early exit!
		}

		DS18X20_show_id_uart( id, OW_ROMCODE_SIZE );

		if( id[0] == DS18B20_FAMILY_CODE || id[0] == DS18S20_FAMILY_CODE ||
		    id[0] == DS1822_FAMILY_CODE ) {
			// temperature sensor

			uart_putc ('\r');

			ow_byte_wr( DS18X20_READ );           // read command

			for ( i=0 ; i< DS18X20_SP_SIZE; i++ ) {
				sp[i]=ow_byte_rd();
			}

			show_sp_uart( sp, DS18X20_SP_SIZE );

			if ( crc8( &sp[0], DS18X20_SP_SIZE ) ) {
				uart_puts_P( " CRC FAIL " );
			} else {
				uart_puts_P( " CRC O.K. " );
			}
			uart_putc ('\r');

			meas = sp[0]; // LSB Temp. from Scrachpad-Data
			meas |= (uint16_t) (sp[1] << 8); // MSB

			uart_puts_P( " T_raw=");
			uart_puthex_byte( (uint8_t)(meas >> 8) );
			uart_puthex_byte( (uint8_t)meas );
			uart_puts_P( " " );

			if( id[0] == DS18S20_FAMILY_CODE ) { // 18S20
				uart_puts_P( "S20/09" );
			}
			else if ( id[0] == DS18B20_FAMILY_CODE ||
			          id[0] == DS1822_FAMILY_CODE ) { // 18B20 or 1822
				i=sp[DS18B20_CONF_REG];
				if ( (i & DS18B20_12_BIT) == DS18B20_12_BIT ) {
					uart_puts_P( "B20/12" );
				}
				else if ( (i & DS18B20_11_BIT) == DS18B20_11_BIT ) {
					uart_puts_P( "B20/11" );
				}
				else if ( (i & DS18B20_10_BIT) == DS18B20_10_BIT ) {
					uart_puts_P( " B20/10 " );
				}
				else { // if ( (i & DS18B20_9_BIT) == DS18B20_9_BIT ) {
					uart_puts_P( "B20/09" );
				}
			}
			uart_puts_P(" ");

			DS18X20_meas_to_cel( id[0], sp, &subzero, &cel, &cel_frac_bits );
			DS18X20_uart_put_temp( subzero, cel, cel_frac_bits );

			decicelsius = DS18X20_raw_to_decicelsius( id[0], sp );
			if ( decicelsius == DS18X20_INVALID_DECICELSIUS ) {
				uart_puts_P("* INVALID *");
			} else {
				uart_puts_P(" conv: ");
				uart_put_int(decicelsius);
				uart_puts_P(" deci°C ");
				DS18X20_format_from_decicelsius( decicelsius, s, 10 );
				uart_puts_P(" fmt: ");
				uart_puts(s);
				uart_puts_P(" °C ");
			}

			uart_puts("\r");

		} // if meas-sensor

	} // loop all sensors
Example #2
0
int main( void )
{
    uint8_t nSensors, i;
    int16_t decicelsius;
    uint8_t error;

    uart_init((UART_BAUD_SELECT((BAUD),F_CPU)));

#ifndef OW_ONE_BUS
    ow_set_bus(&PINA,&PORTA,&DDRA,PA6);
#endif

    sei();

    uart_puts_P( NEWLINESTR "DS18X20 1-Wire-Reader Demo by Martin Thomas" NEWLINESTR );
    uart_puts_P(            "-------------------------------------------" );

    nSensors = search_sensors();
    uart_put_int( (int)nSensors );
    uart_puts_P( " DS18X20 Sensor(s) available:" NEWLINESTR );

#if DS18X20_VERBOSE
    for (i = 0; i < nSensors; i++ ) {
        uart_puts_P("# in Bus :");
        uart_put_int( (int)i + 1);
        uart_puts_P(" : ");
        DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
        uart_puts_P( NEWLINESTR );
    }
#endif

    for ( i = 0; i < nSensors; i++ ) {
        uart_puts_P( "Sensor# " );
        uart_put_int( (int)i+1 );
        uart_puts_P( " is a " );
        if ( gSensorIDs[i][0] == DS18S20_FAMILY_CODE ) {
            uart_puts_P( "DS18S20/DS1820" );
        } else if ( gSensorIDs[i][0] == DS1822_FAMILY_CODE ) {
            uart_puts_P( "DS1822" );
        }
        else {
            uart_puts_P( "DS18B20" );
        }
        uart_puts_P( " which is " );
        if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) == DS18X20_POWER_PARASITE ) {
            uart_puts_P( "parasite" );
        } else {
            uart_puts_P( "externally" );
        }
        uart_puts_P( " powered" NEWLINESTR );
    }

#if DS18X20_EEPROMSUPPORT
    if ( nSensors > 0 ) {
        eeprom_test();
    }
#endif

    if ( nSensors == 1 ) {
        uart_puts_P( NEWLINESTR "There is only one sensor "
                     "-> Demo of \"DS18X20_read_decicelsius_single\":" NEWLINESTR );
        i = gSensorIDs[0][0]; // family-code for conversion-routine
        DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
        _delay_ms( DS18B20_TCONV_12BIT );
        DS18X20_read_decicelsius_single( i, &decicelsius );
        uart_put_temp( decicelsius );
        uart_puts_P( NEWLINESTR );
    }


    for(;;) {   // main loop

        error = 0;

        if ( nSensors == 0 ) {
            error++;
        }

        uart_puts_P( NEWLINESTR "Convert_T and Read Sensor by Sensor (reverse order)" NEWLINESTR );
        for ( i = nSensors; i > 0; i-- ) {
            if ( DS18X20_start_meas( DS18X20_POWER_PARASITE,
                                     &gSensorIDs[i-1][0] ) == DS18X20_OK ) {
                _delay_ms( DS18B20_TCONV_12BIT );
                uart_puts_P( "Sensor# " );
                uart_put_int( (int) i );
                uart_puts_P(" = ");
                if ( DS18X20_read_decicelsius( &gSensorIDs[i-1][0], &decicelsius)
                        == DS18X20_OK ) {
                    uart_put_temp( decicelsius );
                } else {
                    uart_puts_P( "CRC Error (lost connection?)" );
                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
            else {
                uart_puts_P( "Start meas. failed (short circuit?)" );
                error++;
            }
        }

        uart_puts_P( NEWLINESTR "Convert_T for all Sensors and Read Sensor by Sensor" NEWLINESTR );
        if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL )
                == DS18X20_OK) {
            _delay_ms( DS18B20_TCONV_12BIT );
            for ( i = 0; i < nSensors; i++ ) {
                uart_puts_P( "Sensor# " );
                uart_put_int( (int)i + 1 );
                uart_puts_P(" = ");
                if ( DS18X20_read_decicelsius( &gSensorIDs[i][0], &decicelsius )
                        == DS18X20_OK ) {
                    uart_put_temp( decicelsius );
                }
                else {
                    uart_puts_P( "CRC Error (lost connection?)" );
                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
#if DS18X20_MAX_RESOLUTION
            int32_t temp_eminus4;
            for ( i = 0; i < nSensors; i++ ) {
                uart_puts_P( "Sensor# " );
                uart_put_int( i+1 );
                uart_puts_P(" = ");
                if ( DS18X20_read_maxres( &gSensorIDs[i][0], &temp_eminus4 )
                        == DS18X20_OK ) {
                    uart_put_temp_maxres( temp_eminus4 );
                }
                else {
                    uart_puts_P( "CRC Error (lost connection?)" );


                    error++;
                }
                uart_puts_P( NEWLINESTR );
            }
#endif
        }
        else {
            uart_puts_P( "Start meas. failed (short circuit?)" );
            error++;
        }


#if DS18X20_VERBOSE
        // all devices:
        uart_puts_P( NEWLINESTR "Verbose output" NEWLINESTR );
        DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
        _delay_ms( DS18B20_TCONV_12BIT );
        DS18X20_read_meas_all_verbose();
#endif

        if ( error ) {
            uart_puts_P( "*** problems - rescanning bus ..." );
            nSensors = search_sensors();
            uart_put_int( (int) nSensors );
            uart_puts_P( " DS18X20 Sensor(s) available" NEWLINESTR );
            error = 0;
        }

        _delay_ms(3000);
    }
}
Example #3
0
/* verbose output rom-search follows read-scratchpad in one loop */
uint8_t DS18X20_read_meas_all_verbose( void )
{
	uint8_t id[OW_ROMCODE_SIZE], sp[DS18X20_SP_SIZE], diff;
	
	uint8_t i;
	uint16_t meas;
	
	uint8_t subzero, cel, cel_frac_bits;
	
	for( diff = OW_SEARCH_FIRST; diff != OW_LAST_DEVICE; )
	{
		diff = ow_rom_search( diff, &id[0] );

		if( diff == OW_PRESENCE_ERR ) {
		  uart_puts_P( "No Sensor found\r\n" );
		  return OW_PRESENCE_ERR;
		}
		
		if( diff == OW_DATA_ERR ) {
		  uart_puts_P( "Bus Error\r\n" );
		  return OW_DATA_ERR;
		}
		
		DS18X20_show_id_uart( id, OW_ROMCODE_SIZE );
		
		if( id[0] == DS18B20_ID || id[0] == DS18S20_ID ) {	 // temperature sensor
			
			uart_puts_P ("\r\n");
			
			ow_byte_wr( DS18X20_READ );			// read command
			
			for ( i=0 ; i< DS18X20_SP_SIZE; i++ )
				sp[i]=ow_byte_rd();
			
			show_sp_uart( sp, DS18X20_SP_SIZE );

			if ( crc8( &sp[0], DS18X20_SP_SIZE ) )
				uart_puts_P( " CRC FAIL " );
			else 
				uart_puts_P( " CRC O.K. " );
			uart_puts_P ("\r\n");
		
			meas = sp[0]; // LSB Temp. from Scrachpad-Data
			meas |= (uint16_t) (sp[1] << 8); // MSB
			
			uart_puts_P(" T_raw=");
			uart_puthex_byte((uint8_t)(meas>>8));
			uart_puthex_byte((uint8_t)meas);
			uart_puts_P(" ");

			if( id[0] == DS18S20_ID ) { // 18S20
				uart_puts_P( "S20/09" );
			}
			else if ( id[0] == DS18B20_ID ) { // 18B20
				i=sp[DS18B20_CONF_REG];
				if ( (i & DS18B20_12_BIT) == DS18B20_12_BIT ) {
					uart_puts_P( "B20/12" );
				}
				else if ( (i & DS18B20_11_BIT) == DS18B20_11_BIT ) {
					uart_puts_P( "B20/11" );
				}
				else if ( (i & DS18B20_10_BIT) == DS18B20_10_BIT ) {
					uart_puts_P( " B20/10 " );
				}
				else { // if ( (i & DS18B20_9_BIT) == DS18B20_9_BIT ) { 
					uart_puts_P( "B20/09" );
				}
			}			
			uart_puts_P(" ");
			
			DS18X20_meas_to_cel(id[0], sp, &subzero, &cel, &cel_frac_bits);
			
			DS18X20_uart_put_temp(subzero, cel, cel_frac_bits);
			
			uart_puts("\r\n");
			
		} // if meas-sensor
		
	} // loop all sensors
Example #4
0
/**
 * \ingroup usartcmdline
 * \b OWREAD-Befehl DS18x20 auf Bus suchen und anzeigen
 */
int16_t command_OWlookup(char *outbuffer)
{
	if (outbuffer)					// nur bei USART
		return cmd_502(outbuffer);

	#if USE_OW
	uint8_t i;
	uint8_t diff, nSens;
	uint16_t TWert;
	uint8_t subzero, cel, cel_frac_bits;
	uint8_t gSensorIDs[MAXLOOKUP][OW_ROMCODE_SIZE];
	
	usart_write("\r\nScanning Bus for DS18X20");
	
	nSens = 0;
	
	for( diff = OW_SEARCH_FIRST; 
		diff != OW_LAST_DEVICE && nSens < MAXLOOKUP ;  )
	{
		DS18X20_find_sensor( &diff, &gSensorIDs[nSens][0] );
		
		if( diff == OW_PRESENCE_ERR ) {
			usart_write("\r\nNo Sensor found");
			break;
		}
		
		if( diff == OW_DATA_ERR ) {
			usart_write("\r\nBus Error");
			break;
		}
		
		nSens++;
	}
	usart_write("\n\r%i 1-Wire Sensoren gefunden.\r\n", nSens);

//	for (i=0; i<nSens; i++) {
//		// set 10-bit Resolution - Alarm-low-T 0 - Alarm-high-T 85
//		DS18X20_write_scratchpad( &gSensorIDs[i][0] , 0, 85, DS18B20_12_BIT);
//	}

	for (i=0; i<nSens; i++) {
		usart_write("\r\n#%i ist ein ",(int) i+1);
		if ( gSensorIDs[i][0] == DS18S20_ID)
			usart_write("DS18S20/DS1820");
		else usart_write("DS18B20");

		usart_write(" mit ");
		if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) ==
			DS18X20_POWER_PARASITE ) 
			usart_write( "parasitaerer" );
		else usart_write( "externer" ); 
		usart_write( " Spannungsversorgung. " );

		// T messen
		if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, &gSensorIDs[i][0] ) == DS18X20_OK ) {
				_delay_ms(DS18B20_TCONV_12BIT);
				if ( DS18X20_read_meas( &gSensorIDs[i][0], &subzero,
						&cel, &cel_frac_bits) == DS18X20_OK ) {
					DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
					TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
					usart_write(" %i %i.%4i C %i",subzero, cel, cel_frac_bits,TWert);
				}
				else usart_write(" CRC Error (lost connection?)");
			}
			else usart_write(" *** Messung fehlgeschlagen. (Kurzschluss?) ***");
	}
	
	#endif
	return 0;
}
Example #5
0
int main(void) {
  uint8_t i;
  
  //TODO: Enable watchdog.
  //TODO: Define compile-switch to disable serial output.
  
  // UART init
  uart_init((UART_BAUD_SELECT((BAUD),F_OSC)));
  // USB code init
  //	wdt_enable(WDTO_1S);
  //odDebugInit();
  DDRD = ~(1 << 2);   /* all outputs except PD2 = INT0 */
  PORTD = 0; /* no pullups on USB pins */
  /* We fake an USB disconnect by pulling D+ and D- to 0 during reset. This is
   * necessary if we had a watchdog reset or brownout reset to notify the host
   * that it should re-enumerate the device. Otherwise the host's and device's
   * concept of the device-ID would be out of sync.
   */
  //DDRB = ~USBMASK;    /* set all pins as outputs except USB */
  //computeOutputStatus();  /* set output status before we do the delay */
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 250;
  while(--i){         /* fake USB disconnect for > 500 ms */
	//wdt_reset();
	_delay_ms(2);
  }
  usbDeviceConnect();
  //TCCR0 = 5;          /* set prescaler to 1/1024 */
  usbInit();
  sei();

  // Init DS18X20 Connect LED.
  // Turn LED on: Pull to GND 
  DS18X20_STATUS_LED_DDR |= (1 << DS18X20_STATUS_LED_PIN);  // Output

  // search for the available sensors.
  nSensors = search_sensors();
  // TODO: Use LED to signal errors, i.e. CRC errors.
  if (nSensors == 0)
    DS18X20_STATUS_LED_PORT |= (1 << DS18X20_STATUS_LED_PIN); // Disable
  else
    DS18X20_STATUS_LED_PORT &= ~(1 << DS18X20_STATUS_LED_PIN); // Enable


  // Print debugging header
  logs_P( "\r\nUSBtemp - temperature at your fingertips\r\n" );
  logs_P( "----------------------------------------\r\n" );
  logi((int) nSensors);
  logs_P( " DS18X20 Sensor(s) available:\r\n" );
  for (i=0; i<nSensors; i++) {
    logs_P("# in Bus :");
    logi((int) i+1);
    logs_P(" : ");
#ifdef DEBUG
    DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
#endif
    logs_P( "\r\n" );
  }
  sync_read_sensors();
  print_readings();
  // main loop
  uint32_t delay_counter=0;
  enum read_state_t state=IDLE;
  for(;;) {
    //wdt_reset();
    usbPoll();
    delay_ms(MAIN_DELAY_MS); 
    delay_counter+=MAIN_DELAY_MS;
    // statemachine
    if (state == IDLE && delay_counter > READOUT_INTERVAL_MS) {
      // start measurement.
      async_start_read_sensors();
      delay_counter=0;
      state=MEASURING;
    }
    if (state==MEASURING && delay_counter > READOUT_WAIT_MS) {
      // Read the values from the sensors.
      async_finish_read_sensors();
      delay_counter = 0;
      state=UPDATED;
    }
    if (state==UPDATED) {
      // print temperature on uart.
      print_readings();
      delay_counter = 0;
      state=IDLE;
    }
  }
}
Example #6
0
int main(void)
{  
	//Konfiguration der Ausgänge bzw. Eingänge
	//definition erfolgt in der config.h
	DDRA = OUTA;
	#if USE_SER_LCD
		DDRC = OUTC;
	#else
		DDRC = OUTC;
		#if PORTD_SCHALT
			DDRD = OUTD;
		#endif
	#endif
	// RoBue:
	// Pullups einschalten
	PORTA = (1 << PORTA0) | (1 << PORTA1) | (1 << PORTA2) | (1 << PORTA3) | (1 << PORTA4) | (1 << PORTA5) | (1 << PORTA6);
	
    unsigned long a;
	#if USE_SERVO
		servo_init ();
	#endif //USE_SERVO
	
    usart_init(BAUDRATE); // setup the UART
	
	#if USE_ADC
		ADC_Init();
	#endif
	
	usart_write("\n\rSystem Ready\n\r");
    usart_write("Compiliert am "__DATE__" um "__TIME__"\r\n");
    usart_write("Compiliert mit GCC Version "__VERSION__"\r\n");
	for(a=0;a<1000000;a++){asm("nop");};

	//Applikationen starten
	stack_init();
	httpd_init();
	telnetd_init();
	
	//Spielerrei mit einem LCD
	#if USE_SER_LCD
		udp_lcd_init();
		lcd_init();
		// RoBue:
		// LCD-Ausgaben:
		lcd_clear();
		lcd_print(0,0,"*AVR-NET-IO "Version"*");
		lcd_print(2,0,"Counter: ");
		lcd_print(3,0,"Zeit:");
	#endif

	//Ethernetcard Interrupt enable
	ETH_INT_ENABLE;
	
	#if USE_SER_LCD
		// RoBue:
		// IP auf LCD
		lcd_print(1,0,"%1i.%1i.%1i.%1i",myip[0],myip[1],myip[2],myip[3]);
	#endif
	
	//Globale Interrupts einschalten
	sei(); 
	
	#if USE_CAM
		#if USE_SER_LCD
			lcd_print(1,0,"CAMERA INIT");
		#endif //USE_SER_LCD
		for(a=0;a<2000000;a++){asm("nop");};
		cam_init();
		max_bytes = cam_picture_store(CAM_RESELUTION);
		#if USE_SER_LCD
			back_light = 0;
			lcd_print(1,0,"CAMERA READY");
		#endif //USE_SER_LCD
	#endif // -> USE_CAM
	
	#if USE_NTP
	        ntp_init();
	        ntp_request();
	#endif //USE_NTP
	
	#if USE_WOL
	        wol_init();
	#endif //USE_WOL
    
	#if USE_MAIL
	        mail_client_init();
	#endif //USE_MAIL  

	// Startwerte für ow_array setzen
	#if USE_OW
		uint8_t i = 0;
		for (i=0;i<MAXSENSORS;i++){
			ow_array[i]=OW_START;
		}
		for (i=MAXSENSORS;i<MAXSENSORS*3;i++){
			ow_array[i]=OW_MINMAX;
		}
		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		for(a=0;a<1000000;a++){asm("nop");};
		auslesen = 0;
		minmax = 1;
	#endif


//Hauptschlfeife
// *************
		
	while(1)
	{

	#if USE_ADC
		ANALOG_ON;
	#endif

	eth_get_data();
		
        //Terminalcommandos auswerten
	if (usart_status.usart_ready){
	usart_write("\r\n");
		if(extract_cmd(&usart_rx_buffer[0]))
		{
			usart_write("Ready\r\n\r\n");
		}
		else
		{
			usart_write("ERROR\r\n\r\n");
		}
		usart_status.usart_ready =0;
	
	}
	
	// RoBue:
	// Counter ausgeben
	#if USE_SER_LCD
		lcd_print(2,9,"%4i",var_array[MAX_VAR_ARRAY-1]);
	#endif

	// RoBue:
	// Uhrzeit bestimmen und auf LCD ausgeben
	hh = (time/3600)%24;
	mm = (time/60)%60;
	ss = time%60;

	#if USE_SER_LCD
		lcd_print(3,7,"%2i:%2i:%2i",hh,mm,ss);
	#endif

	#if USE_HIH4000
		var_array[VA_OUT_HIH4000] = ((var_array[VA_IN_HIH4000]-160)/6);
	#endif

	#if USE_OW
	// RoBue:
	// Zurücksetzen der Min/Max-Werte um 00:00 Uhr einschalten
	if (( hh == 00 )&&( mm == 00 )) {
		minmax = 1;
	}
	#endif

	// ******************************************************************
	// RoBue:
	// 1-Wire-Temperatursensoren (DS18B20) abfragen
	// ******************************************************************

		#if USE_OW

		uint8_t i = 0;
		uint8_t subzero, cel, cel_frac_bits;
		uint8_t tempID[OW_ROMCODE_SIZE];

		// Messen bei ss=5,15,25,35,45,55		
		if ( ss%10 == 5 ) {

		// Messen?
		if ( messen == 1 ) {

		// RoBue Anmerkung:
		// Hiermit werden ALLE Sensoren zum Messen aufgefordert.
		// Aufforderung nur bestimmter Sensoren:
		// "NULL" durch "tempID" ersetzen
		
		// RoBue Testausgabe UART:
		// usart_write("Starte Messvorgang ...\r\n");		 

		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		
		// Kein Messen mehr bis ss=5,15,25,35,45,55
		messen = 0;

		// Jetzt kann ausgelesen werden
		auslesen = 1;

		}	// -> if messen
		
		}	// -> if ss

		// Auslesen bei ss=8,18,28,38,48,58
		if ( ss%10 == 8 ) {

		// Auslesen?
		if ( auslesen == 1 ) {

		// (erste) ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[0],OW_ROMCODE_SIZE);	
				
		while ( tempID[0] != 0 ) {
		//while ( tempID[0] == 0x10 ) {
				
			// RoBue Anmerkung:
			// Hiermit wird jeweils ein einzelner Sensor ausgelesen
			// und die Temperatur in ow_array abgelegt.
			// Achtung:
			// Pro Sekunde können max. ca. 10 Sensoren ausgelesen werden!
			if ( DS18X20_read_meas( tempID, &subzero,&cel, &cel_frac_bits) == DS18X20_OK ) {

				ow_array[i] = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);

				// Minuswerte:
					if ( subzero )
						ow_array[i] *= (-1);
				
				// min/max:
				if ( minmax == 1 ) {
					// Zurücksetzen der Min/Max_Werte 1x/Tag
					// auf die gerade aktuellen Temperaturen 
					ow_array[i+MAXSENSORS] = ow_array[i];
					ow_array[i+MAXSENSORS*2] = ow_array[i];
				}
				else {
					// Abgleich der Temp. mit den gespeicherten Min/Max-Werten
					if (ow_array[i]  < ow_array[i+MAXSENSORS])
        					ow_array[i+MAXSENSORS] = ow_array[i];
               				if (ow_array[i]  > ow_array[i+MAXSENSORS*2])
						ow_array[i+MAXSENSORS*2] = ow_array[i];
        			}

				//TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
				//ow_array[i] = TWert;
				
				// RoBue:
				// Testausgabe UART:
				// usart_write("%2i:%2i:%2i: Temperatur: %3i Grad\r\n",hh,mm,ss,ow_array[i]/10);
				
			}	// -> if
			else {
				usart_write("\r\nCRC Error (lost connection?) ");
				DS18X20_show_id_uart( tempID, OW_ROMCODE_SIZE );


			}	// -> else
		
		// nächste ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[++i],OW_ROMCODE_SIZE);

		}	// -> while
		
		// RoBue:
		// Temperatur auf LCD ausgeben (IP von Startausgabe (s.o.) wird Überschrieben)
		#if USE_SER_LCD
			lcd_print(1,0,"Tmp:            ");
			lcd_print(1,5,"%i C",ow_array[0]/10);
			lcd_print(1,11,"%i C",ow_array[1]/10);
		#endif

		}	// -> if auslesen

		auslesen = 0;	// Auslesen vorläufig abschalten
		messen = 1;	// Messen wieder ermöglichen
		minmax = 0;	// Min/Max-Werte vergleichen

		}	// -> if ss
		
	#endif
	

	// **********************************************************
	// RoBue:
	// Schalten der Ports (PORTC) durch bestimmte Bedingungen
	// - Temperatur (1-Wire -> PORTA7) mit/ohne Lüftungsautomatik
	// - digital, analog (-> PORTA0-6)
	// - Zeit
	// **********************************************************
	
	// Automatik eingeschaltet?
	if ( var_array[9] == 1 ) {

	if ( ss%10 == 1 ) {
		schalten = 1;
	}

	// Abfrage bei ss =0,10,20,30,40,50
	if ( ss%10 == 0 ) {
	if ( schalten == 1 ) {
	
	// RoBue Testausgabe UART:
	// usart_write("%2i:%2i: Schaltfunktionen testen ...\r\n",hh,mm);	


	// PORTC0:
	// Über Temperatur: var_array[10] - Sensor0		
	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
		PORTC |= (1 << PC0); // ein
	//
	// Über Temperatur: var_array[10] - Sensor0 - PORTA0
	// if ((PINA&0b00000001) == 0 ) {		// PORTA0: Fenster geschlossen?
	//	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
	//		PORTC |= (1 << PC0); // ein
	//	}
	//  	else { 
	//     		PORTC &= ~(1 << PC0); // aus
	//	}
	}
	else {
	      	PORTC &= ~(1 << PC0); // aus
	}

	// PORTC1:
	// Über Temperatur: var_array[11] - Sensor1
	// if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
	//	PORTC |= (1 << PC1); // ein
	//
	// Über Temperatur: var_array[11] - Sensor1 - PORTA1
	if ((PINA&0b00000010) == 0 ) {		// PORTA1: Fenster geschlossen?
		if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
			PORTC |= (1 << PC1); // ein
		}
		else {
			PORTC &= ~(1 << PC1); // aus
		}
	}
	else {
		PORTC &= ~(1 << PC1); // aus
	}
		
	// PORTC2:
	// Über Temperatur: var_array[12] - Sensor2
	// if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {						
	//	PORTC |= (1 << PC2); // ein
	// Über Temperatur: var_array[12] - Sensor2 - PORTA2
	// if ((PINA&0b00000100) == 0 ) {		// PORTA2: Fenster geschlossen?
	//	if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {
	//		PORTC |= (1 << PC2); // ein
	//	}
	//	else {
	//		PORTC &= ~(1 << PC2); // aus
	//	}
	//}
	//else {
	//	PORTC &= ~(1 << PC2); // aus
	//}

	// PORTC4:
	// Über 2 Temperaturen (Differenz)
	// var_array[13] - Sensor3 Vorlauf, Sensor4 Ruecklauf
	//
	// z.B. Zirkulationspumpe für Warmwasser
	// Achtung: Temp. von Sensor3 MUSS höher/gleich sein als Temp. von Sensor4
	// Ansonsten laeuft die Pumpe immer
	//
		if ( (ow_array[3]/10 - ow_array[4]/10) >= var_array[14] ) {						
		PORTC |= (1 << PC4); // ein
	}
	else {
		PORTC &= ~(1 << PC4); // aus
	}

		// PORTC6:
	// Über Analogwert:
	if ( var_array[6] > var_array[18] ) {
		PORTC |= (1 << PC6); // ein
	}
	else {
		PORTC &= ~(1 << PC6); // aus
	}

	// PORTC7:
	// Über Zeit: ein/aus
	if ( hh == var_array[20] ) {
		if ( mm == var_array[21] ) {
			PORTC |= (1 << PC7); // ein
		}
	}
	if ( hh == var_array[22] ) {
		if ( mm == var_array[23] ) {
			PORTC &= ~(1 << PC7); // aus
		}
	}


	schalten = 0;	// Vorerst nicht mehr schalten

	} // -> schalten == 1
	} // -> if ss == ...
	} // -> if var_array == 1
	
	
        //Wetterdaten empfangen (Testphase)
        #if GET_WEATHER
        http_request ();
        #endif
        
        //Empfang von Zeitinformationen
	#if USE_NTP
		if(!ntp_timer){
		ntp_timer = NTP_REFRESH;
		ntp_request();
		}
	#endif //USE_NTP
		
        //Versand von E-Mails
        #if USE_MAIL
	        if (mail_enable == 1)
	        {
	            mail_enable = 0;
	            mail_send();
	        }
        #endif //USE_MAIL
        
        //Rechner im Netzwerk aufwecken
        #if USE_WOL
	        if (wol_enable == 1)
	        {
	            wol_enable = 0;
	            wol_request();
	        }
        #endif //USE_WOL
           
	//USART Daten für Telnetanwendung?
	telnetd_send_data();
    }

return(0);
}