[En-Nut-Discussion] analog input

Lars Andersson lakab at telia.com
Thu Mar 11 22:22:50 CET 2004


Yep,

I have both originally written and tried this code.

Regards, 
Lars H. Andersson

> -----Original Message-----
> From: en-nut-discussion-bounces at egnite.de 
> [mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of 
> Sigurd Kleppan
> Sent: Thursday, 11 March, 2004 14:38
> To: en-nut-discussion at egnite.de
> Subject: Re: [En-Nut-Discussion] analog input
> 
> 
> 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 you're looking for faster.
> 
> 
> 
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
> 




More information about the En-Nut-Discussion mailing list