Okpe Henry Chiagozie
4 min readAug 28, 2021

INTERFACING 7 SEGMENT DISPLAY TO 89C52 MICROCONTROLLER
what are the 7-segment display and the 89c52 microcontroller? They are simply integrated
circuit designed to control operations in an embedded system.
What is an embedded system? An on-board system is a system that contains various components such as computer memory, processor, etc.
However, let me discuss the 7-segment display, 89c52 microcontroller and their interface in more detail.
INTERFACING 7 SEGMENT DISPLAY TO 89C52
Interfacing is simply the connection between a 7-segment display and an 89c52 microcontroller. The 7 segments a-g are connected to pins 1-8 of the microcontroller.

89c52 MICROCONTROLLER
The 89c52 microcontroller is an 8-bit microcontroller. It is part of the 8051 family of Atmel. It has 256 bytes of primary memory (that is, random access memory (RAM)) and 8 KB of programmable flash memory and erasable read only memory (ROM).

89c52 PIN CONFIGURATION

The diagram above is the structure of the 89c52 microcontroller which includes different ports. These ports are very vital for the microcontroller as they have various functionalities and perform various functions that make the 89c52 operational. They are
Port 1: This is an 8-bit bidirectional I / O port in internal pullups. pulled low as entrances
Port 2: This is also an 8-bit bidirectional I / O port with internal pullup. When accessing external memory which uses 16-bit addresses, the most significant address bytes are sent.
Port 3: It also has internal pullups being an 8 bit bidirectional I / O port. it serves as functions for various functionalities of the 80c51 family which are as follows:
Port pin: Alternate functions
P3.0: RXD(Serial input)
P3.1: TXD(serial output)
P3.2: INT 0(External interrupt 0)
P3.3: INT 1 (External interrupt 1) and so on
ALE/PRO: The address latch enable (ALE) output pulse is used to latch the least significant byte of the address when accessing external memory. The ALE is output at a constant rate of 1/6 of the oscillator for external synchronization and synchronization purposes.
PSEN (Stable Program Activation): It is activated twice when the device is operating from an external program memory and will not activate and activate when the devices are operated from memory external program. internal memory. It is also the flash reading of the external memory of the program.
EA/VPP: In this case, the CPU runs out of internal memory when EA is held high and when EA is held low, the CPU runs out of external memory regardless of the value of the program counter.
XTAL 1: Input to the inverting oscillator amplifier
XTAL 2: output from the inverting oscillator amplifier
Port 0: This is an 8-bit open-drain bidirectional port due to its open-drain output port. It also emits a code byte when checking the program.
VCC: Supply voltage.
VSS: Circuit ground.
7 SEGMENT DISPLAY
It is a very popular display because it is used in various types of in-car devices. The 7-segment display allows you to display numbers and alphabets thanks to the 8 LEDs it contains. The 7-segment display is of two types. These are
Anode type: This is a common anode that can sink more than it can supply. They are usually lit when grounding an LED pin. when grounding the LED pins.
Cathode type: In the common cathode, 1 turns it on or off and 0 turns it off or off. All LED cathodes are connected together at logic "0" or ground.
Now I will talk about how to display the numbers and characters on the 7 segment display. Numbers and characters are displayed on the 7-segment display giving it instructions written in codes. First, I will include the necessary reg51.h header file. If you are using keil to write and compile code, you must include this library, otherwise there will be an error while compiling the code. If you are using 89c52 or 89s52, include the reg52.h library instead of reg51.h. Then a delay function is used to give a certain delay for a particular character / alphabet or number to remain printed on the seven segment display. The delay allows you to display the character / alphabet or number for a period of time, then move on to the next. If there is no delay, the numbers will appear so quickly that we will not be able to see them. In the main function, my first instruction is P1 = 0x00. This instruction initializes Port-1 as an output port. The rest of the instructions are in hexadecimal form and the functions are described above.
Note: If you use the common cathode seven segment display, the top controls will be the same, just make a small change, turn 0 (zeros) to 1 (ones) and 1 (ones) to 0 (zeros) when the common cathode lights up its indicator lights up when a pin is high.
The while loop 1 continuously executes our seven-segment display. Means continuously printing characters and numbers on it.
#include<reg51.h>
void delay ()
{
unsigned int i=0,j;
for(j=0;j<=3;j++)
for (i=0;i<=30000;i++);
}
void main()
{
P1=0x00;
while(1){
delay();
P1=0xCF; delay();
P1=0xA4; delay();
P1=0xB0; delay();
P1=0x99; delay();
P1=0x92; delay();
P1=0x82; delay();
P1=0xF8; delay();
P1=0x00; delay();
P1=0x98; delay();
P1=0x88; delay();
P1=0x00; delay();
P1=0xC6; delay();
P1=0xC0; delay();
P1=0x86; delay();
P1=0x8E;