sorry war der falsche code. das war der urspüngliche
Code:
#include <avr/io.h>
uint16_t auswertung (void);
volatile uint16_t wert=0;
int main (void)
{
uint16_t i=0,ergebnis=0;
//Ports initialisieren
DDRD = 0xFF; //Port C als Ausgang für die LED's
PORTD = 0XFF; //Pull Up's aktiviert
while(1)
{
ergebnis = auswertung();
if ( (ergebnis < 512) && (ergebnis > 1) )
{
PORTD = (0b11111111);
}
else PORTD = (0b00000000);
}
}
uint16_t auswertung (void)
{
//Initialisieren
ADCSRA = ((1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0));
ADMUX = (1<<MUX0) ;
//Dummy Auslesung als Warm-Up wie im Tutorial
ADCSRA |= (1<<ADSC);
while (ADCSRA & (1<<ADSC));
//Messung
ADCSRA |= (1<<ADSC);
while (ADCSRA & (1<<ADSC));
wert = ADCL; //ERR
wert += (ADCH<<8); //Alternativ 'wert = ADCW;'
ADCSRA &= ~(1<<ADEN); //ADC Disable
return wert;
}
Lesezeichen