You are on page 1of 7

Interfacing Seven segment display to 8051

admin June - 20 - 2012 22 Comments

A Note about 7 segment LE display!


This article is about how to interface a seven segment LED displa to an !0"1 microcontroller# $ segment LED displa is ver popular and it can displa digits from 0 to % and &uite a few characters li'e () b) C) #) *) E) e) +) n) o)t)u) ) etc# ,nowledge about how to interface a seven segment displa to a micro controller is ver essential in designing embedded s stems# ( seven segment displa consists of seven LEDs arranged in the form of a s&uarish "8# slightl inclined to the right and a single LED as the dot character# Different characters can be displa ed b selectivel glowing the re&uired LED segments# -even segment displa s are of two t pes) common cathode and common anode. .n common cathode t pe ) the cathode of all LEDs are tied together to a single terminal which is usuall labeled as /com/ and the anode of all LEDs are left alone as individual pins labeled as a) b) c) d) e) f) g 0 h 1or dot2 # .n common anode t pe) the anode of all LEDs are tied together as a single terminal and cathodes are left alone as individual pins# The pin out scheme and picture of a t pical $ segment LED displa is shown in the image below#

$ segment LED displa igit drive pattern! Digit drive pattern of a seven segment LED displa is simpl the different logic combinations of its terminals $a" to $%/ in order to displa different digits and characters# The common digit drive patterns 10 to %2 of a seven segment displa are shown in the table below#

igit 0 1 2 3 4 " 5 $ ! %

a 1 0 1 1 0 1 1 1 1 1

b 1 1 1 1 1 0 0 1 1 1

c 1 1 0 1 1 1 1 1 1 1

d 1 0 1 1 0 1 1 0 1 1

e 1 0 1 0 0 0 1 0 1 0

f 1 0 0 0 1 1 1 0 1 1

g 0 0 1 1 1 1 1 0 1 1

Interfacing seven segment display to 8051!

.nterfacing $ segment displa to !0"1 The circuit diagram shown above is of an (T!%-"1 microcontroller based 0 to % counter which has a $ segment LED displa interfaced to it in order to displa the count# This simple circuit illustrates two things# *ow to setup simple 0 to % up counter using !0"1 and more importantl how to interface a seven segment LED displa to !0"1 in order to displa a particular result# The common cathode seven segment displa D1 is connected to the 6ort 1 of the microcontroller 1(T!%-"12 as shown in the circuit diagram# 73 to 710 are current limiting resistors# -3 is the reset switch and 72)C3 forms a debouncing circuitr # C1) C2 and 81 are related to the cloc' circuit# The software part of the pro9ect has to do the following tas's#

+orm a 0 to % counter with a predetermined dela 1around 1:2 second here2# Convert the current count into digit drive pattern# 6ut the current digit drive pattern into a port for displa ing#

