Pengetahuan Dasar ADC AVR microcontroller

UNDER CONSTUCTION….  AVR MICROCONTROLLER ADC PROGRAMMING

-AVR ADC TEORY DASAR

-AVR ADC REGISTER

-AVR ADC BASIC PROGRAMMING

admux_registerregister data hasil konversi ADC

adch_adcl_register

register control dan flag ADCSRA

adcsra_reg

SFIOR register

sfior_adc

Sample Circuit

adc_circuit

Kode Sample

#include <mega32.h>
#include <stdlib.h>
#include <lcd.h>
#include <delay.h>

unsigned int data_adc, data_adc1;
char temp[16],temp1[16];

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0X15;
#endasm

#define mode_adc 0×00 ;

#define ADC_VREF_TYPE 0x00

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=( (adc_input | ADC_VREF_TYPE) & 0xff);
//ADMUX=ADC_VREF_TYPE | adc_input;
// 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)
{
PORTD=0xff;
DDRD=0X07;
// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
//ADMUX = ADC_VREF_TYPE & 0xff;
ADMUX=ADC_VREF_TYPE;
ADCSRA=0xA3;
SFIOR&=0x1F;

// LCD module initialization
lcd_init(16);

while (1)
{
lcd_clear( );
lcd_gotoxy(0,0);
lcd_putsf(“kelas-mikrokontrl”);
lcd_gotoxy(0,1);
lcd_putsf(“nilai ADC”);
//=========================================
data_adc=read_adc(0); //baca ADC channel(x)
itoa(data_adc,temp); // converts integer data_adc characters in string temp.
lcd_gotoxy(10,1) ;
lcd_puts(temp);
delay_ms(700);
//=========================================
data_adc1=read_adc(1); //baca ADC channel(x)
itoa(data_adc1,temp); // converts integer data_adc characters in string temp.
lcd_gotoxy(14,1);
lcd_puts(temp);
delay_ms(700);

};
}

Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis untuk pemula.

Posted on 08/07/2013, in AVR, Pemrograman C untuk AVR dgn CodeVision. Bookmark the permalink. Leave a comment.

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: