Example #1
0
void adc_task(void) {
    uint8_t update_time = 0;
    adc_init();
    while (1) {
        char light_str[6], temp_str[6], time_str[6];
        uint8_t light = adc_acquire(0);
        uint8_t temperature = adc_acquire(1);
        uint8_t_to_ascii(light, &(light_str[0]));
        uint8_t_to_ascii(temperature, &(temp_str[0]));
        uint8_t_to_ascii(ticks, &(time_str[0]));
        os_semaphore_wait(&lcd_sem);
        lcd_set_cursor(0, 0);
        lcd_putstr("Time: ");
        lcd_putstr(time_str);
        lcd_set_cursor(1, 0);
        lcd_putstr("Light: ");
        lcd_putstr(light_str);
        lcd_set_cursor(2, 0);
        lcd_putstr("Temp: ");
        lcd_putstr(temp_str);
        os_semaphore_signal(&lcd_sem);
        
        os_semaphore_wait(&stt_sem);
        if (state) {
            update_time = 1;
        } else {
            update_time = 0;
        }
        os_semaphore_signal(&stt_sem);
        os_semaphore_wait(&tck_sem);
        if (update_time) {
            ticks++;
        }
        os_semaphore_signal(&tck_sem);
        
        if (state == 1) {
            usart_puts("Time: ");
            usart_puts(time_str);
            usart_puts("\r\n");
            usart_puts("Light: ");
            usart_puts(light_str);
            usart_puts("\r\n");
            usart_puts("Temperature: ");
            usart_puts(temp_str);
            usart_puts("\r\n");
        }
        
        os_delay(os_get_current_pid(), 1000);
    }
}
//LM35 data processing function
unsigned int temp_acquire(void)
{
    float l;
    l=adc_acquire(CHANNEL_0);      //get data for processing
    l=(l*500.0)/1023.0;
    unsigned int temp_val=l;
    return temp_val;
}