Listing Program
Listing Program
h>
#include <delay.h>
#include <stdio.h>
// Main function
void main(void){
//--------------- Setting IO and peripheral at startup!
sett_regs();
_lcd_ready();
//--------------- Time for going CRAZY (looping forever)..
for(;;){ //mainloop looping forever until ERROR/POWER SHUTDOWN/RST/WDT
ACTIVE
#asm("wdr") //kick your DOG before DEAD! hwahwa... :D
updatetemp();
#asm("nop")
};
}
void updatetemp(void){
if (temporary != read_adc(0)){//bila ada data baru, tampilkan
//ADC = ( Vin * 1024 / Vref )
//misal, temperature LM35 = 30°C, Vin = 300mV = 0.3V,
//jadi nilai ADC = (.3*1024/2.56)=120, 120/30 = 4
//Persamaan bisa disederhanakan dengan output data ADC/4
temperature = read_adc(0)/4; //hanya untuk Vref 2.56
lcd_gotoxy(0,0);
lcd_putsf(" KELOMPOK 4");
lcd_gotoxy(0,1);
sprintf(buffer,"SUHU: %0.1f%cC ",temperature,0xDF);
lcd_puts(buffer);
temporary = read_adc(0);
delay_ms(100);
}
}
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: Free Running
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA2;
SFIOR&=0x1F;
ACSR=0x80;
SFIOR=0x00;