Exemplo n.º 1
0
Arquivo: main.c Projeto: eerimoq/simba
int test_get_temp(struct harness_t *harness_p)
{
    struct owi_driver_t owi;
    struct ds18b20_driver_t ds;
    struct owi_device_t devices[4];
    char buf[24];
    int number_of_sensors;

    BTASSERT(owi_init(&owi, &pin_d7_dev, devices, membersof(devices)) == 0);
    BTASSERT(ds18b20_init(&ds, &owi) == 0);

    time_busy_wait_us(50000);

    number_of_sensors = owi_search(&owi);

    std_printf(FSTR("number_of_sensors = %d\r\n"), number_of_sensors);

    BTASSERT(number_of_sensors == 2);

    strcpy(buf, "drivers/ds18b20/list");
    BTASSERT(fs_call(buf, NULL, sys_get_stdout(), NULL) == 0);

    time_busy_wait_us(50000);

    return (0);
}
Exemplo n.º 2
0
// main program body
int main(void)
{
	WDTCTL = WDTPW + WDTHOLD;	// Stop WDT

	board_init(); // init dco and leds
	uart_init(); // init uart
	rtc_timer_init(); // init rtc timer

	ds18b20_sensor_t s[3]; // init ds18b20 sensors
	ds18b20_init(&s[0],&P2OUT,&P2IN,&P2REN,&P2DIR,0); // sensor 0: PORT2 pin 0
	ds18b20_init(&s[1],&P2OUT,&P2IN,&P2REN,&P2DIR,1); // sensor 1: PORT2 pin 1
	ds18b20_init(&s[2],&P2OUT,&P2IN,&P2REN,&P2DIR,2); // sensor 2: PORT2 pin 2

    prog_init();
    pout_init(); // init power output (pump switch)

	while(1)
	{
	    int i;
        for (i=0;i<3;i++) ds18d20_start_conversion(&s[i]); // start conversion
        __bis_SR_register(CPUOFF + GIE); // enter sleep mode (leave on rtc second event)
        for (i=0;i<3;i++)
        {
            ds18b20_read_conversion(&s[i]); // read data from sensor
            if (s[i].valid==true)
            {
                t_val[i]=s[i].data.temp; // save temperature value
                t_err[i]=0; // clear error counter
            }
            else if (t_err[i]!=0xFFFF) t_err[i]++; // increase error counter
        }
        __bis_SR_register(CPUOFF + GIE); // enter sleep mode (leave on rtc second event)
        if (minute_event)
        {
            minute_event=false;
            if (pauto) pout_set(AUTO);
            __bis_SR_register(CPUOFF + GIE); // enter sleep mode (leave on rtc second event)
        }
	}

	return -1;
}
Exemplo n.º 3
0
void tempDeviceInit(void)
{
    unsigned int i;

    ds18b20_devices=w1_search(0xf0,ds18b20_rom_codes);
    
    for (i=0; i<ds18b20_devices; i++)
    {
        ds18b20_init(&ds18b20_rom_codes[i][0],-30,125,DS18B20_9BIT_RES);
    }
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    signal(SIGINT, sig_handler);

    //! [Interesting]

    printf("Initializing...\n");

    // Instantiate an DS18B20 instance using the uart 0
    ds18b20_context sensor = ds18b20_init(0);

    if (!sensor)
    {
        printf("ds18b20_init() failed.\n");
        return(1);
    }

    printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));

    // update and print available values every second
    while (shouldRun)
    {
        // update our values for all sensors
        ds18b20_update(sensor, -1);

        int i;
        for (i=0; i<ds18b20_devices_found(sensor); i++)
        {
            printf("Device %02d: Temperature: %f C\n",
                    i, ds18b20_get_temperature(sensor, i));
        }
        printf("\n");

        upm_delay(2);
    }

    printf("Exiting...\n");

    ds18b20_close(sensor);
    //! [Interesting]

    return 0;
}
Exemplo n.º 5
0
void main()
{
    /* speed up clock */
    OSCCONbits.IRCF = 7;

    /* turn on a led to show life sign */
    TRISD = 0;
    LATD = 1;

    /* enable digital input */
    ANSEL = 0;

    ds18b20_init();

    while ( 1 )
    {
        ds18b20_work();
    }
}
Exemplo n.º 6
0
int main(void)
{
	USART1_Init(921600);
	BTN_Init();
	BTN_Interrupts();
	LED_Init();

	// Tick every 1 ms
	if (SysTick_Config(SystemCoreClock / 1000))  while (1);

	printf("Hello, World!\r\n");
	ds18b20_init(GPIOC, GPIO_Pin_6, TIM2);
    while(1)
    {
    	ds18b20_read_temperature_all();
    	ds18b20_wait_for_conversion();
    	printf("%d---\r\n", ds18b20_get_precission());
    	ds18b20_convert_temperature_all();
    }
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ds18b20_poll_process, ev, data)
{
  static struct etimer et;
  static uint8_t scratchpad[DS18B20_SCRATCHPAD_SIZE];
  static ow_rom_code_t id;

  PROCESS_BEGIN();

  printf("\nDS18B20 test\n");

  printf("VSEC ON\n");
  power_control_vsec_set(1);

  /* initialize the DS18B20 hardware */
  printf("Initialize 1-wire\n");
  ow_init();
  printf("1-wire READ ROM\n");
  id = ow_read_rom();
  printf("Initialize DS18B20\n");
  ds18b20_init();
  printf("DS18B20 init done\n");

  /* Poll at 1Hz */
  etimer_set(&et, CLOCK_SECOND);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    /* Reset the etimer to trig again */
    etimer_reset(&et);

    ds18b20_read_scratchpad(id, scratchpad);
    ds18b20_convert_temperature(id);
  }

  PROCESS_END();
}
Exemplo n.º 8
0
simple_float ds18b20_GetTemp2( )
{
	ds18b20_init(GPIOA, GPIO_PIN_6);
	ds18b20_convert_temperature_simple();
	return ds18b20_read_temperature_simple();
}
Exemplo n.º 9
0
int main(void)
{
	uint8_t last_min = 0;
	cli();

	DDRC = _BV(C_SCL);

	DDRD = _BV(D_LCD_BL) | _BV(D_LCD_SEL) | _BV(D_LCD_SCK) |
		_BV(D_LCD_MOSI) | _BV(D_LCD_RESET) | _BV(D_ALERT);

#if (FOSC == 18432000UL)
	/*
	 * Fosc = 18432000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 180;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 180);
#elif (FOSC == 7372800UL)
	/*
	 * Fosc = 7372800
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 72;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 72);
#elif (FOSC == 16000000UL)
	/*
	 * Fosc = 16000000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 156;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 156);
#else
#error "unsupported FOSC freq"
#endif

	twi_master_init();
	twi_add_device(rtc_begin, rtc_end);
	twi_add_device(relay_begin, relay_end);
	sei();

	lcd_init();
	lcd_fill(0, 0, 131, 131, 0x000);

	ow_init();
	ds18b20_init();
	adc_sample();

	set_point = 25 << 8;

	while (1) {
		ds18b20_ping();

		if (last_min != time[1]) {
			temp_history[temp_history_idx] = ds18b20_temps[1];
			temp_history_idx++;
			if (temp_history_idx == ARRAY_SIZE(temp_history))
				temp_history_idx = 0;
			last_min = time[1];
		}

		if (ph == 0) {
			ph = (uint32_t)adc_data[2] << PH_IIR_SHIFT;
		} else {
			ph -= ph >> PH_IIR_SHIFT;
			ph += adc_data[2];
		}

		ui();

		if (alert)
			PORTD |= _BV(D_ALERT);
		else
			PORTD &= ~_BV(D_ALERT);

		cli();
		if (ds18b20_temps[1] < set_point)
			relays &= ~0x1;
		else if(ds18b20_temps[1] > (set_point + (1 << 4)))
			relays |= 0x1;
		sei();
	}

}