www.pudn.com > iccavr_lib.rar > adc.c, change:2002-02-05,size:1023b


/* 
**  Purpose:    ADC init & read routines without interrupt. 
** 
**  Version:    1.0.0, 7:th of October 1999 
** 
**  Author:     Lars Wictorsson 
**              LAWICEL / SWEDEN 
**              http://www.lawicel.com   lars@lawicel.com 
** 
**  History:    1999-10-07  Created 
*/ 
 
#include <io8535.h> 
 
void InitADC( void) 
{ 
    ADMUX = 0;          // Select channel 0 
    ADCSR = 0xC0;       // Enable ADC & start 1:st dummy conversion 
} 
 
int ReadADC( unsigned char channel) 
{ 
    int i; 
 
    ADMUX = channel;                        // Select channel 
     
    ADCSR |= 0x40;                          // Start conversion 
     
    while (!(ADCSR & 0x10));                // Check if converstion is ready 
     
    ADCSR |= 0x10;                          // Clear Conversion ready flag by setting the bit 
 
    i = ADCL;                               // Read 8 low bits first (important) 
    i += (int)ADCH << 8;                    // Read 2 high bits and multiply with 256 
 
    return i; 
}