经实际应用下面的程序完全可以用,晶振11.0592M...读出来的数据是送入数组内部,用的时候直接读取数组相应的位就可以了.
void ADC_START(void);
void ADC0(void);
void ADC1(void);
void ADC2(void);
void ADC3(void);
sfr P1M0 = 0x92;
sfr P1M1 = 0x91;
sfr P1ASF = 0x9D;
sfr AD_CONTR = 0xBC;
sfr AD_RES = 0xBD;
sfr AD_RESL = 0xBE;
sfr IPH = 0xB7;
sfr AUXR1 = 0xA2; //AD寄存器数据调整位;
uint16 READ_ADIN_DATA[4]={0,0,0,0};
void ADC_START(void)
{
AD_CONTR = 0x80; //打开AD电源
AD_RES = 0; //清数据存储寄存器
AD_RESL = 0;
//AUXR1 &= 0xFB;
AUXR1 |= 0x04; //设置高低位存储数据;
AD_CONTR |= 0x08; //开始AD转换;
nop(); //延时
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
while((AD_CONTR & 0x10) == 0); //判断AD是否转换成功
AD_CONTR &= 0xE7; //AD停止并清AD标志位;
}
void ADC0(void) //读P10 口AD数据;
{
uint16 Value = 0;
AD_CONTR = 0xE0; //设置P10口为AD输入端
ADC_START(); //调用AD转换函数
Value = AD_RES; //读低8位数据;
Value <<=8;
Value |= AD_RESL; //合成数据;
READ_ADIN_DATA[0] = Value; //合成数据送数组;
}
void ADC1(void)
{
uint16 Value = 0;
AD_CONTR = 0xE1;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[1] = Value;
}
void ADC2(void)
{
uint16 Value = 0;
AD_CONTR = 0xE2;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[2] = Value;
}
void ADC3(void)
{
uint16 Value = 0;
AD_CONTR = 0xE3;
ADC_START();
Value = AD_RES;
Value <<=8;
Value |= AD_RESL;
READ_ADIN_DATA[3] = Value;
}