#include<htc.h>#include<pic.h>#define _XTAL_FREQ 20000000void InitADC(void){
ADCON1 =0x80;// Make PORTA and PORTE analog pins// Also, Vref+ = 5v and Vref- = GND
TRISA =0x2f;// Make RA5, RA3, RA2, RA1, RA0 input
TRISE =0x07;// Make RE0, RE1 and RE2 input
ADCON0 =0x81;// Turn on the A/D Converter}unsignedint GetADCValue(unsignedchar Channel){
ADCON0 &=0xc7;// Clear Channel selection bits
ADCON0 |=(Channel<<3);// Select channel pin as ADC input
__delay_ms(10);// Time for Acqusition capacitor // to charge up and show correct value
GO_nDONE =1;// Enable Go/Donewhile(GO_nDONE);// Wait for conversion completionreturn((ADRESH<<8)+ADRESL);// Return 10 bit ADC value}void main(){unsignedint ADC_value =0;
PORTB=0x00;
TRISB =0x00;//PORTB as output
InitADC();//Initializes ADC Module#define Temp35 71#define Temp25 51while(1){
ADC_value = GetADCValue(0);//Reading Analog Channel 0if(ADC_value>Temp35){
RB0=1;}
__delay_ms(30);//Delay}}