void ADC_Open(unsigned char u8ADCOpMode, unsigned char u8ADCChMask)
{
set_ADCCON1_ADCEN; /* enable ADC circuit*/
switch (u8ADCOpMode) //ADC signle mode or continus mode select
{
case ADC_SINGLE: SFRS=0x00;ADCCON1&=0xEF; break;
case ADC_CONTINUOUS: SFRS=0x00;ADCCON1|=0x10; break;
default: break;
}
switch (u8ADCChMask) //ADC input channel digtial function disable
{
case 0: SFRS=0x00;ADCCON0&=0xF0;AINDIDS=0xFE;MFP_P25_ADC_CH0;P25_INPUT_MODE; break;
case 1: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x01;SFRS=0x01;AINDIDS=0xFD;MFP_P24_ADC_CH1;P24_INPUT_MODE; break;
case 2: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x02;SFRS=0x01;AINDIDS=0xFB;MFP_P23_ADC_CH2;P23_INPUT_MODE; break;
case 3: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x03;SFRS=0x01;AINDIDS=0xF7;MFP_P22_ADC_CH3;P22_INPUT_MODE; break;
case 4: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x04;SFRS=0x01;AINDIDS=0xEF;MFP_P21_ADC_CH4;P21_INPUT_MODE; break;
case 5: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x05;SFRS=0x01;AINDIDS=0xDF;MFP_P20_ADC_CH5;P20_INPUT_MODE; break;
case 6: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x06;SFRS=0x01;AINDIDS=0xBF;MFP_P31_ADC_CH6;P31_INPUT_MODE; break;
case 7: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x07;SFRS=0x01;AINDIDS=0x7F;MFP_P32_ADC_CH7;P32_INPUT_MODE; break;
case VBG: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x08; break;
case VTEMP: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x09; break;
case VLDO: SFRS=0x00;ADCCON0&=0xF0;ADCCON0|=0x0A; break;
}
}
这个是库函数原型。一开始就先EN了。
|