PIC16F877A based volt meter
This post provides a simple digital voltmeter circuit using PIC16f877A microcontroller. This code is written in C language using MPLAB X IDE with XC8 compiler.
In this post, it is assumed that you know,
- How to use ADC of PIC16F877A microcontroller.
- How to interface LCD with PIC16F877A microcontroller.
 |
| Figure 1. Digital voltmeter using PIC16F877A |
In this circuit PORTB pins are used to interface LCD with PIC167877A microcontroller. The input to the digital voltmeter is given on the RA0 (or AN0) pin.
You cannot feed a 20V signal directly to a PIC microcontroller’s input channel. It is too higher than its operating voltage, and the microcontroller could be damaged. So, first we need a voltage scaler that will scale down the input voltage to the safe operating voltage range of PIC16F877A. It can be achieved by a simple resistor divider network shown in the below Image.
 |
| Figure:2 Voltage divider network |
Using two resistors, R1 and R2, the input voltage ranging from 0-20V can be down
converted to 0-5V.
Calculation:
Voltage Divider Network:
Vout = Vin * R2 / R1+R2
Here Vin =13,R1=470K and R2=200k
Vout = 13*(200+670);
Vout = 13*(0.29850);
Vout = 3.88 volts;
ADC :
0 – 5 V Analog I/P is mapped to one of the 1024 levels (0-1023 Digital Count)
=> Resolution = 5/1024 = 0.00488 V/Count
Volt = ADC_Result * 0.00488 * 0.29850;
Coding:
 |
| Figure 3: Pic16f877A voltmeter code |
Downloads:
Digital voltmeter code using PIC16F877A was compiled in MPLAB X IDE v3.05 with XC8 V1.34 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation Click here.