Example #1
0
void uart_put_temp(int16_t decicelsius) {
  char s[10];
  //uart_put_int( decicelsius );
  printf("%d", (int) decicelsius );
  printf(" deci°C, ");
  DS18X20_format_from_decicelsius( decicelsius, s, 10 );
  printf( s );
  printf(" °C");
}
Example #2
0
static void uart_put_temp(int16_t decicelsius)
{
    char s[10];

    uart_put_int( decicelsius );
    uart_puts_P(" deci°C, ");
    DS18X20_format_from_decicelsius( decicelsius, s, 10 );
    uart_puts( s );
    uart_puts_P(" °C");
}
Example #3
0
void frontend_tempdetails(uint8_t **wheel_target, uint8_t *next_state, int16_t *measVal, uint16_t measMiddle, uint8_t nSensors){
	char buffer[8];
	*wheel_target = NULL;
	*next_state = MENU_MAIN;
	lcd_clrscr();
	for(uint8_t i = 0; i < nSensors; i++){
		if((i+1)%2 != 0){
			lcd_gotoxy(0,(i/2));
		}else{
			lcd_gotoxy(8, (i/2));
		}
		sprintf(buffer, "%i:", i);
		lcd_puts(buffer);
		DS18X20_format_from_decicelsius(measVal[i], buffer, 10);
		lcd_puts(buffer);
	}
	lcd_gotoxy(8,1);
	lcd_putc(AVERAGE);
	lcd_puts(":");
	DS18X20_format_from_decicelsius(measMiddle, buffer, 10);
	lcd_puts(buffer);
}
Example #4
0
void frontend_main(uint8_t **wheel_target, uint8_t *next_state, uint16_t measMiddle, uint8_t rangeMin, uint8_t rangeMax, struct Flag Flags, int8_t timerCounter, uint8_t timerTarget){
	//MAIN//
	char buffer[16];
	*wheel_target = NULL;
	*next_state = MENU_AIM;
	lcd_clrscr();
	lcd_gotoxy(0,0);
	lcd_putc(4);
	DS18X20_format_from_decicelsius(measMiddle, buffer, 10);
	lcd_puts(buffer);
	lcd_putc(3);
	lcd_gotoxy(9,0);
	sprintf(buffer, "R:%i-%i", rangeMin, rangeMax);
	lcd_puts(buffer);
	lcd_gotoxy(0,1);
	if(Flags.heaterOn == 1){
		lcd_putc(0); //Up
		}else{
		lcd_putc(2); //stall
	}
	
	#ifdef DEBUG_CLOCK
		#include "ds1337.h"
		uint8_t t;
		t = ds1337_getHours();
		sprintf(buffer, "%2i", t);
		lcd_puts(buffer);
		t = ds1337_getMinutes();
		sprintf(buffer, ":%2i", t);
		lcd_puts(buffer);
		t = ds1337_getSeconds();
		sprintf(buffer, ":%2i", t);
		lcd_puts(buffer);
	
	#else
	
		lcd_gotoxy(2, 1);
		sprintf(buffer, "t:%im", timerCounter);
		lcd_puts(buffer);
		lcd_gotoxy(9,1);
		sprintf(buffer, "T:%im", timerTarget);
		lcd_puts(buffer);
	
	#endif
}
/* 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 #6
0
int main (void) {            // (2)
   ledidx_t i;

   DDRB  = 0xFF;  // Port B: 1 = output
   PORTB = 0x01;  //bootup 1

   //_delay_ms(1000);

   // Initialize LCD Display
   DDRC |= (1<<PC1) | (1<<PC3); //PC1 = R/W, PC3 = Backlight control
   PORTC &= ~(1<<PC1);
   //Switch Backlight on:
   PORTC |= (1<<PC3);

   _delay_ms(10); lcd_init();

   PORTB = 0x02;  //bootup 2
   _delay_ms(100);
   lcd_string_P(PSTR("blinkylight 0.3 "));
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Booting ...     "));
   //PORTB = 0x03;  //bootup 3
   //_delay_ms(1000);

   uart_init();
   uart_putc('p'); uart_putc('w'); uart_putc('r'); uart_putc('O'); uart_putc('N'); uart_putc('\n');
   //PORTB = 0x04;  //bootup 4



   //PORTB = 0x05;  //bootup 5

   // Enable Interrupts
   sei();
   PORTB = 0x06;  //bootup 6

   // muss vor ws2801_init stehen, da dieser PA1 und PA2 als output schaltet
   DDRA  = 0x00; // Port A: 0 = input
   PORTA = 0x00;  //        0 = pull-ups off

   //PORTB = 0x0a;  //bootup a


   PORTB = 0x00;  //bootup d
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Boot complete  "));
   _delay_ms(10);

   //Switch Backlight off:
   PORTC &= ~(1<<PC3);

   // Enter main loop
   uint8_t dezisek = 0;
#define DEZISEKTHRES 4
   while(1) {                // (5)
     /* "leere" Schleife*/   // (6)
     _delay_ms(25);
     //pb_scroll <<= 1;
     //if (pb_scroll == 0b00010000) pb_scroll = 0b00000001;
     //PORTB &= 0b11110000;
     //PORTB |= pb_scroll;
     PORTB ^= (1<<PB2);
     if (dezisek > DEZISEKTHRES) {
       if (relay_timer > 0) {
         relay_timer --;
         if (relay_timer == 0) relay_reset = 1;
         else {
           PORTB ^= ( 1 << PB5 )|(1<<PB6)|(1<<PB7);
         }
       }
     }
     dezisek++;
     if (disp_set) {
       lcd_clear();
       lcd_home();

       for(i=0;i<16;i++)lcd_data(disp_buf[i]);
       lcd_setcursor(0,2);
       for(;i<32;i++)lcd_data(disp_buf[i]);

       disp_set = 0;
       _delay_ms(250);
     }
     if (relay_set) {
       PORTB |= (1<<PB4);
       PORTB |= (1<<PB5)|(1<<PB6)|(1<<PB7);
       relay_set = 0;
     }
     if (relay_reset) {
       PORTB &= ~(1<<PB4);
       PORTB &= ~((1<<PB5)|(1<<PB6)|(1<<PB7));
       relay_reset = 0; relay_timer = 0;
     }
     if (PINA & (1<<PA7)) {
       uart_putc('5');
     }
     if (PINA & (1<<PA6)) {
       uart_putc('4');
     }
     if (PINA & (1<<PA5)) {
       uart_putc('3');
     }
     if (PINA & (1<<PA4)) {
       uart_putc('2');
     }
     if (measure_temp == 1) {
       //PORTC ^= (1<<PC3);
       uint8_t sensor_id[OW_ROMCODE_SIZE];
       uint8_t diff = OW_SEARCH_FIRST;
       ow_reset();
       DS18X20_find_sensor(&diff, &sensor_id[0]);
       if (diff == OW_PRESENCE_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Presence     "));
       else if (diff == OW_DATA_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Data         "));
       else {
         if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) {
           _delay_ms( DS18B20_TCONV_12BIT );
           int16_t decicelsius;
           if ( DS18X20_read_decicelsius( &sensor_id[0], &decicelsius) == DS18X20_OK ) {
             disp_tmp_buf[0]='T'; disp_tmp_buf[1]='e'; disp_tmp_buf[2]='m'; disp_tmp_buf[3]='p'; disp_tmp_buf[4]=':'; disp_tmp_buf[5]=' ';
             DS18X20_format_from_decicelsius( decicelsius, &disp_tmp_buf[6], 8 );
           } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: Read        "));
           }
         } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: StartMeasure"));
         }
       }
       sprintf(&disp_tmp_buf[16], "%d bytes recv.", recv_len);
       //disp_show_buf(&disp_tmp_buf[0]);
       for(i=0;i<20;i++) uart_putc(disp_tmp_buf[i]);
       measure_temp=0;
     }
     if (PINA & (1<<PA3)) {
       relay_set = 1;
       relay_timer = 10;
       uart_putc('1');
     }
     //uart_putc('+');
//     uart_putc('\n');
   }                         // (7)
   /* wird nie erreicht */
   return 0;                 // (8)
}