(ll the above said tas's are accomplished b the program given below# &rogram!
ORG 000H //initial starting address START: MOV A,#00001001B // initial value of a u!ulator MOV B,A MOV R0,#0AH //Register R0 initiali"ed as ounter #$i $ ounts fro! 10 to 0 %AB&%: MOV A,B '() A MOV B,A MOV) A,*A+,) // adds t$e -.te in A to t$e /rogra! ounters address MOV ,1,A A)A%% 0&%A1 // alls t$e dela. of t$e ti!er 0&) R0//)ounter R0 de re!ented -. 1 MOV A,R0 // R0 !oved to a u!ulator to $e 2 if it is "ero in ne3t instru tion4 56 START //)$e 2s a u!ulator for "ero and 7u!/s to START4 0one to $e 2 if ounting $as -een finis$ed4 S5M, %AB&% 0B 89H // digit drive /attern for 0 0B 0:H // digit drive /attern for 1 0B ;BH // digit drive /attern for < 0B =9H // digit drive /attern for 8 0B ::H // digit drive /attern for = 0B :0H // digit drive /attern for ; 0B >0H // digit drive /attern for : 0B 0>H // digit drive /attern for > 0B >9H // digit drive /attern for ? 0B :9H // digit drive /attern for @ 0&%A1: MOV R=,#0;H // su-routine for dela. AA'T1: MOV R8,#00H AA'T<: MOV R<,#00H AA'T8: 05(6 R<,AA'T8 05(6 R8,AA'T< 05(6 R=,AA'T1 R&T &(0

About t%e program! .nstruction ;<=C ()>(?6C is the instruction that produces the re&uired digit drive pattern for the displa # E@ecution of this instruction will add the value in the accumulator ( with the content of the program counter1address of the ne@t instruction2 and will move the data present in the resultant address to (# (fter this the program resumes from the line after ;<=C ()>(?6C#

.n the program) initial value in ( is 00001001A# E@ecution of ;<=C ()>(?6C will add oooo1001A to the content in 6C 1 address of ne@t instruction2# The result will be the address of command DA 3+* 1line1"2 and the data present in this address ie 3+* 1digit drive pattern for 02 gets moved into the accumulator# ;oving this pattern in the accumulator to 6ort 1 will displa 0 which is the first count# (t the ne@t count) value in ( will advance to 00001010 and after the e@ecution of ;<=C ()>?6C )the value in ( will be 05* which is the digit drive pattern for 1 and this will displa 1 which is the ne@t count and this c cle gets repeated for subse&uent counts# The reason wh accumulator is loaded with 00001001A 1% in decimal2 initiall instructions from line % to line 1" consumes % b tes in total# is that the

The lines 1" to 24 in the program which starts with command DA can be called as a Loo' (p )able *L()+# Command DA is 'nown as Define A te B which defines a b te# This table defines the digit drive patterns for $ segment displa as b tes 1in he@ format2# ;<=C operator fetches the b te from this table based on the result of adding 6C and contents in the accumulator# 7egister A is used as a temporar storage of the initial value of the accumulator and the subse&uent increments made to accumulator to fetch each digit drive pattern one b one from the loo' up table1LCT2# Note,- .n line 5) (ccumulator is incremented b 1 each time 1each loop iteration2 to select the ne@t digit drive pattern# -ince ;<=C operator uses the value in ( to fetch the digit drive pattern from LCT) value in (CC has to be incremented:manipulated accordingl # The digit drive patterns are arranged consecutivel in LCT# 7egister 70 is used as a counter which counts from 10 down to 0# This ensures that digits from o to % are continuousl displa ed in the $ segment LED# Dou ma note lines 4) 11) 12) and 13 in the above program# Line 4 initialiEes 70 to 10 1<(h2# Fhen the program counter reaches line 11 for the first time) $ segment LED has alread displa ed 0# -o we can reduce one count and that is wh we have written DEC 7o# Fe need to continuousl chec' if 70 has reached full count 1that is 02# .n order to do that lines 12 and 13 are used# Fe move 70 to accumulator and then use the Jump if Gero 1JG2 instruction to chec' if accumulator has reached Eero# .f (ccH0) then we ma'es the program to 9ump to -T(7T 1initial state2 and hence we restart the $ segment LED to displa from 0 to % again# .f (cc not e&ual to Eero) we continue the program to displa the ne@t digit 1chec' line 142#

.ultiple/ing 7 segment display to 8051!


-uppose ou need a three digit displa connected to the !0"1# Each $ segment displa have ! pins and so a total amount of 24 pins are to the connected to the microcontroller and there will be onl ! pins left with the microcontroller for other input output

applications# (lso the ma@imum number of displa s that can be connected to the !0"1 is limited to 4 because !0"1 has onl 4 ports# ;ore over three 3 displa s will be <I alwa s and this consumes a considerable amount of power# (ll these problems associated with the straight forward method can be solved b multiple@ing # .n multiple@ing all displa s are connected in parallel to one port and onl one displa is allowed to turn <I at a time) for a short period# This c cle is repeated for at a fast rate and due to the persistence of vision of human e e) all digits seems to glow# The main advantages of this method are

+ewer number of port pins are re&uired # Consumes less power# ;ore number of displa units can be interfaced 1ma@imum 242#

The circuit diagram for multiple@ing 2 seven segment displa s to the !0"1 is shown below#

;ultiple@ing $ segement displa to !0"1 Fhen assembled and powered on) the circuit will displa the number J15K and let us see how it is done# .nitiall the first displa is activated b ma'ing 63#0 high and then digit drive pattern for L1M is loaded to the 6ort 1# This will ma'e the first displa to show L1M# .n the mean time 63#1 will be low and so do the second displa will be <++# This condition is maintained for around 1ms and then 63#0 is made low# Iow both displa s will be <++# Then the second displa is activated b ma'ing 63#1 high and then the digit drive pattern for L5M is loaded to the port 1# This will ma'e the second displa to show L5M# .n the mean time 63#0 will be low and so the second displa will be <++# This

condition is maintained for another 1ms and then port 3#1 is made low# This c cle is repeated and due to the persistence of vision ou will feel it as L15M# Transistor N1 drives the first displa 1D12 and transistor N2 drives the second displa 1D22# 711 and 712 are the base current limiting resistors of N1 and N2# The purpose of other components are e@plained in the first circuit# &rogram!
ORG 000H // initial starting address MOV ,1,#00000000B // lears /ort 1 MOV R:,#1H // stores B1B MOV R>,#:H // stores B:B MOV ,8,#00000000B // lears /ort 8 MOV 0,TR,#%AB&%1 // loads t$e adress of line <@ to 0,TR MA'(: MOV A,R: // B1B is !oved to a u!ulator S&TB ,840 // a tivates 1st dis/la. A)A%% 0'S,%A1 // alls t$e dis/la. su- routine for getting t$e /attern for B1B MOV ,1,A // !oves t$e /attern for B1B into /ort 1 A)A%% 0&%A1 // alls t$e 1!s dela. )%R ,840 // dea tivates t$e 1st dis/la. MOV A,R> // B<B is !oved to a u!ulator S&TB ,841 // a tivates <nd dis/la. A)A%% 0'S,%A1 // alls t$e dis/la. su- routine for getting t$e /attern for B<B MOV ,1,A // !oves t$e /attern for B<B into /ort 1 A)A%% 0&%A1 // alls t$e 1!s dela. )%R ,841 // dea tivates t$e <nd dis/la. S5M, MA'( // 7u!/s -a 2 to !ain and . le is re/eated 0&%A1: MOV R8,#0<H 0&%1: MOV R<,#09AH 0&%<: 05(6 R<,0&%< 05(6 R8,0&%1 R&T 0'S,%A1: MOV) A,*A+0,TR // adds t$e -.te in A to t$e address in 0,TR and loads A #it$ data /resent in t$e resultant address R&T %AB&%1:0B 89H 0B 0:H 0B ;BH 0B =9H 0B ::H 0B :0H 0B >0H 0B 0>H 0B >9H 0B :9H &(0

You might also like