有关AD的一段代码
其中AD2BUG用于对八路通道循环采样,结果放入长度为80的一个数组中,试验证明有效,AD2BUF_Single_Channel用于对同一条通道采样,结果同样存入数组,可是这时的采样值全部为零!请问什么地方出错。谢谢大家!void AdcRead(u8 channel,u8 *adcvaule)
{
ADCON0 = (channel << 3) | 0x81;// enable ADC
// Delay(3);
Delay(30);
ADGO = 1;
while(ADGO); // wait for conversion complete
*adcvaule = ADRESH;
}
void AD2BUF(void)
{
u8 bufcount;
u8 *mid;
for(bufcount = 0; bufcount < 80; bufcount++) {
AdcRead(bufcount % 8, mid);
Receive_Buffer = *mid;
}
}
void AD2BUF_Single_Channel(u8 channel)
{
u8 bufcount;
u8 *mid;
for(bufcount = 0; bufcount < 80; bufcount++) {
AdcRead(channel, mid);
Receive_Buffer = *mid;
}
} 在PICC中指针编译无错,但是实际上发现是无法有效执行的,因此只要把AdcRead()函数改为返回的形式就应该可以解决问题:
u8 AdcRead(u8 channel)
{
u8 adcvaule;
ADCON0 = (channel << 3) | 0x81;// enable ADC
Delay(30);
ADGO = 1;
while(ADGO); // wait for conversion complete
adcvaule = ADRESH;
return adcvaule;
}
页:
[1]