/**
* [url=home.php?mod=space&uid=247401]@brief[/url] This API configures ADC module to be ready for convert the input from selected channel
* @param[in] u8OpMode Decides the ADC operation mode. Valid values are:
* - \ref ADC_SINGLE :Single mode.
* - \ref ADC_CONTINUOUS :Continuous scan mode.
* @param[in] u8ChMask Channel enable bit. Each bit corresponds to a input channel. 0 is channel 0, 1 is channel 1..., 7 is channel 7.
* VBG means band-gap voltage, VTEMP means temperature sensor, VLDO means LDO voltage.
* [url=home.php?mod=space&uid=266161]@return[/url] None
* [url=home.php?mod=space&uid=536309]@NOTE[/url] ML51 series MCU ADC can only convert 1 channel at a time. If more than 1 channels are enabled, only channel
* with smallest number will be convert.
* @exmaple : ADC_Open(ADC_SINGLE,0);
*/
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;
}
}
这个是官方的库函数,我们看CASE0,跟其他的不同,那个我们可以理解成省略了ADCCON0|=0x00;
但是后面这个AINDIDS=0xFE;省略前面的SFRS=0x01;是不对的吧?因为前面有个SFRS=0x00
|