I'm using PIC18F45K22 as my microcontroller and RA0 wihich is also AN0 as my analog input. Below is my code, please help me to find out the mistakes i've made. The temperature being displayed is always 0
Rich (BB code):
void main(void)
{
init();
while(1)
{
LCDWrite("Room Temp: ",11,0,0);
sprintf(buffer,"%d",(int)temperatureA);
LCDWrite(buffer,2,0,12 );
LCDWrite("'C",2,0,15);
}
}
void interrupt ISR()
{
if((TMR0IE==1)&&(TMR0IF==1))
{
counter++;
if(counter==31)//2 hz osccilatinge
{
//temperature sensor 1
ADCON0=0B00000001; //AN0, ADC on
GO=1; //Start conversion
while(ADCON0bits.GODONE==1); //polling of GO/DONE' bit
result=ADRESL;
resulthi=ADRESH;
resulthi=resulthi<<8;
result|=resulthi;
temperatureA=(char)result*500/1023;//temperature formula for LM35
counter=0;//reset the 1Hz counter
}
}
}