Blame | Last modification | View Log | Download | RSS feed
#include "defines.h"#include "ADC.h"void ADC_Init(void) {ADCON0bits.ADON = 0; // Turn off ADC moduleADCON1bits.ADFM = 1; // Right justified dataADCON1bits.ADCS = 0b110; // A/D conversion clock = FOSC/64ADCON1bits.ADNREF = 0; // Negative reference is VSSADCON1bits.ADPREF = 0b00; // Positive reference is VDD}uint16_t ADC_Read(uint8_t channel) {uint16_t ret;ADCON0bits.CHS = channel; // Set channelADCON0bits.ADON = 1; // Turn ADC on__delay_us(10); // Wait the acquisition timeADCON0bits.GO_nDONE = 1; // Start conversionwhile (ADCON0bits.GO_nDONE == 1); // Wait for conversion to finishret = ADRESH << 8; // Read ADC valueret |= ADRESL;return ret;}