This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc2530 光敏传感器adc转换问题!!

协议栈是2.5.1-a,想利用热敏电阻接P0_5,以下是我用来读取adc的值

uint16 ReadLightData( void )
{
  uint16 reading = 0;

  uint16 total = 0; 

  int i;
  P0SEL &= ~0x20;//设置为普通IO
  P0DIR &= ~0x20; // 设置P0.5为输入方式
  asm("NOP");asm("NOP");

for(i = 0; i < 4; i++)
{
APCFG |= 1 << 5 ; //注意这里是设置ADC输入通道!!
ADCCON3 = 0x80|0x20|0x05;   //AVDD5参考电压 10位分辨率  通道5使能
ADCCON1 |= 0x30;//手动模式
ADCCON1 |= 0x40; //开启单通道ADC

while(!(ADCCON1 & 0x80)); //等待AD转换完成

reading = ADCL;
 
reading |= ((uint16) ADCH) << 8;


reading >>= 6;
 
total += reading;
}
total >>= 2; //求4次平均值
return total;
}

这样得出来的adc值,在不懂光敏电阻情况下,输出值也是时大时小,有0-1000浮动,本以为adc这东西最简单了,搞了一天都这样,真郁闷!!!