PIC18F4550 ADC example with CCS PIC C compiler

The microcontroller PIC18F4550 has 13 ADC (Analog to Digital Converter) channels. The resolution of the PIC18F4550 ADC is 10-bit, which means the analog value after conversion is stored as a 10-bit number that varies from 0 to 1023 (0x3FF). 
The analog reference voltage is software selectable to either the device’s positive and  negative supply voltage (VDD and VSS) or the voltage level on the RA3/AN3/VREF+ and RA2/AN2/VREF-/CVREF pins.
The ADC converter has a unique feature of being able to operate while the device is in Sleep mode. To operate in Sleep, the ADC conversion clock must be derived from the ADC’s internal RC oscillator.

PIC18F4550 ADC example with CCS C compiler:
This example shows how to analog data from analog input and display this reading as digital on LCD display as shown in the circuit schematic below:
PIC18F4550 ADC example circuit
The internal oscillator of PIC18F4550 is used at 8MHz and MCLR pin function is disabled.
The LCD used to display the analog value after conversion where channel 0 (RA0) is the analog input and analog signal can be changed from the potentiometer. The output analog voltage of the potentiometer varies from 0V to 5V.
The reference voltage is set to VDD (+5V) and GND.
To know how to use LCD display with PIC18F4550 microcontroller see the following topic:
PIC18F4550 interface with LCD using CCS PIC C compiler

PIC18F4550 ADC example C code:
This is the C code used for this example with some comments. It was tested with CCS C compiler version 5.051.

PIC18F4550 ADC example video:
The following video shows our example in a real hardware circuit.

Reference:
PIC18F4550 datasheet from Microchip

One comment

  1. Hello sir,
    i try to display float value.but in c18 compiler i cnt display float value,if you have any idea please help me.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.