4_Ust-vo_poluchenia_velichi.../DHT_22.h

56 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Функция чтения данных с DHT
unsigned int dht_check()
{
if ( dht_check_act )
{
dht_check_act = false;
//-----[ 01. Старт, выжидание 18мс ]-----
if ( interrupt_flag == 1)
{
// Запускаем таймер на 18 мс посылка start на dht
Serial.print("Start DHT -> ");
DHT_DDR |= (1 << DHT_BIT); // Пин как выход
DHT_PORT &= ~(1 << DHT_BIT); // Выход ноль
TCNT1 = 0;
OCR1A = 288;
TCCR1A = 0b00000000;
TIMSK1 = 0b00000010;
TCCR1B = 0b00000101;
}
if ( interrupt_flag == 2)
{
DHT_PORT |= (1 << DHT_BIT);
DHT_DDR &= ~(1 << DHT_BIT);
dht_save_time_id = 0;
TCNT1 = 0;
OCR1A = 10000;
TCCR1A = 0b00000000;
TCCR1B = 0b10000001;
TIFR1 = 0b00000000;
TIMSK1 = 0b00100010;
dPos = 7;
dNum = 0;
dht_last_state = false;
}
// Вычисляем температуру и влажность
if ( dht_done )
{
dht_done = false;
temperature = (data[3] * 0.1) + ((data[2] & 0b01111111) * 25.6);
if (data[2] & 0b10000000) temperature *= -1;
humidity = (data[1] * 0.1) + (data[0] * 25.6);
// Выводим данные на UART
Serial.print(humidity);
Serial.print("% ");
Serial.print(temperature);
Serial.println("C");
}
}
}