Re: PIC16F18855 Analog input problem
You seem to be right, there is a copy/paste mistake in the assembly code example attached in message #1.
In the Datasheet, just beside example code, there is comment 1. referring you to study ANSELx register.
(fill in A, B, C ... instead of the x)
I cannot see that there is a lot of complexity.
ADC hardware for this device have a couple of optional counters for automatic precharge and aquisition time. These are not used in the basic mode example.
Instead, the example assume a function: SampleTime to be called to provide a suitable delay.
But there are more mistakes in the example code.
In this device type, the bit controlling result format: ADFRM0 is in ADCON0 register,
not in ADCON1 register, as in some previous PIC device types,
so comment about ';Right justified' result in connection with setting ADCON1 register is wrong.
If you need only 8 bits precision in result, you may leave ADFRM0 bit in ADCON0 register = 0,
and use result value from ADRESH directly.
Also, comment about ';Select channel AN0'
in connection with setting value for ADCON0 register is also wrong.
In this family of PIC devices, selection of Analog input channel is done by ADPCH register,
so selection of AN0 channel in example, is because reset default, not by concious code.
If you do not specifically want to, or are required to program in assembly language,
then setting up ADC registers may just as easily be done in C language.
Device support file:
have symbolic names and bitfield definitions for all the registers in the microcontroller.
By using symbolic names for control bits and registers,
compiler may help by warning you if trying to use a named control bit or field in the wrong register.