Analog to Digital convertor ADC source code (C lang on PIC18, HiTech compiler,MPLAB)

Thread Starter

JK-FlipFlop

Joined Jul 5, 2010
111
I have made this code for those who doesn't know how to program a A2D converter on PIC18 series. (with HITECH compiler and MPLAB)

Rich (BB code):
#include <adc.h>
#include <hitech.h>
#include <pic18.h>
int ADC_VALUE; /* The value from the analog - digital convertor */
main()
{
TRISA=0x3f; /* PORTA as Anlog input */
TRISD=0x00; /* PORTD as output */
while(1) /* loop */
{
ADCON0=0b1000011; /* config : http://roboticsforyou.blogspot.com/2008/02/pic16f877a-programming-analog-digital.html - the osc F bits 7-6 | the channel bits 5-3| start bit2 | none bit 1| A2D on when "1" bit 0| */
ADCON1= 0x00; /* 10 bit / 8 bit convertor when "0x10" 10 bit - "0x00" 8 bit */
 
ADIE  = 0; /* Masking the interrupt */
 ADIF  = 0; /* Resetting the ADC interupt bit */ 
ADRESL = 0; /* Resetting the ADRES value register */
ADRESH = 0; 
GODONE=1;     /* Staring the ADC process */ 
while(GODONE); /* Wait for conversion complete */
ADC_VALUE = (ADRESH); /* Getting HSB of CCP1, in 8 bit mode only ADRESH in 10 bit mode need the ADRESL to perform the first 8 bits, THE ADRESH perform the 8 last bits*/
 
PORTD = ADC_VALUE; /* perform in PORTD the Value */
}
}
for more info: http://roboticsforyou.blogspot.com/2008/02/pic16f877a-programming-analog-digital.html
http://extremeelectronics.co.in/microchip-pic-tutorials/using-analog-to-digital-converter-%E2%80%93-pic-microcontroller-tutorial/
http://www.expertcore.org/viewtopic.php?f=18&t=603
http://www.ermicro.com/blog/?p=1408

I hope it will help for anyone someday...
(Niv the onlyone who belive...)
 
Last edited:
Top