aboutsummaryrefslogtreecommitdiffstats
path: root/adc.c
blob: 81913acf9f5848c3447adcdb45ddd2bf7e4613ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
}