//基准界说
#defineAD_ref_vref0x00//基准Vref
#defineAD_ref_avcc0x40//基准AVCC
#defineAD_ref_vref_in0xc0//基准内部Vref
#defineAD_refAD_ref_vref
//常量界说
//单端通道,不扩大
#define AD_SE_ADC0 0x00//ADC0
#define AD_SE_ADC1 0x01//ADC1
#define AD_SE_ADC2 0x02//ADC2
#define AD_SE_ADC3 0x03//ADC3
#define AD_SE_ADC4 0x04//ADC4
#define AD_SE_ADC5 0x05//ADC5
#define AD_SE_ADC6 0x06//ADC6
#define AD_SE_ADC7 0x07//ADC7
//界说AD端口变量
#define AD_TEMPAD_SE_ADC0//ADC0
#define AD_VOUTAD_SE_ADC1//ADC1
#define AD_KEYINAD_SE_ADC2//ADC2
#defineAD_VINAD_SE_ADC3//ADC3
#define AD_IOUTAD_SE_ADC4//ADC4
#define AD_6BATAD_SE_ADC5//ADC5
#defineBAT_SE_PORTPORTB
#defineBAT_EN_PORTPORTB
#defineBAT_EN_PIN0X03
void adc_init(void)
{
DDRA=0x00;
ADCSRA=(1<
//ADMUX=(1< //DIDR0=(1<
} unsigned int read_adc(unsigned char adc_input,unsigned char i)//查询办法读取ADC单端通道 { unsigned charx; unsigned inty=0; ADC=0; ADMUX=(AD_ref|adc_input);//adc_input:单端通道 0x00~0x07,0x1E,0x1F //0xc0:挑选内部2.56V参阅电压 delay_nus(100); for(x=0;x
{ ADCSRA|=(1<
loop_until_bit_is_set(ADCSRA,ADIF);//办法1 等候AD转化完毕 //while ((ADCSRA&(1<
//loop_until_bit_is_clear(ADCSRA,ADSC);//办法2 检测ADSC=0也行 ADCSRA|=(1<
y += ADC;//ADC=ADCH:ADCL } return y; }