uchar get_AD_result(uchar channel)
{
uchar AD_finished=0;
ADC_RES = 0;
channel &= 0x07;
ADC_CONTR = AD_SPEED;
_nop_();
ADC_CONTR |= channel;
_nop_();
ADC_CONTR |= 0x80;
delay(1);
ADC_CONTR |= 0x08;
AD_finished = 0;
while (AD_finished ==0 )
{
AD_finished = (ADC_CONTR & 0x10);
}
ADC_CONTR &= 0xE7;
return (ADC_RES);
}
把AD的结果通过IO口输出就可以了
这个程序P1.7做AD脚的,你稍微小改下,有什么迷糊的,直接搬下来用就OK了,反正我一直这么用,他也没脾气。
STC的单片机基本都差不多少,自己修改下就可以了
5604ad的
uint GetADCResult(uchar ch)
{ uint temp=0;
ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
delay_us(4); //Must wait before inquiry
while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag
ADC_CONTR &= ~ADC_FLAG; //Close ADC
temp=((temp|ADC_DATA)<<8)&0xff00|ADC_LOW2;
return temp; //Return ADC result
}
/*----------------------------
Initial ADC
----------------------------*/
void InitADC()
{
P1 = P1M0 = P1M1 = 0xff; //Set all P1 as Open-Drain mode
ADC_DATA = 0; //Clear previous result
ADC_LOW2 = 0;
ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
delay_ms(10); //ADC power-on and delay
}