Created
May 14, 2019 10:32
-
-
Save avr-programmierung/71e3bc7009f0eefb6d61f9c5c73b23f0 to your computer and use it in GitHub Desktop.
ATmega88 @ 1MHz ADC-Wandlung
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* adc_01.c ATmega88 @ 1MHz */ | |
#include <avr/io.h> | |
int main(void) | |
{ | |
uint16_t x, ergebnis; | |
DDRD = 0xFF; // Richtungsregister Port D auf Ausgang | |
//*** Init ADC *** | |
ADCSRA |= (1<<ADEN); // ADC aktivieren | |
ADCSRA |= (1<<ADPS0)|(1<<ADPS1); // Vorteiler auf 8 | |
ADMUX |= (1<<REFS0); // Uref = 5V | |
ADMUX |= (1<<MUX2)|(1<<MUX0); // ADC-Kanal 5 einstellen | |
ADMUX |= (1<<ADLAR); // Ausgabe linksbündig | |
DIDR0 |= (1<<ADC5D); // Dig. Input Kanal ADC5 deaktivieren (spart Strom) | |
//*** Dummy Readout *** | |
ADCSRA |= (1<<ADSC); // Start ADC-Wandlung | |
while (ADCSRA &(1<<ADSC)); // Auf Abschluss der Konvertierung warten | |
x = ADC; // Das Ergebnis der 1.Wandlung in x speichern | |
while(1) | |
{ | |
ADCSRA |= (1<<ADSC); // Start ADC-Wandlung | |
while (ADCSRA &(1<<ADSC)); // Auf Abschluss der Konvertierung warten | |
ergebnis = ADCH; // Inhalt von ADCH in ergebnis speichern | |
PORTD = ergebnis; // Wandlungsergebnis am Port D ausgeben | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment