Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

// 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 *text;

unsigned int v,vp;

char *volt = "00.00 VOLTS";

//char *volt = "00.000 VOLTS"; // format 00.000

void main()

CMCON = 0x07; // Comparators OFF

TRISA = 0x04; // Configure RA2 as Inpu

ADCON1 = 0x80; // Configure PORTA & PORTE as analog

Lcd_Init(); // LCD display initialization

Lcd_Cmd(_LCD_CURSOR_OFF); // LCD command (cursor off)


Lcd_Cmd(_LCD_CLEAR); // LCD command (clear LCD)

text = "LET'S THINK BINARY"; // Define the first message

Lcd_Out(1,2,text); // Write the first message in the first line

text = "www.electronify.org"; // Define the second message

Lcd_Out(2,1,text); // Write the message in the second line

text = "DIGITAL Voltmeter"; // Define the third message

Lcd_Out(3,2,text); //Write the message in the third line

do

v = ADC_Read(2); // Read analog value from channel 2

v = ((v*4.89)/5)*20; // V GOES FROM 0 TO 20 volts

// Resolution 10 bits ( 0......1023)

if(v!=vp )

vp = v;

volt[0] = (v/10000)+ 48; // Extract volts (thousands of millivolts) from result

// Write result in ASCII format

volt[1] = (v/1000)%10+48; // Extract thousands of mv

volt[3] = (v/100)%10+48; // Extract hundreds of mv

volt[4] = (v/10)%10+48; // Extract tens of millivolts if you want the format 00.000

Lcd_Out(4,1,"Voltage= ");

Lcd_Out(4,9,volt);

Delay_ms(200);

} while(1);

}
Digital Voltmeter using PIC16F877a (Schematic Diagram)

Digital Voltmeter using PIC16F877a schematic diagram

digital voltmeter upto 20 volt range animated circuit diagram

Results :

Compile the PIC code and generate the hex file from it. For simulating with PROTEUS ISIS hit run button
and then you will get above output.

So, now we can see the LCD is displaying exactly the same values as are shown in the voltmeter. Now if
you change the value of variable resistor RV3 then the value of voltage will change in LCD.

This digital voltmeter using PIC16F877A can read voltage only between 0-20 volt.

Resource :

You might also like