Skip to main content

7 Segment Display With PIC16F687

7 segment display proteus schematic.
7 Segment Display Proteus Schematic

In this article, we will tell you how to operate a 7-segment display (7SD in short) with a microcontroller. There are two (perhaps more) options to do this. The first is to connect the 7SD directly to the output ports of the microcontroller as shown in the picture above. This may cause a port shortage in large projects. As a second way to avoid this; We can run it by connecting a decoder to the 7SD. We will show both for you.

We will use a function to display the desired number in 7SD. This function is as follows;

Display Num Function Code

void displayNum(char num) {
  TRISC = 0x00;
  switch (num) {
        case 0:
            PORTC = 0b00111111;
        case 1:
            PORTC = 0b00000110;
        case 2:
            PORTC = 0b01011011;
        case 3:
            PORTC = 0b01001111;
        case 4:
            PORTC = 0b01100110;
        case 5:
            PORTC = 0b01101101;
        case 6:
            PORTC = 0b01111101;
        case 7:
            PORTC = 0b00000111;
        case 8:
            PORTC = 0b01111111;
        case 9:
            PORTC = 0b01100111;
            PORTC = 0b00111111;

The numbers we assign to PORTC are the equivalent of that number in 7SD. Here we used the first 7 bits of PORTC. Now let’s come to the main program;

Main Program Code

int main() {
  // Make pins as digital.
  ANSEL = 0x00;
  // Make PORTC as output.
  TRISC = 0x00;
  PORTC = 0x00;
  // Make RA0 as input.
  TRISA = 0b00001001;

  while (1) {
    // Displays numbers with 300ms delay.
    for (char i = 0; i < 10; i++) {
      // Wait for switch.
      while (RA0);

  return (0);

First of all, to make pins digital, we need to reset the ANSEL Register. Then we reset TRISC and PORTC. With TRISA, we set pin A0 as input. We show the numbers in 7SD respectively with 300 ms intervals in the infinite loop. If the A0 pin is 1 (5V), we are waiting.

The second way is to run the 7SD using the 4511 IC (decoder). The circuit for this will be as follows.

7 segment display with 4511 ic schematic.
7 Segment Display Proteus With 4511 Schematic

With the decoder, we can run 7SD by simply entering the number. For this, we can change the function as follows;

Display Num Function Code For 4511

void displayNum(char num) {
  TRISC = 0x00;
  PORTC = num;

Thus, we reduced the number of pins used and did not use the program memory much.
Finally, below is a simulation made with Proteus.

7 segment display proteus simulation.
7 Segment Display Proteus Simulation

We hope it has been helpful. Stay healthy …


Popular posts from this blog

How to Make Blink LED with PIC16F628A

How to Make Blink LED With PIC16F628A In this project tutorial, we are going to make blink-led projects with a pic microcontroller. After you read this tutorial you can build a PIC microcontroller project with XC8 on MPLAB IDE. We are going to make 3 different blinking projects. These projects are basic. Just learn how to make a basic project with a PIC microcontroller. You can see below which projects we are going to make; Blinking LED with 1s delay, LED with button, Blinking LED with a button.

Ultrasonic Sensor HC-SR04 With PIC Microcontroller

How Ultrasonic Sensor Works An ultrasonic sensor is a very useful sensor that measures distances with sounds. We used the PIC16F628A microcontroller for this project. This microcontroller has TMR1 which we are going to use. We need 2 I/O pins for TRIG and ECHO pins. For showing distance, we used an LCD. For more information about the LCD library and usage click the button below. LCD Interfacing with PIC Using XC8

DC Motor Speed Control With PIC16F628A

DC Motor Speed Control Simulation In this project, we will control the speed and direction of a DC motor using the PIC16F628A microcontroller. We will write the software in MPLAB IDE with the XC8 language that will send a PWM signal to L293D to control the motor. Finally, we will simulate it through the Proteus software. PWM (Pulse Width Modulation) You can get more information about the PWM signal from the link above. Now let’s examine the L293D motor driver.