#include<P18F4550.h>
#define RS PORTCbits.RC0
#define En PORTCbits.RC1
void delay()
{
unsigned int q;
for(q=0;q<10000;q++);
}
void lcdcmd(unsigned char value)
{
PORTB=value;
RS=0; //Select command register
En=1; // High to Low pulse on Enable pin of LCD
delay();
En=0;
}
void lcddata(unsigned char value)
{
PORTB=value;
RS=1; //Select data register
En=1; // High to Low pulse on Enable pin of LCD
delay();
En=0;
}
void lcdinit()
{
lcdcmd(0x38); //Call Command subroutine (value=0x38)
delay();
lcdcmd(0x0E);
delay();
lcdcmd(0x01);
delay();
lcdcmd(0x06);
delay();
}
void adcinit(){
TRISAbits.RA0=1;
ADCON1 = 0x01; //Ref voltages Vdd & Vss; AN0 - AN7 channels Analog
ADCON2 = 0x8E; // select result format, acquistion time,clock slect bits
ADCON2bits.ADFM=1;
}
unsigned int ADCRead( unsigned char ch){
ADCON0 = 0x00;//configuring analog channel
ADCON0 = (ch<<2); //selecting analog channel
ADCON0bits.ADON = 1; //switch on adc module
ADCON0bits.GO_DONE =1;//Start conversion
while(ADCON0bits.GO_DONE); //wait for the conversion to finish
ADCON0bits.ADON=0; //switch off adc
return ADRESL;
}
void stringlcd(const char * s)
{
while(*s)
lcddata(*s++);
}
unsigned int deci2ascii(unsigned int mb){
unsigned int ans;
ans= 0x30 | mb;
return(ans);
}
void main()
{
TRISAbits.RA0=1;
TRISB = 0x00; // Configure LED pins (PORT B) as output
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
lcdinit();
lcdcmd(0x80);
unsigned char dt[]="Temperature:";
stringlcd(dt);
unsigned int val;
unsigned int ans,n;
while(1){
lcdcmd(0xC0);
delay();
val=ADCRead(0);
ans= (ADRESL*500)/1023;
n=deci2ascii(ans);
lcddata(n);
lcddata(223);
lcddata('C');
}
}