[En-Nut-Discussion] analog input
Sigurd Kleppan
021243 at student.hit.no
Thu Mar 11 14:38:05 CET 2004
Hello!
You can use following code, but i don't know how to set the pin you want to read on PORTF. Someone how knows? Is it just to set the variable chan to example "1" for PIN1 on PORTF????
I have not tried this code...
Someone who has???
#include <io.h>
void ADCSetup(void)
{
// for ATMEGA128
/*
REFS1 = 1; // Use internal 2.56V REF
REFS0 = 1;
ADLAR = 0;
ADEN = 1; // AD converter on
*/
ADCSRA = 0x97;
ADMUX = 0xC0;
}
int ADConvert(short chan)
{
int tmp;
int ADresult;
tmp = ADMUX & ~0x07;
tmp |= chan & 0x7;
ADMUX = tmp; // Set
channel
// maybe delay a little here to settle the MUX
sbi(ADCSRA,ADSC);
// Start ADC
loop_until_bit_is_set(ADCSRA, ADIF); // Wait for ADIF, will
happen soon
ADresult = ADCL; // Read LSB
first
ADresult |= ((int)ADCH) << 8; // then MSB
sbi(ADCSRA,ADIF);
// Clear AD Interrupt Flag
return ADresult;
}
tomek w <twojcikpl at yahoo.com> skrev:
>hi
>what is the easiest way to programm analog input
>any ideas???
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Search - Find what youre looking for faster.
More information about the En-Nut-Discussion
mailing list