76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <avr/interrupt.h>  
 | 
						||
#include <avr/io.h>  
 | 
						||
//#define F_CPU 1000000UL 
 | 
						||
  
 | 
						||
// Определения портов и битов  
 | 
						||
#define DHT_PORT PORTB  
 | 
						||
#define DHT_DDR DDRB  
 | 
						||
#define DHT_PIN PINB  
 | 
						||
#define DHT_BIT 0  
 | 
						||
  
 | 
						||
// Глобальные переменные  
 | 
						||
unsigned char data[5];  
 | 
						||
byte  dt[48];
 | 
						||
byte  dtcnt;
 | 
						||
 | 
						||
 | 
						||
float temperature, humidity;  
 | 
						||
  int enc_val, last_enc_val;
 | 
						||
float last_temperature, last_humidity;
 | 
						||
 | 
						||
// Флаг прерывания  
 | 
						||
volatile unsigned char interrupt_flag = 1;  
 | 
						||
bool dht_check_act = false;
 | 
						||
bool dht_done = false;
 | 
						||
int  dht_check_icp;
 | 
						||
 | 
						||
byte dht_state, dht_last_state;
 | 
						||
int T1time, dPos, dNum;
 | 
						||
 | 
						||
//int dht_save_time[42];
 | 
						||
int dht_save_time_id;
 | 
						||
  
 | 
						||
// Таймер для задержки  
 | 
						||
volatile unsigned int  timer_counter = 0;
 | 
						||
int dht_en_timer=0;  
 | 
						||
 | 
						||
void PrintDebug();
 | 
						||
 | 
						||
#include "timers.h"  
 | 
						||
#include "dht.h"
 | 
						||
#include "enc.h"
 | 
						||
// Настройка  
 | 
						||
void setup()  
 | 
						||
{  
 | 
						||
    // Инициализируем UART  
 | 
						||
    Serial.begin(57600);  
 | 
						||
    encoder_setup();
 | 
						||
    // Настраиваем таймер  
 | 
						||
    setup_timer();  
 | 
						||
  
 | 
						||
    // Разрешаем прерывания  
 | 
						||
    sei();
 | 
						||
    Serial.println("Start system");
 | 
						||
    delay(10);
 | 
						||
    DDRD = 0b10000000;
 | 
						||
}  
 | 
						||
  
 | 
						||
// Основной цикл  
 | 
						||
void loop()  
 | 
						||
{  
 | 
						||
  
 | 
						||
  // Читаем данные с DHT  
 | 
						||
    dht_check();
 | 
						||
    enc_val = encoder_value();
 | 
						||
    bool  Draw=false;
 | 
						||
 | 
						||
    if ( enc_val != last_enc_val )        
 | 
						||
    { 
 | 
						||
      Draw = true; last_enc_val = enc_val; 
 | 
						||
    } 
 | 
						||
 | 
						||
    if ( Draw )
 | 
						||
    {
 | 
						||
      Serial.println("Enc ["+(String)enc_val+"] "); 
 | 
						||
    }  
 | 
						||
} |