By | 24/11/2018
Hello sahabat anak Kendali.

pada kesempatan kali ini saya akan menulis artikel tentang Atmega16 / Atmega32, Tutorial Mengakses DHT11 dan LCD I2C 16×2



sebelumnya juga saya sudah menulis Artikel yang berikaitan dengan CVAVR dan DHT11,

namun hanya di tampilkan pada LCD 16×2 tanpa komunikasi I2C, silahkan baca artikelnya Tutorial Mengakses DHT11 dengan CVAVR Atmega 16 / 32 



dan sekarang saya akan menulis tentang tutorial Atmega16 / 32 untuk mengakses DHT11 dan ditampilkan pada LCD i2c 16×2



terlebih dahulu silahkan download library i2c lcd CVAVR di artikel Tutorial Mengakses LCD I2C 16×2 dengan CVAVR

Atmega16 / Atmega32, Tutorial Mengakses DHT11 dan LCD I2C 16x2

Keyword :

Tutorial CVAVR DHT11

DHT11 Atmega16

DHT11 Atmega32

DHT11 Atmega LCD I2C

Cara Mengakses DHT11 CVAVR

berikut adalah skema rangkaian yang saya gunakan.

pin DATA  DHT11   —-  PORTA.0 Atmega32/16

pin GND  DHT11     —-  GND  Atmega32/16

pin VCC  DHT11     —-  5V    Atmega32/16

pin SDA I2C_LCD   —- PORTC.1 Atmega32/16

pin SCL I2C_LCD   —- PORTC.0 Atmega32/16

pin GND I2C_LCD  —- GND Atmega32/16

pin 5V I2C_LCD      —- 5V Atmega32/16

kemudian buatlah program seperti berikut ini :

/*****************************************************

This program was produced by the

CodeWizardAVR V2.05.3 Standard

Automatic Program Generator

© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.

http://www.hpinfotech.com

Project :

Version :

Date    : 11/7/2018

Author  : Chaerul Anam

Company : Unisi Robotik

Comments:

Chip type               : ATmega32

Program type            : Application

AVR Core Clock frequency: 16.000000 MHz

Memory model            : Small

External RAM size       : 0

Data Stack size         : 512

*****************************************************/

#include <mega32.h>

#include <lcd_i2c_cvavr.h>

#include <delay.h>

#include <stdio.h>

#include <stdint.h>

#include <stdlib.h>

// Declare your global variables here

#define PIN_DHT11 0

char buff[10];

uint8_t c=0, I_RH, D_RH, I_TEMP, D_TEMP, CheckSum;

int i;

void Req()

{

DDRA |= (1<<PIN_DHT11);

PORTA &= ~(1<<PIN_DHT11);

delay_ms(20);

PORTA |= (1<<PIN_DHT11);

}

void Resp()

{

DDRA &= ~(1<<PIN_DHT11);

while(PINA & (1<<PIN_DHT11));

while((PINA & (1<<PIN_DHT11))==0);

while(PINA & (1<<PIN_DHT11));

}

uint8_t receive_data()

{

    for (i=0; i<8; i++){

        while ((PINA & (1<<PIN_DHT11))== 0);

        delay_us(30);

        if (PINA & (1<<PIN_DHT11))

        c=(c<<1)|(0x01);

     

        else

        c=(c<<1);

     

        while(PINA & (1<<PIN_DHT11));

        }

        return c;

    } 

 

void baca_dht(){

Req();

Resp();

I_RH = receive_data();

D_RH=receive_data();

I_TEMP=receive_data();

D_TEMP=receive_data();

CheckSum =receive_data();

}

 

void main(void)

{

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

// Port B initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=0xFF

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: Timer1 Stopped

// Mode: Normal top=0xFFFF

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x05;

TCNT1H=0xC2;

TCNT1L=0xF7;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer2 Stopped

// Mode: Normal top=0xFF

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: Off

// INT1: Off

// INT2: Off

MCUCR=0x00;

MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x00;

// USART initialization

// USART disabled

UCSRB=0x00;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

// ADC initialization

// ADC disabled

ADCSRA=0x00;

// SPI initialization

// SPI disabled

SPCR=0x00;

// TWI initialization

// TWI disabled

TWCR=0x00;

lcd_clear();

lcd_begin(0x3F, 16,2);

            lcd_clear();

            lcd_gotoxy(0,0);

            lcd_print(“Humidity : “);

            lcd_gotoxy(0,1);

            lcd_print(“Temp : “);

while (1)

      {

      // Place your code here

 baca_dht();             

       lcd_clear(); 

   

            lcd_gotoxy(0,0);

            lcd_print(“Humidity : “);

            lcd_gotoxy(0,1);

            lcd_print(“Temp : “); 

         

      if ((I_RH + D_RH + I_TEMP + D_TEMP) != CheckSum){

      lcd_gotoxy (0,0);

      lcd_print(“error”);

      }

   

     else {

 itoa(I_RH,buff);

   lcd_gotoxy(11,0);

   lcd_print(buff);

   lcd_print(“.”);

 

   itoa(D_RH,buff);

   lcd_print(buff);

   lcd_print(“%”);

   itoa(I_TEMP,buff);

   lcd_gotoxy(6,1);

   lcd_print(buff);

   lcd_print(“.”);

 

   itoa(D_TEMP,buff);

   lcd_print(buff);

   lcd_print(“C “);

 

   itoa(CheckSum,buff);

   lcd_print(buff);

   lcd_print(” “);

            }

            delay_ms(10);

        }

     }

DOWNLOAD FILE PROJECT CODE CVAVR

nah mungkin cukup sekian dulu artikel kali ini, jika ada yang ingin ditanyakan silahkan bisa komentar dibawah, atau hubungi via EMAIL.

jangan lupa untuk berbagi artikel ini di sosial media kamu.

Leave a Reply

Your email address will not be published. Required fields are marked *