Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Digital voltmeter with PIC16F877A and LCD

Status
Not open for further replies.

jean12

Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
Hey,I would like to implement a digital voltmeter with PIC16F877A and an 16*2 LCDbut the conversion is not succeeding,the voltmeter has to measure 0-30VDC but I am not getting good values.

Could you please help see the codes here below:
PHP:
#include <16f877A.h> //Header declaration for pic used
#DEVICE ADC=10   //definition of ADC bits for conversation purpose
//Fuses definition for the PIC

#fuses HS     //definition of the quartz in use High Frequency =4MHZ
#fuses NOWDT  //Disable internal Timer watchdog
#fuses NOLVP   //Disable programmation at low voltage 
#fuses NODEBUG   //disable test of codes at runtime
#fuses NOCPD   //Avoid protection of codes
#use delay(clock=4M)  //Set the values of Quartz to use

//Definition of pins for connecting the LCD:Light Crystal Display

#define LCD_DATA4    PIN_D4
#define LCD_DATA5    PIN_D5
#define LCD_DATA6    PIN_D6
#define LCD_DATA7    PIN_D7

#define LCD_RW_PIN      PIN_D3
#define LCD_ENABLE_PIN   PIN_D1
#define LCD_RS_PIN       PIN_D2
#include <lcd.c>
 float  volt1,volt2; //Variable declaration


void main() //Initialization of the main function
{
set_tris_d(0x00); //definition of ports 
lcd_init(); //Initialization of the LCD to be used
  
   delay_us(5); //set of a delay of 5uS for ADC to start operating
   setup_adc_ports(AN0);  //Set the pin where input is connected
   Setup_adc(ADC_CLOCK_INTERNAL);   //set the clock used by the internal ADC Module
   set_adc_channel(0); //set the channel from which the ADC will be reading the data from
   setup_vref(FALSE); //use of 5V of the power supply as a reference voltage
 
   while(TRUE)  //define the endless loop for measuring the voltage
   {
      delay_us(10);    //set a simple delay for the ADC to start reading 
      read_adc(ADC_START_ONLY);//Start reading the ADC value 
      
      delay_us(2); //set a simple delay for the ADC to start reading 
      volt1=read_adc();//start reading and  store the value in variable volt1
      
       volt2=(volt1*4.88)/1023;  //conversion to decimal number     
      
      
      
      if(volt2==0)//Condition for displaying the text before priniting out on the LCD
      {
      delay_ms(20);
      lcd_gotoxy(2,1);
      printf(lcd_putc,"vin is needed!!");    //printing the text on the LCD  
      }
      else//in case the input is connected the value has to be printed out here below
      lcd_gotoxy(1,1);
      printf(lcd_putc,"\connected vin is:");
delay_ms(600);
lcd_gotoxy(2,2);
      printf(lcd_putc,"vin=%f V",volt2);
       delay_us(200);//delay for reading and displaying the value on the screen(LCD)
   }
}
For voltage divider I used 750ohm and 3.9Kohm as resistors for reducing the voltage up to approximately 5V,in parallel to the 750ohm I placed a zener diode of 5.1V,unfortunately when calculating
Vout(max)=750*30/(3900+750)=4.838Volts.

Please help to handle!!
 

HI, how much voltage reading are you getting. from 0v to __?
 

hey the voltage might be 0-30V.

Thank you!!
 

Hi,

the voltmeter has to measure 0-30VDC but I am not getting good values.

... but what values do you see?

analog signal input = 0V ---> output LCD reading?
analog signal input = 5V ---> output LCD reading?
analog signal input = 10V ---> output LCD reading?
analog signal input = 30V ---> output LCD reading?

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top