Its fairly straightforward to connect a 7 segment display to your 8051 processor, in this example we will do this and show a code example which cycles through the numbers 0 to 9.
First of all a 7 segment display is basically a collection of LED’s, 1 LED per segment and a decimal point.
Here is the pinout of a fairly typical display, you should always refer to the datasheet of your display to verify the pinout.
Displaying a number
Displaying a number on a 7 segment display is as simple as sending a logic low or high (depending on the display type) to a sequence of pin(s) to light up the segment. The table below shows the segments that would be required to be enabled for a common cathode, in that case a 1 will light a segment. Invert the numbers in columns a – g if you have a common anode 7 segment display
So to display a 1 we need to activate segments b and c.
This is the basic 8051 connected up to the 7 segment display, other circuitry such as crystal and capacitors and power is not shown here.
The display is a common anode type
This code is for a common anode 7 segment display, the code was written using the mikroC PRO for 8051 compiler
P0 = 0xFF;
//activate segments 1 at a time. Number 1 first
P0 = 0xF9;
P0 = 0xA4;
P0 = 0xB0;
P0 = 0x99;
P0 = 0x92;
P0 = 0x82;
P0 = 0xF8;
P0 = 0x80;
P0 = 0x98;
P0 = 0xC0;
P0 = 0xff;
} while(1); // Endless loop