本帖最后由 ilovezqh 于 2017-7-19 13:22 编辑
uint16 advGet(uint8 iAdCh)
{
uint16 uiRet;
ADCON1 = B1010_0000;/* Left justified;VREF is connected to VDD; ADC Conversion Clock:FOSC/32 */
ADCON0 = B0000_0001 | (iAdCh << 2);
ADIE = 0;
ADIF = 0;
/* Need Add time for caiyang*/
// delayUs(200);
ADRESL = 0;
ADRESH = 0;
__delay_us(10);
ADGO = 1;
while(ADGO);
uiRet = ADRESL;
uiRet += (ADRESH << 8);
return uiRet;
}
void main(void)
{
uint8 i;
uint16 uiBat;
uint16 uiTemp;
uiTemp = advGet(BAT1_AD_CH);
uiTemp = advGet(BAT2_AD_CH);
for(i=0;i<8;i++)
{
uiBat += advGet(BAT3_AD_CH);
}
uiBat >>= 3;
uiTemp = advGet(BAT4_AD_CH);
/* 为什么我得到的uiBat是错误的,求高手解答 */
} |