diff options
-rw-r--r-- | adc.c | 12 | ||||
-rw-r--r-- | adc.h | 2 |
2 files changed, 14 insertions, 0 deletions
@@ -1,2 +1,14 @@ #include "adc.h" +unsigned int Adc_Read(unsigned int channel) { + ADFM = 1; // results right justified + ADCS0 = 1; //conversion speed = 64*Tosc + ADCS1 = 1; + ADCS2 = 1; + ADCON0bits.CHS = channel; + ADON = 1; // Turn on ADC + __delay_ms(1); + GO_DONE = 1; + while (ADCON0bits.GO_DONE == 1); + return ((ADRESH << 8) + ADRESL); // ex 1024 +}
\ No newline at end of file @@ -1,2 +1,4 @@ #include "conf.h" +// Get ADC value +unsigned int Adc_Read(unsigned int);
\ No newline at end of file |