I have an analog-digital reading issue on AN0 with 18F24k50. The ADC values in the serial terminal are not showing however other UART_Write is OK. I am not sure if the config of the controller is correct on the analog input. Please check the code and the schematics and if you have any suggestion I would appreciate. Thank you in advance.
Code: Select all
unsigned int adc_result;
char text;
void main() {
TRISA = 0b00000001; // AD conversion pdf 293
ANSELA = 0b00000001; // AN0
//ADCON1 = 0; // pdf 295
//ADCON0 = 1;
//CM1CON0.C1ON = 0; // pdf 307
//CM2CON0.C2ON = 0;
LATA = 0;
PORTA = 0;
LATB = 0;
TRISB = 0;
PORTB = 0;
LATC = 0;
TRISC = 0;
PORTC = 0;
UART1_Init(9600);
Delay_ms(100);
UART1_Write_Text("UART init");
UART1_Write('\r');
ADC_Init();
UART1_Write_Text("ADC init");
UART1_Write('\r');
delay_ms(10);
adc_result = ADC_Read(0);
UART1_Write_Text("ADC0 read");
UART1_Write('\r');
IntToStr(adc_result, text);
UART1_Write_Text(text);
UART1_Write('\r');
UART1_Write_Text("ADC0 value send to terminal");
UART1_Write('\r');
}
Bonca