Here in this tutorial, you will learn the basics of seven-segment displays, their types, and how to interface them with the AT89051 microcontroller. By the end, you’ll understand how to connect the display, write simple programs, and show digits on it. But remember that they can also display a limited set of letters and special characters.
So first what is Seven-Segment display?
A seven-segment display (SSD) is an electronic device used to show decimal numbers (0-9). These are used, and you will see them in digital clocks, basic calculators, electronics meter and other devices that needs to display numbers. It is called seven segment display, because internally it displays contains seven LEDs(as segments) arrange in 8 figure patterns. By turning on specific led or segments, the forms a decimal digits.
Types of Seven-Segment Displays
There are two types of seven segment display- anode and cathode. Each 7 LEDs inside the seven-segment display have anode and cathode and depending upon how these two terminals are connected, they are classified as anode type seven segment display and cathode type seven segment display.
Common Cathode Seven Segment Display
In this type of seven segment display, all the cathode of the LEDs are tied together and connected to ground. To display the character (numbers usually sometimes alphabets) in this type, the anode of the LEDs are applied with high signal through current limiting resistors.
Shown below is common cathode seven segment display:
Common Anode Seven Segment Display(SSD)
In this type of seven segment display, all the anode of the LEDs are tied together and connected to power(logic high). To display the character(numbers usually sometimes alphabets) in this anode type, the anode of the LEDs are applied with low signal through current limiting resistors.
Shown below is common anode seven segment display:
System Design for Interfacing
To understand SSD operation, let’s design a simple system.
Components Needed
+12V Power Supply
+12V to +5V Converter
ATC89051 Microcontroller
220Ω Resistors
Seven-Segment Display(Cathode)
Block Diagram
The system works as follows:
Power supply provides voltage.
Converter steps down +12V to +5V for the microcontroller.
Microcontroller (8051/NuttyFi)
ATC89051 Microcontroller sends signals to SSD.
Resistors limit current to protect SSD LEDs.
SSD displays the required digit.
segment_code[]) stored in program memory and outputting those values to Port 2. Each hexadecimal value in the array represents a specific 8-bit binary pattern tailored to your unique schematic wiring, where the highest bit (P2.7) is ignored and the remaining bits (P2.6 down to P2.0) cleanly map to segments a through g respectively. The main function loops infinitely, updating Port 2 with the next number's segment configuration every time the nested for loops in the software delay routine finish executing.
#include <reg51.h>
void delay(unsigned int ms);
// EXACTLY MATCHED Array for your custom Port 2 layout:
// Bit configuration -> [ Disconnected(0), a, b, c, d, e, f, g ]
unsigned char code segment_code[] = {
0x7E, // 0 -> Lights up a, b, c, d, e, f
0x30, // 1 -> Lights up b, c
0x6D, // 2 -> Lights up a, b, g, e, d
0x79, // 3 -> Lights up a, b, c, d, g
0x33, // 4 -> Lights up f, g, b, c
0x5B, // 5 -> Lights up a, f, g, c, d
0x5F, // 6 -> Lights up a, f, g, c, d, e
0x70, // 7 -> Lights up a, b, c
0x7F, // 8 -> Lights up all segments (a, b, c, d, e, f, g)
0x7B // 9 -> Lights up a, b, f, g, c, d
};
void main() {
unsigned char i;
while(1) {
for(i = 0; i < 10; i++) {
P2 = segment_code[i]; // Send the perfectly aligned mapping to Port 2
delay(100); // 1-second delay
}
}
}
// Simple delay function
void delay(unsigned int ms) {
unsigned int x, y;
for(x = 0; x < ms; x++) {
for(y = 0; y < 1275; y++);
}
}
