7-Segment Display with 74HC595 Shift Register | mikroC Projects

Adding a serial-in parallel-out shift register such as the popular one 74HC595 to a 7-segment display will reduce number of pins required to drive it (the display).
Basically the 7-segment display requires 9 pins: 8 segment pins (A, B, C, D, E, F, G and DP) + common pin. By connecting all the segment pins to a shift register, the required number of pins becomes just 3: clock pin and data pin (for the shift register) + common pin.
So, for a 4-digit 7-segment display we need just 6 pins: clock, data and 4 common pins (each digit has its individual common pin).

This topic shows how to build a simple digital counter using PIC16F887 microcontroller, common anode 7-segment display with 4 digits and 74HC595 shift register.
The compiler used in this project is mikroC PRO for PIC.

To see how to interface PIC16F887 microcontroller with 7-segment display (without shift register) visit the following post:
Interfacing PIC microcontroller with 7-segment display | mikroC Projects

Hardware Required:

  • PIC16F887 microcontroller  —->  datasheet
  • 4-Digit common anode 7-segment display
  • 74HC595 shift register   —->   datasheet
  • 4 x PNP transistor (2SA10152S90152N3906 …)
  • 8 x 100 ohm resistor
  • 4 x 4.7k ohm resistor
  • Push button
  • 5V source
  • Breadboard
  • Jumper wires

7-Segment display with 74HC595 shift register circuit:
The image below shows our example circuit schematic diagram.

PIC16F887 7-segment display 74HC595 shift register

All the grounded terminals are connected together.

As shown in the circuit diagram above, all segment pins are connected to the 74HC595 output pins, each one through 100 ohm resistor, where:
Segment A … G are connected to 74HC595 pin Q7 … Q1 respectively and segment DP is connected to pin Q0.
The data pin of the 74HC595 shift register is named DS (#14) and it is connected to PIC16F887 pin RD2.
ST_CP (or RCLK) and SH_CP (or SRCLK) are connected together which then connected to PIC16F887 pin RD3, this is the clock pin.

Since the display has 4 digits, there’re 4 common pins: 1 (most left), 2, 3 and 4. Each common pin is connected to collector terminal of one transistor. Emitter terminals of the 4 transistors are connected to +5V. Base terminals of the four transistors are connected to the PIC16F887 through 4.7k resistors.

The 4 transistors are of the same type (PNP).

The push button which is connected to PIC16F887 pin RB4 is used to increment the displayed number.

The PIC16F887 microcontroller uses its internal oscillator @ 8 MHz, MCLR pin is configured as an input pin.

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

Shift register clock pin and data pin are defined as:

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

Project DIY hardware circuit is similar to the one shown in the video below where Arduino uno board is used instead of PIC16F887 microcontroller:


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

4 thoughts on “7-Segment Display with 74HC595 Shift Register | mikroC Projects”

  1. i tried the circuit & the code but the circuit didnt work with me ,ive 2 issues 1st timing message 2nd instead of numbers it showed only 7segments lines

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