/* includes globales */
#include <xc.h>
#include <plib/usart.h>
#include <plib/adc.h>
#include <stdio.h>
#include <stdlib.h>
/* includes locales */
#include "config_bits.c"
/* declaración de variables globales */
unsigned char MsgFromPIC[] = "\r\nADC value is: ";
int ADCValue = 0;
unsigned char ADCStringVal[4];
/* Declaracion de funciones */
void OpenUSART(unsigned char config,unsigned int spbrg);
void main(void)
{
// configuramos modulo ADC
ADCON1 = 0x0E;
ADCON0 = 0x03;
ADCON2 = 0x9D;
// Configuracion del puerto serie USART
// (frecuencia a la que trabaja el cpu/dbaudrate)/16)-1
// (20.000.000/9600)/16)-1=129
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX & USART_BRGH_HIGH, 129);
ConvertADC();
while(1)
{
ADCValue = ReadADC();
putsUSART(MsgFromPIC);
putsUSART
(itoa( ADCStringVal
, ADCValue
,10)); // convertimos a string }
}