Print ADC Values on 7-Segment Display with PIC MCU | 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 mikroC PRO for PIC.

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 (2SA1015, 2S9015, 2N3906 …)
  • 10k ohm potentiometer
  • 7 x 100 ohm resistor
  • 4 x 4.7k ohm resistor
  • 5V source
  • Breadboard
  • Jumper wires

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 }.

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:


  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 Reply

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