internal ADC AVR use….

Chip type : ATmega32L
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 512
Programmer : Tommy Agustianto
*****************************************************/

#include <mega32.h>
#include <delay.h>
#include <math.h>
#include <stdio.h>

#define ADC_VREF_TYPE 0x20

unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// Declare your global variables here
union ctoi
{
unsigned char ch;
unsigned int intg;
}result;

void main(void)
{

char str[3];
float flt;
unsigned char res;

PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0xFF;

PORTC=0x00;
DDRC=0x00;

PORTD=0x00;
DDRD=0x00;

TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

MCUCR=0x00;
MCUCSR=0x00;

TIMSK=0x00;

UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

ACSR=0x80;
SFIOR=0x00;

ADMUX=ADC_VREF_TYPE;
ADCSRA=0x86;

lcd_init(16);
ADCSRA = 0xFF;
while (1)
{
res = read_adc(0);
flt = (float)res/51;
sprintf(str,”Ch0: %2.3f V”,flt);
printf(“\n\r%s”,str);
delay_ms(500);
lcd_clear();
lcd_puts(str);
};
}

Advertisements
internal ADC AVR use….

One thought on “internal ADC AVR use….

Leave a Reply

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