Print ADC Values on 7-Segment Display with PIC | mikroC Projects

This PIC16F887 project shows how to read analog voltages from analog channel and print the correspondent digital values on a multiplexed 4-digit 7-segment display. A potentiometer is used to get a voltage that varies between 0 and 5V. A common anode 7-segment display is used in this example.
The compiler used in this project is the MikroElektronika mikroC PRO for PIC.
What makes this project so easy is that the PIC16F887 microcontroller already has a 10-bit ADC module with total analog channels of 14.

Last time I made a simple interfacing of PIC16F887 microcontroller with 7-segment display, project link is below:
Interfacing PIC microcontroller with 7-segment display | mikroC Projects

Components Required:

  • PIC16F887 microcontroller   —->  datasheet
  • 4-digit common anode 7-segment display
  • 4 x PNP transistor (2SA10152S90152N3906 …)
  • 10k ohm potentiometer
  • 7 x 100 ohm resistor
  • 4 x 4.7k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires
  • PIC MCU Programmer (PICkit 3, PICkit 4…)

Print ADC values on 7-segment display with PIC16F887 circuit:
The following image shows example circuit diagram.

PIC16F887 ADC 7 segment display common anode circuit

All the grounded terminal are connected together.

The four transistors used in this example are of the same type (PNP).
The potentiometer has 3 pins VCC , output and GND where:
VCC is connected to +5V
The output pin is connected to PIC16F887 analog channel 0 (AN0)
GND is connected to circuit ground.

In this project the PIC16F887 microcontroller runs with its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

The Code:
The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.

Since the 4 digits are multiplexed we need to refresh the display very quickly (display one digit at a time, others are off), for that I used Timer0 module (8-bit timer) interrupt with 1:16 prescaler, this means Timer0 overflows every 2048 microseconds { 256/[8/(4 x 16)] = 256 x 8 = 2048 microseconds }.

The PIC16F887 ADC (Analog-to-Digital Converter) reads analog voltage applied to analog channel AN0 (#2) and convert it to a digital representation which is then printed on the 7-segment display.
The PIC16F887 microcontroller has a built-in ADC module with 10-bit resolution. With a positive reference voltage of VCC (+5V) a 0V is represented by 0 and 5V is represented by 1023.

Full mikroC code:
Configuration words:
CONFIG1 = 0x2CD4
CONFIG2 = 0x0700

My hardware circuit gave me a result similar to what’s shown in the following video where Arduino UNO is used instead of the PIC16F887 microcontroller:

3 thoughts on “Print ADC Values on 7-Segment Display with PIC | mikroC Projects”

  1. Thank you, I solved it now the only problem that’s left is ”Program or EEPROM data has invalid adress [2000,2001,2002,2003] for this device, i’m new at this and I connected everything like the picture ^^ please help!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top