A. Rangkaian Simulasi
B. Program
#include
#include stdlib.h
#include lcd.h
#include delay.h
#define kurangi_suhu_kipas PIND.6
#define tambah_suhu_kipas PIND.7
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
int SUHU;
char temp[8];
float suhu_celcius;
unsigned char suhu_kipas,simpan;
eeprom unsigned char p_eeprom;
void tulis_eeprom()
{
p_eeprom=simpan;
}
void baca_eeprom()
{
simpan=p_eeprom;
}
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
PORTB=0xFF;
DDRB=0xFF;
PORTD=0xFF;
DDRD=0xFF;
suhu_kipas=24;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
// LCD module initialization
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("ALAT PENGONTROL");
lcd_gotoxy(0,1);
lcd_putsf("KIPAS DENGAN");
delay_ms(50);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("SENSOR SUHU LM35");
delay_ms(50);
while (1)
{
lcd_clear( );
SUHU = read_adc(3);
suhu_celcius = (float)SUHU*425/1023;//rumus untuk mengubah kedalam derajat celcius
lcd_gotoxy(0,0);
lcd_putsf("SUHU RUANG");
ftoa(suhu_celcius,0,temp);//float to array, mengubah tipedata float k tipe data array yg kan ditampilkan di LCD
lcd_gotoxy(12,0);
lcd_puts(temp);
lcd_gotoxy(14,0);
lcd_putchar(0x89);//menampilkan karakter derajat
lcd_putsf("C");
lcd_gotoxy(0,1);
lcd_putsf("KPS ON SH >");
ftoa(simpan,0,temp);
lcd_gotoxy(12,1);
lcd_puts(temp);
lcd_gotoxy(14,1);
lcd_putchar(0x89);//menampilkan karakter derajat
lcd_putsf("C");
if(kurangi_suhu_kipas==0){suhu_kipas--;delay_ms(300);simpan=suhu_kipas;tulis_eeprom();}
if(tambah_suhu_kipas==0){suhu_kipas++;delay_ms(300);simpan=suhu_kipas;tulis_eeprom();}
baca_eeprom();
//if(kurangi_suhu_kipas==0){suhu_kipas--;delay_ms(300);}
//if(tambah_suhu_kipas==0){suhu_kipas++;delay_ms(300);}
if(suhu_celcius>simpan){PORTB.0=1;}
else PORTB.0=0;
delay_ms(5);
};
}
C. Rangkaian Implementasi
rangkaian simulasi+program dapat di download disini
Tidak ada komentar:
Posting Komentar