Anda di halaman 1dari 3

// Sensor di simulasikan oleh variable resistor di hubungkan ke pin ADC chanel 0 (kaki 40

atmega8535)

//Adc : channel 0 (pin 40)

//Compiler: CodeVision

//mengambil data ADC dengan interupt ADC.

// hasil konversi resolusi 10 bit , 00 0000 0000 ~ 11 1111 1111 (3FFH)

#include <mega8535.h>

#include <delay.h>

// Alphanumeric LCD Module functions

#asm

.equ __lcd_port=015 ;PORTC

#endasm

#include <lcd.h>

// ADC interrupt service routine

interrupt [ADC_INT] void adc_isr(void)

unsigned int polutan; //

// 20ms delay

delay_ms(20);

// Start a new AD conversion

ADCSRA|=040;

//data 10 bit hasil konversi disimpan di ADCW


polutan = (unsigned int) ADCW; //rubah type data ADCW ke integer

if(polutan>500)

{ lcd_gotoxy(0,1);

lcd_putsf(berbahaya );

else

{ lcd_gotoxy(0,1);

lcd_putsf(Tidak berbahaya);

lcd_gotoxy(6,0);

lcd_putsf(PPM);

lcd_gotoxy(0,0);

// rubah angka integer ke char Ascii , misal angka 1 -> code ASCII =1 + 30 = 31H

lcd_putchar(polutan/1000 %10 + 030); //menampilkan digit ribuan

lcd_putchar(polutan/100 %10 + 030); //menampilkan digit ratusan

lcd_putchar(polutan/10 %10 + 030); //menampilkan digit puluhan

lcd_putchar(polutan %10 + 030); //menampilkan digit satuan

void main(void)

{
// ADC Interrupts: On

ADCSRA=0x8E;

// LCD module initialization

lcd_init(16);

lcd_gotoxy(6,0);

lcd_putsf(PPM);

// Global enable interrupts

#asm(sei)

// Select ADC input 0

ADMUX=040;

// Start the first AD conversion

ADCSRA|=040;

// All the job is done by ADC interrupts

while (1);

Anda mungkin juga menyukai