Alat Pengukur Kelembaban Tanah
Dengan AVR ATMEGA 8535
Tampilan LCD
Alat ini saya modifikasi dari rangkaian pada soil moisture Tester . Pada
rangkaian tersebut yang menjadi pengolah pembacaan sensor hingga menjadi output
dengan menggunakan IC LM3914. Output yang dihasilkan berupa indikator led,
berjumlah 10. Pada alat yang saya buat, menggantikan IC LM3914 dan indikator
led dengan sebuah mikrokontroler dan LCD 2×16. Secara dasar input sebuah sensor
berupa sinyal analog yang nantinya diubah menjadi sinyal digital.
1. Modul DT-AVR (Low Cost Micro System) + isp programmer dari Innovative Electronics
1. Modul DT-AVR (Low Cost Micro System) + isp programmer dari Innovative Electronics
2. LCD 2×16
3.
CodevisionAVR
4. Sensor
Berikut
listing programnya
#include
<mega8535.h>
#include <stdio.h>
#include <delay.h>
#include <stdio.h>
#include <delay.h>
//
Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0×18 ;PORTB
#endasm
#include <lcd.h>
#asm
.equ __lcd_port=0×18 ;PORTB
#endasm
#include <lcd.h>
#define
ADC_VREF_TYPE 0×60
char buf[33];
unsigned char dtadc;
unsigned char dtadc;
// Read the
8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0×40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0×10)==0);
ADCSRA|=0×10;
return ADCH;
}
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0×40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0×10)==0);
ADCSRA|=0×10;
return ADCH;
}
void
tampil(unsigned char dat)
{
unsigned char data;
data = dat / 100;
data+=0×30;
lcd_putchar(data);
{
unsigned char data;
data = dat / 100;
data+=0×30;
lcd_putchar(data);
dat%=100;
data = dat / 10;
data+=0×30;
lcd_putchar(data);
data = dat / 10;
data+=0×30;
lcd_putchar(data);
dat%=10;
data = dat + 0×30;
lcd_putchar(data);
data = dat + 0×30;
lcd_putchar(data);
}
void
display()
{
if (dtadc==0){
lcd_gotoxy(0,0);
lcd_putsf(“ “);
}
if ((dtadc>1) && (dtadc<=10)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>10) && (dtadc<=20)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>20) && (dtadc<=30)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>30) && (dtadc<=40)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>40) && (dtadc<=50)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>50) && (dtadc<=60)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>60) && (dtadc<=70)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>70) && (dtadc<=80)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>80) && (dtadc<=90)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>90) && (dtadc<=100)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(” “);
}
{
if (dtadc==0){
lcd_gotoxy(0,0);
lcd_putsf(“ “);
}
if ((dtadc>1) && (dtadc<=10)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>10) && (dtadc<=20)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>20) && (dtadc<=30)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>30) && (dtadc<=40)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>40) && (dtadc<=50)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>50) && (dtadc<=60)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>60) && (dtadc<=70)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>70) && (dtadc<=80)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>80) && (dtadc<=90)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(“ “);
}
if ((dtadc>90) && (dtadc<=100)){
lcd_gotoxy(0,0);
sprintf(buf,”\xff”);
lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);lcd_puts(buf);
lcd_putsf(” “);
}
}
// Declare
your global variables here
void
main(void)
{
// Declare your local variables here
{
// 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
PORTA=0×00;
DDRA=0×00;
// 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
PORTA=0×00;
DDRA=0×00;
// Port B
initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0×00;
DDRB=0xFF;
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0×00;
DDRB=0xFF;
// 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=0×00;
DDRC=0×00;
// 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=0×00;
DDRC=0×00;
// 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=0×00;
DDRD=0×00;
// 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=0×00;
DDRD=0×00;
//
Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0×00;
TCNT0=0×00;
OCR0=0×00;
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0×00;
TCNT0=0×00;
OCR0=0×00;
//
Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0×00;
TCCR1B=0×00;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0×00;
TCCR1B=0×00;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;
//
Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0×00;
TCCR2=0×00;
TCNT2=0×00;
OCR2=0×00;
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0×00;
TCCR2=0×00;
TCNT2=0×00;
OCR2=0×00;
// External
Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0×00;
MCUCSR=0×00;
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0×00;
MCUCSR=0×00;
//
Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0×00;
TIMSK=0×00;
// Analog
Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0×80;
SFIOR=0×00;
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0×80;
SFIOR=0×00;
// ADC
initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: On
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0×82;
SFIOR&=0xEF;
SFIOR|=0×10;
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: On
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0×82;
SFIOR&=0xEF;
SFIOR|=0×10;
// LCD
module initialization
lcd_init(16);
lcd_init(16);
// Global
enable interrupts
lcd_gotoxy(2,0);
lcd_putsf(“Alat Pengukur”);
delay_ms(1000);
lcd_gotoxy(0,1);
lcd_putsf(“Kelembaban Tanah”);
delay_ms(1000);
lcd_clear();
lcd_gotoxy(4,1);
lcd_putsf(“%”);
lcd_gotoxy(11,0);
lcd_putsf(“<-Led”);
while (1)
{
dtadc=read_adc(0); // baca data ADC dari ch.0;
lcd_gotoxy(0,1);
tampil(dtadc);
display();
lcd_gotoxy(2,0);
lcd_putsf(“Alat Pengukur”);
delay_ms(1000);
lcd_gotoxy(0,1);
lcd_putsf(“Kelembaban Tanah”);
delay_ms(1000);
lcd_clear();
lcd_gotoxy(4,1);
lcd_putsf(“%”);
lcd_gotoxy(11,0);
lcd_putsf(“<-Led”);
while (1)
{
dtadc=read_adc(0); // baca data ADC dari ch.0;
lcd_gotoxy(0,1);
tampil(dtadc);
display();
// Keterangan
if (dtadc<=50){
lcd_gotoxy(6,1);
lcd_putsf(“Kering “);
}
if ((dtadc>50) && (dtadc<=90)){
lcd_gotoxy(6,1);
lcd_putsf(“Lembab “);
}
if (dtadc>90){
lcd_gotoxy(6,1);
lcd_putsf(“Basah “);
}
if (dtadc<=50){
lcd_gotoxy(6,1);
lcd_putsf(“Kering “);
}
if ((dtadc>50) && (dtadc<=90)){
lcd_gotoxy(6,1);
lcd_putsf(“Lembab “);
}
if (dtadc>90){
lcd_gotoxy(6,1);
lcd_putsf(“Basah “);
}
delay_ms(100);
};
}
};
}
Selamat
mencoba !!!!
sumber referensi dari : http://catatansaad.wordpress.com/2009/11/01/alat-pengukur-kelembaban-tanah-dengan-avr-atmega-8535/
Tolong diberikan sumber acuan/referensinya biar lebih keren.
BalasHapusiya pak....
BalasHapussegera saya konfirmasi lagi kepada teman saya yg posting
thanks