INTERFACING SEVEN SEGMENT DISPLAY WITH 89C51 MICROCONTROLLER

Course work on microcontroller and seven-segment display, by Electronic and Computer Engineering Department of Nnamdi Azikiwe University.

Chukwuma Miracle
4 min readAug 23, 2021

SEVEN SEGMENT DISPLAY

A seven-segment display is a form of an electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays.

Seven segment displays are widely used in digital clocks, electronic meters, basic calculators, petrol meters, and other electronic devices that display numerical information.

The seven-segment display has two major configurations which are the common cathode configuration and the common anode configuration

When the seven-segment display is connected in the common cathode configuration, it requires a HIGH i.e a One to light up the led. While when it is connected in the common anode configuration, it requires a LOW i.e a Zero to light up a led.

89C51 MICROCONTROLLER

This is a single-chip computer that consists of a memory unit, CPU, and input-output units. One major difference between a microcontroller and a microprocessor is that a microcontroller has internal memory but a microprocessor doesn’t have an internal memory but it can access external memory.

The 89C51 microcontroller requires a low power of at least +5v to power on this is possible because the 89C51 microcontroller was produced with a CMOS technology and CMOS technology devices require a low power to function.

8051 microcontroller port-1 interfaced with 7 segment — Individual pin connections

7 segment pins connection’s with 89c52 microcontroller port-1 individual pins is shown in the below picture. 7 segment display only has 7 sevens pins and 8051 microcontroller port-1 is 8-bit wide. So one pin of 89c52 port-1 is void.

8051(89c51, 89c52) Port 1 pin assignment to seven-segment display

How numbers and characters are displayed on 7 segment display?

89c52 microcontroller port pins are assigned to seven segments in the above order(picture). Instructions like P1=0xCF are hexadecimal instructions and they are making port 1 pins high or low.

Like P1=0xCF is equivalent to 11001111(C=1100 and F=1111) in binary. This instruction makes f & e(P1.5 and P1.4) pins of seven-segment ground and the corresponding led’s to these pins becomes high. which prints 1 on the seven-segment display.

Below are the full instructions used to display numbers and alphabets on the 7 segment display. These instructions are hardcoded in the code.

  • Making 1- f and e are grounded. P1=0xCF; 11001111
  • Making 2- a, b, g, e, and d are grounded. P1=0xA4; 10100100
  • Making 3- a, b, c, d, and g are grounded. P1=0xB0; 10110000
  • Making 4- b, c, f, and g are grounded. P1=0x99; 10011001
  • Making 5- a, c, d, f, and g are grounded. P1=0x92; 10010010
  • Making 6- a, c, d, e, f, and g are grounded. P1=0x82; 10000010
  • Making 7- a, b, and c are grounded. P1=0xF8; 11111000
  • Making 8- a, b, c, d, e, f, and g are grounded. P1=0x00; 00000000
  • Making 9- a, b, c, f, and g are grounded. P1=0x98; 10011000
  • Making A- a, b, c, e, f, and g are grounded. P1=0x88; 10001000
  • Making B- a, b, c, d, e, f, and g are grounded. P1=0x00; 00000000
  • Making C- a, d, e, and f are grounded. P1=0xC6; 11000110
  • Making D- a, b, c, d, e, and f are grounded. P1=0xC0; 11000000
  • Making E- a, d, e, f, and g are grounded. P1=0x86; 10000110
  • Making F- a, e, f, and g are grounded. P1=0x8E; 10001110​

Example Program

ORG 000H //initial starting address
START: MOV A,#00001001B // initial value of accumulator
MOV B,A
MOV R0,#0AH //Register R0 initialized as a counter which counts from 10 to 0
LABEL: MOV A, B
INC A
MOV B, A
MOVC A,@A+PC // adds the byte in A to the program counters address
MOV P1,A
ACALL DELAY // calls the delay of the timer
DEC R0//Counter R0 decremented by 1
MOV A, R0 // R0 moved to accumulator to check if it is zero in next instruction.
JZ START //Checks accumulator for zero and jumps to START. Done to check if counting has been finished.
SJMP LABEL
DB 3FH // digit drive pattern for 0
DB 06H // digit drive pattern for 1
DB 5BH // digit drive pattern for 2
DB 4FH // digit drive pattern for 3
DB 66H // digit drive pattern for 4
DB 6DH // digit drive pattern for 5
DB 7DH // digit drive pattern for 6
DB 07H // digit drive pattern for 7
DB 7FH // digit drive pattern for 8
DB 6FH // digit drive pattern for 9
DELAY: MOV R4,#05H // subroutine for delay
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END

--

--

Chukwuma Miracle

Undergraduate of Electrical Engineering, Full Stack developer (Java and Angular).