/********************************** * Function : WORD ReadTemperature(BYTE sensor) * This function have a reading adc values. * The parameter sensor's type shows in below. * ADC_PHOTODIODE(0x01) : photodiode adc value * ADC_CHAMBER(0x02) : chamber temperature adc value * ADC_HEATSINK(0x03) : heatsink temperature adc value * The returned value is sampled in SAMPLING_COUNT times. **********************************/ WORD ReadTemperature(BYTE sensor) { WORD w; BYTE low=0x00; BYTE high=0x00; BYTE counter = SAMPLING_COUNT; // multiple adc sampling WORD sum=0; // Select the ADC Channel by parameter. // The ADC Channel information shows in HardwareProfile -PICDEM FSUSB.h file. switch(sensor) { case ADC_PHOTODIODE: SetADCChannel(Sensor_Photodiode); break; case ADC_CHAMBER: SetADCChannel(Sensor_Chamber); break; case ADC_HEATSINK: SetADCChannel(Sensor_Heatsink); break; } while(counter--) { while(ADCON0bits.NOT_DONE); // Wait for busy ADCON0bits.GO = 1; // Start AD conversion while(ADCON0bits.NOT_DONE); // Wait for conversion low = ADRESL; high = ADRESH; w = (WORD)high*256 + (WORD)low; sum += w; } w = sum/SAMPLING_COUNT; return w; }
int main(void) //main body calls all other functions to initialize the proper values of the Transmission protocol, timer and ADC module, then starts them { InitialzeLCD(); //initializes LCD SetADCChannel(5); // sets ADC channel for temperature sensor InitADC(); // Initializes ADC and timer below to 1 second InitTimer(); startTimer(); startADC(); while(1) { // Main loop } }