Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
If you are using C, here is a sample A/D test program
ADC and Serial UART Test Program
Author: Evan Dudzik
This program is an example of interfacing with two pieces of hardware within the PIC:
the analog to digital converter, and the UART, as well as using interrupts.
The program continuously reads the ADC value, and when it changes, outputs it via serial.
The output can be either a single character (0-255),
or encoded to ASCII decimal for easy viewing in a terminal,
by simply commenting out the appropriate line in the main function.
As a simple test, the program also echos recieved characters back to the host.
This way you can type in a terminal program to check the serial communication.
#pragma DATA 0x2007, 0x3F50//_INTRC_IO & _WDT_OFF & _LVP_OFF
//important bits in SFR's for ADC, UART, and interrupt.
volatile bit go @ ADCON0.GO;
volatile bit gie @ INTCON.GIE;
volatile bit rcie @ PIE1.RCIE;
volatile bit peie @ INTCON.PEIE;
volatile bit rcif @ PIR1.RCIF;
volatile bit trmt @ TXSTA.TRMT;
//interrupt service routine
if(rcif) //UART Recieve Interrupt
data_in = rcreg;
newdata = 1;
rcreg = 0;
//Function: Reads one value from the ADC
//Returns: most significant byte of result
inline char adc_read()
//Function: sends a single byte with the hardware serial UART.
inline void sendbyte(char b)
//Function: Sends a character as ASCII decimal
void senddecimal(char b)
char temp, temp2;