大家早上好,我不能用PIC12F1572读取ADC的值。我试图用RA1作为模拟输入,所以我用以下方式初始化ADC模块:ANSELABI
tiTS。ANSA1=1;/选择RA1作为输入电压ADCON0SIT的模拟输入引脚。CHS=0x01;//我使用AN1作为输入ADCONDOWS。ADON=1。/ADC是启用ADCONLIDE。ADCs=0x01;//选择ADC转换时钟选择为FoC/ 8 ADCON1BIT。ADFFM=0x01;//结果是正确的,那么在主循环中,我使用以下函数:未签名int模拟值;/ /用于捕获捕获后的ADC结果,(1){模拟值=Read值();LATA2=1;//L上的延迟(50000);//250MS@=16MHz LababITIT.LATA2=0;//led OFF延迟(50000);//250MS@ FoCC=16MHz }试图用MPLABX和ICD3调试我的代码,我可以看到连接到RA2的ON/OFF切换,但是变量模拟值总是0x00。谢谢你,安德烈。
以上来自于百度翻译
以下为原文
Goodmorning to all,
I'm not able to read a value from ADC with PIC12F1572.
I'm trying to use RA1 as analog input, so I initialized the ADC Module in the following way:
ANSELAbits.ANSA1=1; // Select RA1 as analog input pin for input voltage
ADCON0bits.CHS=0x01; // I'm using AN1 as input
ADCON0bits.ADON=1; // ADC is enabled
ADCON1bits.ADCS=0x01; // select ADC conversion clock select as Fosc/8
ADCON1bits.ADFM=0x01; // results are right justified
Then in the main loop I'm using the following function:
unsigned int AnalogValue; // used to store ADC result after capture
while(1)
{
AnalogValue = Read_ADC_Value();
LATAbits.LATA2 = 1; // LED on
_delay(50000); // 250ms @ Fosc=16MHz
LATAbits.LATA2 = 0; // LED off
_delay(50000); // 250ms @ Fosc=16MHz
}
Trying to debug my code with MPLABX & ICD3, I can see LED connected to RA2 toggling ON/OFF but variable AnalogValue is always 0x0000
Any suggestions will be very appreciated
Thank you
Andrea