Vous êtes sur la page 1sur 5

Digital volt meter ,

for quire contact: engnr.shakeel@gamil.com

Digital volt meter by using PIC16F877A


This is simple design of DIGITAL VOLTMETER by changing the RV2(variable resistance ) we can
observe the changing voltage on LCD

Software used:
1) Proteus 7.7 for simulation
2) MickroC Pro v4.15 for code compiling and HEX file

BEST OF LUCK.

Engnr Rana Muhammad Shakeel


Engnr.shakeel@gmail.com
+92-333-4962507
https://www.facebook.com/EngnrShakeel

Circuit Diagram:
1

Engnr Rana M Shakeel, +92-333-4962507 | engnr.shakeel@gmail.com

Digital volt meter ,

for quire contact: engnr.shakeel@gamil.com

CODE:
/*Header******************************************************/

// 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;
2

Engnr Rana M Shakeel, +92-333-4962507 | engnr.shakeel@gmail.com

Digital volt meter ,

for quire contact: engnr.shakeel@gamil.com

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

unsigned char ch;

//

unsigned int adc_rd;

// Declare variables

char *text;

//

long tlong;

//

void introduction (void)


{
Lcd_Cmd(_LCD_CLEAR);
text = " Volt Meter ";
Lcd_Out(1,1,text);
text = "by PIC16F877A";
Lcd_Out(2,1,text);

// LCD command (clear LCD)


// Define the first message
// Write the first message in the first line
// Define the second message
// Define the first message

Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
text = "Engnr Rana M";

// Define the first message

Lcd_Out(1,1,text);

// Write the first message in the first line

Delay_ms(1000);
text = " Shakeel ";
Lcd_Out(2,1,text);

// Define the second message


// Define the first message

Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
text = " Volt Meter ";
3

// LCD command (clear LCD)


// Define the first message

Engnr Rana M Shakeel, +92-333-4962507 | engnr.shakeel@gmail.com

Digital volt meter ,

for quire contact: engnr.shakeel@gamil.com

Lcd_Out(1,1,text);

}
void main() {
INTCON = 0;

// All interrupts disabled

TRISA = 0x04;

Lcd_Init();

// LCD display initialization

Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);

ADCON1 = 0x82;

// LCD command (cursor off)


// LCD command (clear LCD)

// A/D voltage reference is VCC

TRISA = 0xFF;

// All port A pins are configured as inputs

Delay_ms(1000);
introduction (void);
text = "voltage:";

// Define the third message

Delay_ms(1000);
while (1) {
adc_rd = ADC_Read(2);
Lcd_Out(2,1,text);

// A/D conversion. Pin RA2 is an input.


// Write result in the second line

tlong = (long)adc_rd * 5000; // Convert the result in millivolts


tlong = tlong / 1023;
ch = tlong / 1000;

// 0..1023 -> 0-5000mV


// Extract volts (thousands of millivolts)

// from result
Lcd_Chr(2,9,48+ch);
4

// Write result in ASCII format

Engnr Rana M Shakeel, +92-333-4962507 | engnr.shakeel@gmail.com

Digital volt meter ,

for quire contact: engnr.shakeel@gamil.com

Lcd_Chr_CP('.');
ch = (tlong / 100) % 10;

// Extract hundreds of millivolts

Lcd_Chr_CP(48+ch);

// Write result in ASCII format

ch = (tlong / 10) % 10;


Lcd_Chr_CP(48+ch);
ch = tlong % 10;
Lcd_Chr_CP(48+ch);

// Extract tens of millivolts


// Write result in ASCII format
// Extract digits for millivolts
// Write result in ASCII format

Lcd_Chr_CP('V');
Delay_ms(1);

}
}

Engnr Rana M Shakeel, +92-333-4962507 | engnr.shakeel@gmail.com