Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#include <pic.h>#include <adc.h> // ADC library functionsunsigned int result //where the a/d value will end upvoid main(){TRISA = 0b11111111;OpenADC(ADC_FOSC_2 & ADC_LEFT_JUST & ADC_1ANA_0REF, ADC_CH0 & ADC_INT_OFF);//setup adcSetChanADC(ADC_CH0); //set the a/d converter to sample channel 0 //ADC_CH0 is port a0 / ADC_CH1 is port a1 etc....ConvertADC(); // Start an A/D conversion while(BusyADC()){ // Wait for the conversion to complete//maybe some code for while were waiting (could turn an led on maybe)}//once the conversion is complete, the a/d reading will be in the registers//ADRES and ADRESH - I usually copy these to an intresult = ADRES;result += ADRESH;// The a/d reading value is now stored in the variable result//you can now do something like if(result > 200){do something}}