Class 3 - 7-Segment Display Counter

May 07, 2025

Hi buddies!
In this tutorial, let’s learn how to create a simple 0–9 counter using a 7-segment display and an 8051 microcontroller. If you’re just getting started with embedded systems, this is a perfect project to understand digital output and counters!

🧠 What is a 7-Segment Display?

A 7-segment display contains 7 individual LEDs arranged to form numbers from 0 to 9. These LEDs are named from a to g, and there’s sometimes an additional dot (dp) to show decimal points.

In our earlier tutorial, we saw how to turn a single LED on and off. Now, we’ll control 7 LEDs together in a specific pattern to display numbers!

🔌 Types of 7-Segment Displays

There are two types:

  • Common Anode (CA): All anodes (+) of the LEDs are connected together. You need to provide LOW (0V) to light up individual segments.
  • Common Cathode (CC): All cathodes (–) are connected together. You need to provide HIGH (5V) to light them up.

In this project, we’ll use Common Anode (CA) for better brightness, since the 8051 ports have internal pull-ups that limit brightness when using CC.

🧩 Segment Mapping & Logic

Each segment (a to g) must be turned on/off according to the number we want to display. For example:

  • To display 0: segments a, b, c, d, e, f ON, g OFF.
  • To display 1: only b and c ON.

You can derive this using K-maps, but there’s a much easier method.

🗂 Using a Lookup Table

Instead of complex logic equations, we use a lookup table – a simple array of hex values, where each value represents the ON/OFF pattern of segments for digits 0–9.

Here, code tells the compiler to store the data in Flash memory, saving RAM space.

🧪 Circuit Description

  • Microcontroller: Buddy51 Mini
  • Display: Common Anode 7-segment
  • Resistors: 330Ω for current limiting
  • Connections:
    • Segments a–g connected to P0.0–P0.6
    • Common pin connected to Vcc (+5V)

Note: We avoid using CC displays here because internal pull-up resistors limit brightness.

💻 Code Explanation

Let’s walk through the main parts of the code:

  1. Declare a variable count to store the current number.
  2. On key press (connected to a pin), increment count.
  3. If count > 9, reset to 0.
  4. Use the lookup table to send the segment pattern to PORT0.

🧯 Testing the Output

Once the code is flashed to the microcontroller:

  • Press the button → the number increments.
  • After 9, it resets to 0.
  • The 7-segment display shows the count in real-time!

🤔 Got Questions?

If you have any doubts or want a deep dive into how lookup tables work or how to connect the hardware, feel free to comment below or check out our video tutorial on this same topic.

Thanks for reading – Happy Learning!
Team BuddyKit 🚀

Leave a reply
Class 2 – Input Handling – LED Control with ButtonClass 4 – Counter using LCD

Leave Your Reply