给AD口输入0v电压,但经过AD转换后,结果寄存器的值160 左右,不为0,请各位指教:具体程序如下:
static void Adc_init(void)
{
ADCON1bits.ADCS = 0b010;//AD conveter clock choose
//TRISAbits.TRISA3 = 1; //Set the port A3 as Input
TRISB0 = 1; //Set as input
ANSB0 =1; // Set as analog input
ADCON1bits.ADPREF = 0b00; //reference votage choose
ADCON1bits.ADFM =1;//output right allain
}
Uint ADkey(void)
{
ADCON0bits.CHS = 0b01100; //AD channel choose
Uint ADC_Result = 0;
ADCON0bits.ADON =1; //enable AD convertion
Delay(20);
ADCON0bits.GO_nDONE =1; //start the ADC
while(ADCON0bits.GO_nDONE == 1);
ADC_Result = ADRES0L; //get the low result;
ADC_Result = ADRES0L + (ADRES0H<<6)*4; //get the result
return (ADC_Result);
} |