unsigned long adc_value; //Declaration of adc_value (variable)
unsigned char hit1, hit2,hit3,hit4; //Declaration of hit (variable)
void main()
{
ADCON1=0x82;
TRISA=0XFF;
Lcd_Init();
lcd_cmd(_LCD_CLEAR);
lcd_cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,"VOLT METER");
lcd_out(2,1,"VOLT:");
for(;
{
adc_value=ADC_Read(0); // Get AN0 PIN
adc_value=adc_value*5000/1023; // Calculate ADC_Read for 4.88 Vdc
hit1=adc_value/1000;
hit2=(adc_value%1000)/100;
hit3=((adc_Value%1000)%100)/10;
hit4=((adc_value%1000)%100)%10;
// lcd_chr(2,11,48+hit1);
if (hit1) // Follow andrew method edaforum
lcd_chr(2,11,48+hit1);
else
lcd_chr(2,11, ' ');
lcd_chr_cp(hit2+48);
lcd_chr_cp('.');
lcd_chr_cp(48+hit3);
lcd_chr_cp(48+hit4);
lcd_chr_cp('V');
// lcd_chr(2,11, ' ');
delay_ms(20);
}
}