aboutsummaryrefslogtreecommitdiffstats
path: root/adc.c
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2019-07-31 21:52:36 -0500
committerWilliam Harrington <kb0iic@berzerkula.org>2019-07-31 21:52:36 -0500
commit477a0be9f2cb250f813b9ec8098d126049866ee3 (patch)
treee58c01929ab7eb58e1e2030aa82c9be555128f35 /adc.c
parente48d3fd9e92263ecf26d2bb619b3606eaa151472 (diff)
Move Adc_Read() function from main to adc source and header.
Diffstat (limited to 'adc.c')
-rw-r--r--adc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/adc.c b/adc.c
index 3278632..81913ac 100644
--- a/adc.c
+++ b/adc.c
@@ -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