Friday, February 24, 2012

Mini project Digital Volt Meter (DVM) using PIC16F877A with C code

DVM Project Overview
Digital Volt Meter is a Mini Project that I made as my project of the subject ‘Microprocessor Based Instrumentation System’. In this project I have used three major electronic components. They are PIC16F877A, LCD Display (16 X 2) and Low power Quad op-amp (LM324). PIC16F877A is used as an ADC module which converts the analog input into corresponding 10 bit digital output. It also provides enable and RS signals to the LCD display. LCD Display is used to display the converted digital binary data to decimal format so that user can easily understand the voltage. And finally Low power quad op-amp is used as buffer and as inverter. The DVM measures the voltages ranging from –50 V to +50 V
. But PIC can operate only up to +5 V. So to measure the +50 V, the voltage divider is used. This divider divides the input voltage 10 times so that +50V input voltage is now becomes +5V at the PIC input.  Inside PIC a program is written which multiplies the converted digital value by 10 before sending it to the LCD display. A screen capture of a rough design of the project in Proteus 7.0 Professional is given below.
Digital Voltmeter Design proteus
PIC16F877A ADC Module
PicThe A/D convertor module has eight inputs. The conversion of analog input results in a corresponding 10 bit digital output. The A/D module has four registers. They are
  1. A/D Result High Register (ADRESH)
  2. A/D Register Low Register (ADRESL)
  3. A/D Control Register 0 (ADCON0)
  4. A/D Control Register 1 (ADCON1)
The ADICON0 register controls the operation of the A/D module and the ADICON1 register configures the functions of the port pins.
The structure of ADICON0
ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE’ - ADON
bits 7-6 : ADCS1:ADCS2 => Conversion channel select
bits 5-3: CHS2:CHS0 => Analog channel select [000 = Channel 1, 001 = Channel 2 and so on up to channel 7]
bit 2: GO/GONE’ => AD Conversion status bit [1 indicates conversion in progress and 0 indicates conversion not in progress]
bit1: Unimplemented
bit 0: ADON => A/D on bit [1 indicates converter module is power up and 0 indicates shut down]
The structure of ADICON1
ADFM ADCS2 - - - PCFG3 PCFG1 PCFG0
bit 7 : ADFM => A/D Result format [1 indicates Right Justified and 0 indicates Left Justified]
bit 6: ADCS2 => Conversion channel select
bits 5-4: Unimplemented
bits 3-0: A/D port configuration control bits
LDC Display (16 x 2)
Pin No. Name Funciton
1 Vss Ground
2 Vdd +Ve Supply
3 Vee Contrast
4 RS Register Select
5 R/W Read/Write
6 E Enable
7 D0 Data bit 0
8 D1 Data bit 1
9 D2 Data bit 2
10 D3 Data bit 3
11 D4 Data bit 4
12 D5 Data bit 5
13 D6 Data bit 6
14 D7 Data bit 7

C Source Code
#include <htc.h>
#define data PORTB
#define RS RD0
#define EN RD1

__CONFIG(HS & WDTDIS & PWRTEN & BORDIS & LVPDIS);

float valch0,valch1;

void delay_ms(int n )
{
    TMR1H=0xEC; 
 TMR1L=0x77;
 T1CKPS1=0;
 T1CKPS0=0;
 TMR1CS=0;
 TMR1IF=0;
 TMR1ON=1;
    while(n>0)
    {
  while(!TMR1IF);
  TMR1IF=0;
  TMR1H=0xEC; 
  TMR1L=0x77;
  n--;
 }
}

float select_adc(unsigned char chnl){    // init_adc(channel name);
    CHS2=CHS1=0;CHS0=chnl;
    delay_ms(10);
    ADON=1;
    ADGO=1;
    while(ADGO);
    return (((ADRESH*256+ADRESL)*5.0/1023)*10);
}




void LCD_Write(unsigned char values,int rs){
 data = values;
 RS = rs;    // rs=0 command and rs=1 data
 EN = 1;
 delay_ms(1);
 EN = 0;
}

void LCD_clear(void){
 LCD_Write(0x01,0);  //this clears LCD
}

void LCD_goto(unsigned char row,unsigned char column){
 if(row==1){
  LCD_Write(0x80+column,0);
 }
 else if(row==2){
  LCD_Write(0xC0+column,0);
 }
}

void LCD_num(int n){

  LCD_Write((n/100)+48,1);
  LCD_Write(((n%100)/10)+48,1);
  LCD_Write((n%10)+48,1);
}

void initLCD(void){

 TRISD=0x00;//as output
 TRISB = 0x00;
 delay_ms(100);


 LCD_Write(0x30, 0); //8 - bit display
 EN=1; EN = 0;
 LCD_Write(0x38,0);    //2 lines mode



 LCD_Write(0x0C,0);    //dispaly on , cursor blinking
 delay_ms(1);

 LCD_clear();LCD_goto(1,0);delay_ms(1);
 LCD_goto(1,7);
 LCD_Write('D',1);delay_ms(100);
 LCD_Write('V',1);delay_ms(100);
 LCD_Write('M',1);delay_ms(100);
 LCD_goto(2,12);
 LCD_Write('v',1);delay_ms(100);
 LCD_goto(2,7);
 LCD_Write('.',1);delay_ms(100);

}

