.:: HI-TECH C Compiler ADC Example ::.
A library for HI-TECH C compiler for reading from ADC ports

Library for HI-TECH C Compiler for analog to digital (ADC) readings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | static volatile unsigned char ADRES @ 0x1E; static volatile unsigned char ADCON0 @ 0x1F; static bank1 unsigned char ADCON1 @ 0x9F; static volatile unsigned char ADCON2 @ 0x9B; void ADCInit() { ADCON2=0b10001010; } unsigned int ADCRead(unsigned char ch) { if(ch>13) return 0; //Invalid Channel ADCON0=0x00; ADCON0=(ch<<2); //Select ADC Channel ADON=1; //switch on the adc module ADCON0bits.GO_DONE=1; //Start conversion while(ADCON0bits.GO_DONE); //wait for the conversion to finish ADON=0; //switch off adc return ADRES; } |