本帖最后由 andy520520 于 2018-9-26 19:11 编辑
我用的是MC97F6108A,SOP20的单片机,此单片机是51核,现在出现AD读出的数据错误
以下是设置:
void ad_init(void)
{
ADCM1 = 0x05; // fx/4, 时钟, fx = 8MHZ ,左对齐
ADCM = 0x00;// PSR2 = _1010_0011; // P17,P20,P02,P01 as analog port
}
unsigned int get_ad_value(unsigned char ad_ch) // 8us
{
uint16_t AdcVal;
ADCM &= ~0x0f;
ADCM |= ad_ch;
//--------------------------
ADCM &= ~ADST; // stop ADC
nop();
ADCM |= ADST; // start ADC
while(!AFLAG);
AdcVal = (ADCRH << 8) | ADCRL;
// AdcVal >>= 4; // ×ó¶ÔÆë
return AdcVal;
}
|