TCS Pune

PIC16 XC8 ADC Reader

MPLAB XC8

PIC16 XC8 ADC Reader

Read a PIC16 analogue channel and transmit the value over UART.

IDE: MPLAB X IDE with XC8 compilerBoard/MCU: PIC16F877A trainer or compatible target

Project files

Download project ZIP
Starter — main.c
#include <xc.h>
void main(void){ /* TODO: configure ADC and UART */ while(1){} }
Completed — main.c
#include <xc.h>
#define _XTAL_FREQ 20000000UL
void main(void){ TRISAbits.TRISA0=1; ADCON1=0x0E; ADCON0=0x01; while(1){ GO_nDONE=1; while(GO_nDONE); unsigned int value=((unsigned int)ADRESH<<8)|ADRESL; (void)value; __delay_ms(100); }}

Toolchain and dependencies

IDE requirements

MPLAB X IDE with XC8 compiler

Compatible targets

PIC16F877A trainer or compatible target

Libraries/dependencies

  • Device family pack for selected PIC16

Serial output examples

Serial Monitor

ADC=000
ADC=512
ADC=1023

Serial Plotter

Compiler-error explanations

(192) undefined identifier GO_nDONE

Likely cause: Register bit name differs for selected device/header

Fix: Check the exact device datasheet and XC8 header

__delay_ms requires _XTAL_FREQ

Likely cause: Clock macro is missing

Fix: Define _XTAL_FREQ to the real oscillator frequency

Submit your code

Log in to edit the starter files and submit your solution for instructor review.

Log in to submit
Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA