前两天用MEGA48PA测试程序,发现两个AD通道数据是一样的。搜到一个帖子https://bbs.csdn.net/topics/330077433看了也没解决,最后翻DATASHEET找到原因了。按着改了一下还真解决了。
DATASHEET里有下面这句话:
If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read ADCH. Otherwise,ADCL must be read first, then ADCH, to ensure that the content of the Data Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is read, neither register is updated and the result from the conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers is re-enabled.
意思就是需要先读取 ADCL的值再读取 ADCH的值,才可以刷新。 如果反过来 后读 ADCL,其实是第二次刷新的值。在读取 ADCH之前,里面的值是锁定不变的。