Bit 7 = 0
bit 6 = 0
bit 5 = 0 for VSS 1 VREF-(AN2)
bit 4 = 0 for VDD 1 VREF+(AN3)
bit 3 = 1 \
bit 2 = 1 \
bit 1 = 1 / these set the pin you want to use
bit 0 = 0 /
ADCON1 = 0b00001110
Just like this
#include <htc.h>
#include <math.h>
#include "lcd.h"
#pragma config WDT = OFF
#pragma LVP = OFF
#pragma OSC = INTIO67
//Simple Delay Routine
void Wait(unsigned int delay)
{
for(;delay;delay--)
__delay_us(100);
}
//Function to Initialise the ADC Module
void ADCInit()
{
//We use default value for +/- Vref
//VCFG0=0,VCFG1=0
//That means +Vref = Vdd (5v) and -Vref=GEN
//Port Configuration
//We also use default value here too
//All ANx channels are Analog
/*
ADCON2
*ADC Result Right Justified.
*Acquisition Time = 2TAD
*Conversion Clock = 32 Tosc
*/
ADCON2=0b10001010;
}
//Function to Read given ADC channel (0-13)
unsigned int ADCRead(unsigned char ch)
{
if(ch>13) return 0; //Invalid Channel
ADCON0=0b00001011; //Select ADC Channel
ADCON1=0b00001110;
ADON=1; //switch on the adc module
GODONE=1;//Start conversion
while(GODONE); //wait for the conversion to finish
ADON=0; //switch off adc
return ADRES;
}
void main()
{
//Let the LCD Module start up
Wait(100);
//Initialize the LCD Module
LCDInit(LS_BLINK);
//Initialize the ADC Module
ADCInit();
//Clear the Module
LCDClear();
//Write a string at current cursor pos
LCDWriteString("Temperature:");
LCDWriteStringXY(4,1,"Degree C");
/* while(1)
{
unsigned int val; //ADC Value
unsigned int t; //Temperature
val=ADCRead(0); //Read Channel 0
//t=round(val*0.48876);//Convert to Degree Celcius
t=round(val*100);
LCDWriteIntXY(0,1,t,3);//Prit IT!
Wait(1000);
}
*/
while(1)
{
unsigned int val;
unsigned int t; //Temperature
val=ADCRead(0); //Read Channel 0
//voltage= ((val)/1100)*5;
//The above formula give voltage in Volts, to get Voltage in mili Volts (mV) we must multiply it with 1000, so
//voltage=((val)/1100)*5*1000); //Voltage is in mV
//since (1/220)mV = 1 degree, to get temperature we must divide it by 1/220, so
//t=((val)/1100)*5*1000*220); //t is in degree centigrade
//simplifying further we get
//t=((val/1100)*1100000);
//t=(val*1000);
//we round off this value, so
t=round(val*1000);
LCDWriteIntXY(0,1,t,3);//Prit IT!
Wait(1000);
}
}
this is all my code now.....any mistake??but still the same my display stay at 000 .....what mistake i might make???