// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections

char look(int a)
{
  switch(a)
  {
    case 0:
      return '0';
    case 1:
      return '1';
    case 2:
      return '2';
    case 3:
      return '3';
    case 4:
      return '4';
    case 5:
      return '5';
    case 6:
      return '6';
    case 7:
      return '7';
    case 8:
      return '8';
    case 9:
      return '9';
    default:
      return '.';
  }
}

void main()
{
  unsigned int v;
  char *volt = "00.0";
  CMCON = 0x07;
  TRISA = 0xFF;                        // PORTA is Analog input
  PORTA = 0X00;                        // PORTA is clear
  ADCON1 = 0x00;
  Lcd_Init();                          // Initialize lcd module
  ADC_Init();                          // Initialize ADC module
  Lcd_Cmd(_LCD_CLEAR);                 // Clear Lcd display
  Lcd_Cmd(_LCD_CURSOR_OFF);            // Cursor of the Lcd display
  Lcd_Out(1,1, "DEVELOPED BY");        // Lcd show "DEVELOPED BY"
  Lcd_Out(2,1, "MINA TECHNOLOGY");     // Lcd show "MINA TECHNOLOGY"
  delay_ms(2000);                      // 2 second delay
  Lcd_Cmd(_LCD_CLEAR);                 // Clear Lcd display

  do                                   // loop start
  {
    v = ADC_Read(0);                   // RA0 is Analog input
    v = (v*4.89) ;                     // 4.89 is Voltage Resulation
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    Lcd_Out(1,1,"Digital Voltmeter");
    Lcd_Out(2,1,"Voltage = ");
    Lcd_Out(2,11,volt);
    Lcd_Out(2,16,"V");

    Delay_ms(500) ;                     // 500ms delay

  } while(1);                           // loop end
}