Đo nhiệt độ và độ ẩm dùng DHT11 PIC16f887 hiển thị LCD:
Nguồn: http://www.stm32vn.com/
#include <16f887.h>
//!#device ADC=10
#use delay (CLOCK = 4M)
#fuses INTRC_IO
#include <stdlib.h>
#include <lcd.c>
//!#include <lcd420.c>
//!#define LCD_ENABLE_PIN PIN_D0
//!#define LCD_RS_PIN PIN_D1
//!#define LCD_RW_PIN PIN_D2
//!#define LCD_DATA_PORT PORTD
//!#define LCD_TRIS_LOCATION TRISD
#define Buzz PIN_E0
#define UP PIN_E1
#define DW PIN_E2
#define DHT11_pin PIN_A0
unsigned char values[5];
const unsigned char symbols[8]=
{
0x07, 0x05, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00
};
unsigned int16 Max;
//!int8 i;
void setup();
void DHT11_init();
unsigned char get_byte();
unsigned char get_data();
void lcd_symbols();
void Click_UP();
void Click_DW();
void main()
{
//! set_tris_e(0xff);
//! //set_tris_a(0x00);
//! setup_adc_ports(NO_ANALOGS);
//! setup_adc_ports(sAN5);
//! setup_adc(ADC_CLOCK_INTERNAL);
//!
unsigned char state = 0;
setup();
lcd_init();
set_tris_e(0b11111110);
Max=65;
//! lcd_gotoxy(1,2);
//! printf(lcd_putc,"CAI DAT=%03Ld",Max);
//! lcd_gotoxy(12,2); lcd_putc(223);
//! lcd_gotoxy(13,2); lcd_putc("C");
while(TRUE)
{
get_data();
if(Max>values[0]) output_high(Buzz);
else output_low(Buzz);
lcd_gotoxy(1, 1);
lcd_putc("Tmp/ C: ");
lcd_gotoxy(5, 1);
lcd_putc(0);
lcd_gotoxy(1, 2);
lcd_putc("R.H/ %: ");
lcd_gotoxy(9, 1);
printf(lcd_putc, "%3u.%03u ", values[2], values[3]);
lcd_gotoxy(9, 2);
printf(lcd_putc, "%3u.%03u ", values[0], values[1]);
delay_ms(1000);
delay_ms(1000);
};
}
void setup()
{
disable_interrupts(global);
port_B_pullups(FALSE);
//! setup_timer_0(T0_internal | T0_8_bit);
//! set_timer0(0);
DHT11_init();
lcd_init();
lcd_putc("\f");
lcd_symbols();
}
void DHT11_init()
{
output_float(DHT11_pin);
delay_ms(1000);
}
unsigned char get_byte()
{
unsigned char s = 0;
unsigned char value = 0;
for(s = 0; s < 8; s += 1)
{
value <<= 1;
while(!input(DHT11_pin));
delay_us(30);
if(input(DHT11_pin))
{
value |= 1;
}
while(input(DHT11_pin));
}
return value;
}
unsigned char get_data()
{
short chk = 0;
unsigned char s = 0;
unsigned char check_sum = 0;
output_high(DHT11_pin);
output_low(DHT11_pin);
delay_ms(18);
output_high(DHT11_pin);
delay_us(26);
chk = input(DHT11_pin);
if(chk)
{
return 1;
}
delay_us(80);
chk = input(DHT11_pin);
if(!chk)
{
return 2;
}
delay_us(80);
for(s = 0; s <= 4; s += 1)
{
values[s] = get_byte();
}
output_high(DHT11_pin);
for(s = 0; s < 4; s += 1)
{
check_sum += values[s];
}
if(check_sum != values[4])
{
return 3;
}
else
{
return 0;
}
}
void lcd_symbols()
{
unsigned char i = 0;
lcd_send_byte(0, 0x40);
for(i = 0; i < 8; i++)
{
lcd_send_byte(1, symbols[i]);
}
lcd_send_byte(0, 0x80);
}
void Click_UP()
{
if(input_state(UP)==0)
{
delay_ms(50);
Max++;
if(Max>=100) Max=100; else;
lcd_gotoxy(1,2);
printf(lcd_putc,"CAI R.H=%03Ld",Max);
while(input_state(UP)==0);
delay_ms(50);
}
}
void Click_DW()
{
if(input_state(DW)==0)
{
delay_ms(50);
Max--;
if(Max<=0) Max=0; else;
lcd_gotoxy(1,2);
printf(lcd_putc,"CAI R.H=%03Ld",Max);
while(input_state(DW)==0);
delay_ms(50);
}
}
Nguồn: http://www.stm32vn.com/
#include <16f887.h>
//!#device ADC=10
#use delay (CLOCK = 4M)
#fuses INTRC_IO
#include <stdlib.h>
#include <lcd.c>
//!#include <lcd420.c>
//!#define LCD_ENABLE_PIN PIN_D0
//!#define LCD_RS_PIN PIN_D1
//!#define LCD_RW_PIN PIN_D2
//!#define LCD_DATA_PORT PORTD
//!#define LCD_TRIS_LOCATION TRISD
#define Buzz PIN_E0
#define UP PIN_E1
#define DW PIN_E2
#define DHT11_pin PIN_A0
unsigned char values[5];
const unsigned char symbols[8]=
{
0x07, 0x05, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00
};
unsigned int16 Max;
//!int8 i;
void setup();
void DHT11_init();
unsigned char get_byte();
unsigned char get_data();
void lcd_symbols();
void Click_UP();
void Click_DW();
void main()
{
//! set_tris_e(0xff);
//! //set_tris_a(0x00);
//! setup_adc_ports(NO_ANALOGS);
//! setup_adc_ports(sAN5);
//! setup_adc(ADC_CLOCK_INTERNAL);
//!
unsigned char state = 0;
setup();
lcd_init();
set_tris_e(0b11111110);
Max=65;
//! lcd_gotoxy(1,2);
//! printf(lcd_putc,"CAI DAT=%03Ld",Max);
//! lcd_gotoxy(12,2); lcd_putc(223);
//! lcd_gotoxy(13,2); lcd_putc("C");
while(TRUE)
{
get_data();
if(Max>values[0]) output_high(Buzz);
else output_low(Buzz);
lcd_gotoxy(1, 1);
lcd_putc("Tmp/ C: ");
lcd_gotoxy(5, 1);
lcd_putc(0);
lcd_gotoxy(1, 2);
lcd_putc("R.H/ %: ");
lcd_gotoxy(9, 1);
printf(lcd_putc, "%3u.%03u ", values[2], values[3]);
lcd_gotoxy(9, 2);
printf(lcd_putc, "%3u.%03u ", values[0], values[1]);
delay_ms(1000);
delay_ms(1000);
};
}
void setup()
{
disable_interrupts(global);
port_B_pullups(FALSE);
//! setup_timer_0(T0_internal | T0_8_bit);
//! set_timer0(0);
DHT11_init();
lcd_init();
lcd_putc("\f");
lcd_symbols();
}
void DHT11_init()
{
output_float(DHT11_pin);
delay_ms(1000);
}
unsigned char get_byte()
{
unsigned char s = 0;
unsigned char value = 0;
for(s = 0; s < 8; s += 1)
{
value <<= 1;
while(!input(DHT11_pin));
delay_us(30);
if(input(DHT11_pin))
{
value |= 1;
}
while(input(DHT11_pin));
}
return value;
}
unsigned char get_data()
{
short chk = 0;
unsigned char s = 0;
unsigned char check_sum = 0;
output_high(DHT11_pin);
output_low(DHT11_pin);
delay_ms(18);
output_high(DHT11_pin);
delay_us(26);
chk = input(DHT11_pin);
if(chk)
{
return 1;
}
delay_us(80);
chk = input(DHT11_pin);
if(!chk)
{
return 2;
}
delay_us(80);
for(s = 0; s <= 4; s += 1)
{
values[s] = get_byte();
}
output_high(DHT11_pin);
for(s = 0; s < 4; s += 1)
{
check_sum += values[s];
}
if(check_sum != values[4])
{
return 3;
}
else
{
return 0;
}
}
void lcd_symbols()
{
unsigned char i = 0;
lcd_send_byte(0, 0x40);
for(i = 0; i < 8; i++)
{
lcd_send_byte(1, symbols[i]);
}
lcd_send_byte(0, 0x80);
}
void Click_UP()
{
if(input_state(UP)==0)
{
delay_ms(50);
Max++;
if(Max>=100) Max=100; else;
lcd_gotoxy(1,2);
printf(lcd_putc,"CAI R.H=%03Ld",Max);
while(input_state(UP)==0);
delay_ms(50);
}
}
void Click_DW()
{
if(input_state(DW)==0)
{
delay_ms(50);
Max--;
if(Max<=0) Max=0; else;
lcd_gotoxy(1,2);
printf(lcd_putc,"CAI R.H=%03Ld",Max);
while(input_state(DW)==0);
delay_ms(50);
}
}
14/05/24, 03:19 pm by sieuviet2020
» Màn hình máy tính Dell D2020H 19.5 icnh chính hãng giá tốt
08/05/24, 09:43 am by thinhphat
» Lắp đặt Nhà thông minh với 3 phút
03/05/24, 11:58 pm by sieuviet2020
» TẠI SAO HỆ THỐNG NHÀ THÔNG MINH KHÔNG DÂY FIBARO ĐANG TRỞ TH
03/05/24, 11:58 pm by sieuviet2020
» Công nghệ Z wave trong hệ thống Smathome
03/05/24, 11:57 pm by sieuviet2020
» Công nghệ Z wave trong hệ thống Smathome
03/05/24, 11:57 pm by sieuviet2020
» Giá barrier tự động mới nhất 2021
03/05/24, 11:57 pm by sieuviet2020
» Lắp đặt barie tự động khu công nghiệp - barrier tự động
03/05/24, 11:57 pm by sieuviet2020
» Giá barie chắn đường tại Bà Rịa - Vũng Tàu
03/05/24, 11:56 pm by sieuviet2020