C8051F310 的 ADC 讀取問題?
最近寫了個測試程式發覺有點怪怪的,想請問我是不是使用方式有誤呢?
問題點:
我讀取Temperature Sensor的時候,只有第一筆出來的值是正確的(0x01b5左右),而輸出的值都會是0x0000~0x0001很詭異!?我也試著去讀取 Vdd 過,也是類似情況,第一筆是0x03c8,而後都是0x03ff不變!
附上我的程式碼看看是否有誤呢?
void ADC_Init(void)
{
REF0CN = 0x0A; /* Set voltage reference to "internal" */
ADC0CF = 0xF9; /* Set analog amp gain to 1.0 */
AMX0P = 0x1F; /* Set positive MUX to pin 0 */
AMX0N = 0xFF; /* Set negative MUX to ground */
AD0EN = 1; /* Set AD1EN to activate the ADC */
}
int Read_ADC( char ch ) {
int result = 0x0000;
// Valid ADC Channel
if( ch < 0x20 ) {
AMX0P = ch;
AD0BUSY = 1;
// Wait For ADC Complete
while( !AD0INT );
result = (ADC0H << 8) + ADC0L;
AD0INT = 0;
}
return result;
}