2,6 → 2,7 |
#include "adc.h" |
|
static ADC_DATA adc_data; |
static ADC_DATA *adc_data_p = &adc_data; |
|
void ADC_Init(unsigned char TAD, unsigned char FOSC) { |
TRISAbits.TRISA0 = 1; |
8,8 → 9,8 |
TRISAbits.TRISA1 = 1; |
TRISAbits.TRISA2 = 1; |
|
adc_data.last_channel = 0; |
adc_data.result = 0; |
adc_data_p->last_channel = 0; |
adc_data_p->result = 0; |
|
ADCON0bits.VCFG1 = 0; // VRef- = AVss |
ADCON0bits.VCFG0 = 1; // VRef+ != AVdd |
29,7 → 30,7 |
} |
|
void ADC_Start(unsigned char channel) { |
adc_data.last_channel = channel; |
adc_data_p->last_channel = channel; |
ADCON0bits.CHS = channel; // Set A/D channel |
ADCON0bits.GO_DONE = 1; // Start A/D conversion |
} |
39,7 → 40,7 |
} |
|
void ADC_Interrupt_Handler() { |
adc_data.result = ADRES; |
adc_data_p->result = ADRES; |
} |
|
char ADC_Get_Result(unsigned int* ret) { |
46,7 → 47,7 |
if (ADCON0bits.GO_DONE) { |
return 0; |
} else { |
*ret = adc_data.result; |
*ret = adc_data_p->result; |
return 1; |
} |
} |