|
发表于 2006-9-11 11:50:00
|
显示全部楼层
<DIV class=quote><B>以下是引用<I>freshman123</I>在2006-5-12 9:58:00的发言:</B>
大家帮忙看看s3c44b0x的AD启动程序:
rADCCON=0x1|(0x0<<2); //开始A/D转换
问题:这里直接用rADCCON=0x1不就可以了吗?
while(rADCCON&0x1); //为避免第一个标志位有错
问题:这条指令又是什么意思? </DIV>
你看一下源码:
unsigned short Read_Adc(unsigned char ch)
{
int i;
static int prevCh=-1;
if(prevCh!=ch)
{
rADCCON = 0x1|(ch<<2); //设置AD转换通道
for(i=0;i<150;i++); //最小15uS
}
rADCCON=0x1|(ch<<2); //开始AD转换
while(rADCCON & 0x1); //避免标志FLAG错误
while(!(rADCCON & 0x40)); //等待AD转换结束
for(i = 0; i < rADCPSR; i++); //避免第二次标志FLAG错误
prevCh=ch;
return rADCDAT; //返回AD转换值
}
它这里是 rADCCON=0x1|(ch<<2); //开始AD转换
如果你直接用rADCCON=0x1,那就是把AD输入通道指定为0通道。那如果用别的通道的话这段程序就不能用。所以它这儿用的语句是rADCCON=0x1|(ch<<2);
第二个问题我也不明白,看那个SPEC上说:
The ADC converter state flag(ADCCON[6], FLAG bit) is not correct. The FLAG operates incorrectly in the following
cases:
a) The FLAG will be 1 for one ADC clock time just after the ADC conversion is started. This is not correct.
b) The FLAG will be 1 one ADC clock time ago than the ADC conversion is completed. This is not correct.
This problem will be shown conspicuously only if the ADCPSR is large. To read ADC converted data correctly ,
please refer to the following codes;
rADCCON=0x1|(0x0<<2); //Start A/D conversion
while(rADCCON &0x1); //To avoid The first FLAG error case.
//(The START bit is cleared in one ADC clock.)
while(!(rADCCON & 0x40));
for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
Uart_Printf("A0=%03xh ",rADCDAT);
照上面的意思,在执行完rADCCON=0x1|(0x0<<2); 后ADCCON的FLAG位被置1了,但这不应该的,我觉得在这条语句之后加上rADCCON&=0x1才对,那样才能改rADCCON里的值,如果是while(rADCCON &0x1);rADCCON的值永远也改不了。请老手指点。
我最近也在学习S3C44BOX,想共同探讨的朋友加我。QQ:58576410,MSN: wangx_nj@hotmail.com |
|