本帖最后由 henxiano 于 2019-8-17 16:35 编辑
这个IC 的ADC只能一次使用一个吗,每次配置第二个ADC之后读取会出错。
Trigger_ADC_Convertion();
Set_ADC_Input_Mode(E_CHANNEL0); // Set ADC0 (P0.1 default) is input only mode
ADC_Channel_Sel(E_CHANNEL0); // ADC Channel Select (P0.1 default)
u16ADCL = ADCCON0;
u16ADCL = u16ADCL >> 6; // ADC[1:0]
u16ADC = ADCH;
u16ADC = (u16ADC << 2 ) + u16ADCL; // ADC[9:2] + ADC[1:0]
Set_ADC_Input_Mode(E_CHANNEL4); // Set ADC4 (P0.5 default) is input only mode
ADC_Channel_Sel(E_CHANNEL4); // ADC Channel Select (P0.5 default)
u16ADCL_4 = ADCCON0;
u16ADCL_4 = u16ADCL_4 >> 6; // ADC[1:0]
u16ADCH_4 = ADCH;
u16ADC_4 = (u16ADCH_4 << 2) + u16ADCL_4; // ADC[9:2] + ADC[1:0]
if(u16ADC<24){
P14 = 1;
}
else if(u16ADC>24){
P14 = 0;
}
这个代码,如果去掉
Set_ADC_Input_Mode(E_CHANNEL4); // Set ADC4 (P0.5 default) is input only mode
ADC_Channel_Sel(E_CHANNEL4); // ADC Channel Select (P0.5 default)
u16ADCL_4 = ADCCON0;
u16ADCL_4 = u16ADCL_4 >> 6; // ADC[1:0]
u16ADCH_4 = ADCH;
u16ADC_4 = (u16ADCH_4 << 2) + u16ADCL_4; // ADC[9:2] + ADC[1:0]
就可以正常,否则P14一直都是1 |