/*Basic A/D Libray
  Version 1.0
  (c) 2004 by Malte Marwedel
  www.marwedels.de/malte
  Die Verwendung geschieht auf eigene Verantwortung, es wird nicht garantiert,
  dass diese Datei fehlerfrei ist.
  Die Datei darf frei verwendet werden.
  Änderungen sind erlaubt solage kenntlich gemacht wird, dass es sich
  nicht mehr um die original Datei handelt.
*/

#include <io.h>
#include <inttypes.h>

//proceeds an A/D conversion
uint16_t getadc(uint8_t channel) {
ADMUX = channel; //Kanal wählen (select AD channel)
sbi(ADCSR,ADSC); //Setzt das Bit um die A/D Wandlung zu starten
//wartet, bis die Wandlung komplett ist (waits until the conversion is complete)
while (inp(ADCSR) & BV(ADSC));
return ADCW;
}

//Nur 8 Bit Auflösung
uint8_t getadc8(uint8_t channel) {
uint8_t temp;
ADMUX = channel; //Kanal wählen (select AD channel)
sbi(ADCSR,ADSC); //Setzt das Bit um die A/D Wandlung zu starten
//wartet, bis die Wandlung komplett ist (waits until the conversion is complete)
while (inp(ADCSR) & BV(ADSC));
temp = ADCW >> 2;
return temp;
}