void main(void){
    PCFG3=PCFG2=PCFG1=PCFG0=0;
 ADFM=1;
 ADCS1=1;
 ADCS0=0;
    TRISA=0xFF;
 initLCD();

    while(1){

        valch0=select_adc(0);
        valch1=select_adc(1);


        if(valch0 <= 0.00 && valch1!=0){
            valch0=valch1;
            LCD_goto(2,1);
            LCD_Write('-',1);
            delay_ms(5);
        }

        else{
            LCD_goto(2,1);
            LCD_Write('+',1);
            delay_ms(5);
        }


        LCD_goto(2,4);
        LCD_num(valch0);
        LCD_goto(2,8);
        LCD_num((valch0-(int)valch0)*1000);

    }
}

35 comments:

  1. can u give me a detail pictures due to i cannot see with detail component.hope u can help me.thanks..please email to farlin1987@gmail.com

    ReplyDelete
    Replies
    1. i have emailed you..see your mailbox...

      Delete
    2. also send me the pictures please? rashiddl@yahoo.com

      Delete
    3. hi good morning great project. can you please email me the picture to see with detail, the components to buy them. i will build it. Thank you very much

      guillerman70@gmail.com

      Delete
    4. send me the pictures please? wajih.siai.91@gmail.com

      Delete
  2. please send me one detailed picture of the circuit(bhaskars239@gmail.com). thanking you

    ReplyDelete
  3. can you help me to make a line follower robot using pic 16f877?
    mahedi.siu@gmail.com

    ReplyDelete
  4. can u give me a detail pictures due to i cannot see with detail component.hope u can help me.thanks..please email to p.sreeja92@gmail.com.

    ReplyDelete
  5. can u please give me a detailed circuit of the project. please email me at bhaskars239@gmail.com

    ReplyDelete
  6. hi am arun. i have some problem,Error 128 "volt.c" Line 6(1,5): A #DEVICE required before this line
    __CONFIG(HS & WDTDIS & PWRTEN & BORDIS & LVPDIS);

    how to solve this
    i am using ccs c compiler plz help

    my mail arunvtkl@gmail.com

    ReplyDelete
  7. Hi, can u give me a detail pictures due to i cannot see with detail component.hope u can help me.thanks..
    please email to yoke_kong92@hotmail.com.

    ReplyDelete
  8. Hi, I too need a detailed picture of the circuit. Please email it to me at abhmukh@gmail.com

    ReplyDelete
  9. can u give me a detail pictures because i cannot see with detail component.hope u can help me.thanks..please email to virus@gmail.com

    ReplyDelete
  10. Is this project will work.......
    Because i designed this project not working.
    It displaying an block line only..

    Kindly give your reply.

    THANK YOU

    ReplyDelete
  11. Can you provide me the details of this ?
    such as simulation Kindly mail me at
    naeem7240@hotmail.com
    thanks :)

    ReplyDelete
  12. Hi, can u give me a detail pictures due to i cannot see with detail component.hope u can help me.thanks..
    please email to writetoisra@yahoo.com.my

    ReplyDelete
  13. Hello there.. i cannot clearly identify the other electronic components could you email me the detailed image please? Thank you!

    teaphengrayfog@gmail.com

    ReplyDelete
  14. where is the probe in the circuit should I want to measure a component?

    ReplyDelete
  15. could you email me the detailed image please? Thank you!
    please email me asze89@gmail.com

    ReplyDelete
  16. Hi, kindly email me the schematic with clearer component labels at bboofs@yahoo.com. Thank you

    ReplyDelete
  17. thanks this is good example could u email for the simulation and the source code very grateful for this

    unilearnanything@gmail.com

    ReplyDelete
  18. i need a clearer schematic diagram of this circuit. If you don't mind sending, please do at robertjohndichos@gmail.com or trebor_nhoj_ditch@yahoo.com

    thanks

    ReplyDelete
  19. can u pls give me a detailed info about the construction of simple digital voltmeter.....
    reddy.sunnyth@gmail.com

    ReplyDelete
  20. pls give me the picture of detailed component thanks :)
    my email is roanzky@gmail.com

    ReplyDelete
  21. can you please provide me with a high resolution pic of the simulation or the .DSN file at this email address ( najambutt143@gmail.com)? ...thanks in anticipation..... :)

    ReplyDelete
    Replies
    1. hi good morning great project. can you please email me the picture to see with detail, the components to buy them. i will build it. Thank you very much
      (shahirahghazali93@gmail.com)

      Delete
  22. Great project. can you please email me detailed picture of the circuit in isis. i will build it. Thank you very much
    (wajih_siai@hotmail.fr)

    ReplyDelete
  23. pls send me a detailed picture of the circuit
    my mail id is
    kichunyk@gmail.com..
    as soon as possible please

    ReplyDelete
  24. Can you send the picture to see with detail, the components to buy them? There will be very helpful. raymondliu56@hotmail.com

    ReplyDelete
  25. is there anyway u can convert this to be used for a pic16f917 programmed through ICD 3 using MPLAB

    ReplyDelete
  26. pls email me your complete detail of your project.. ianzz_libra@yahoo.com

    ReplyDelete
  27. Can you send the picture to see with detail, the components to buy them? There will be very helpful. pumpkin125_mcr@yahoo.com

    ReplyDelete
  28. it's not working on my code blocks..
    this error is shown ,

    fatal error : htd.h : no such file or directory .

    ReplyDelete
  29. Good day sir,

    Would be grateful if you could send me the picture to see with detail, the components to buy them.

    karthikeyanramadoss@outlook.com

    ReplyDelete
  30. Hello, It also provides enable and RS signals to the LCD display. LCD Display is used to display the converted digital binary data to decimal format so that user can easily understand the voltage. And finally Low power quad op-amp is used as buffer and as invert er.Great effort in analyzing. Thanks for the post.

    ReplyDelete