// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt1[] = "ADC Example";
char txt[2];
char txt2[5];
unsigned int temp_res;
float data2;
void main() {
ansel=4; // Configure AN2 pin as analog
anselh=0;
c1on_bit=0;
c2on_bit=0;
////////////////////////////////////////////////////////////////
TRISA = 0xFF; // PORTA is input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,txt1);
adc_init();
do {
temp_res = ADC_read(2); // Get 10-bit results of AD conversion
data2 = (temp_res*5)/1023.0;
FloatToStr(data2,txt2);
txt2[5]=0;
Lcd_Out(2,1,txt2);
Delay_ms(1000);
}
while(1) ;
}