Anda di halaman 1dari 18

HOME FORUMS DATASHEETS LAB MANUAL TESTING COMPONENTS BUY PROJECT KITS

Electronic Circuits and Diagram-Electronics Projects and Design


Search
Custom Search

Interfacing Seven segment display to 8051


ADMIN JUNE - 20 - 2012 26 COMMENTS

A Note about 7 segment LED display.


This article is about how to interface a seven segment LED display to an 8051 microcontroller. 7 segment LED display is very popular and it can display digits from 0 to 9 and quite a few characters like A, b, C, ., H, E, e, F, n, o,t,u,y, etc. Knowledge about how to interface a seven segment display to a micro controller is very essential in designing embedded systems. A seven segment display consists of seven LEDs arranged in the form of a squarish 8 slightly inclined to the right and a single LED as the dot character. Different characters can be displayed by selectively glowing the required LED segments. Seven segment displays are of two types,common cathode and common anode. In common cathode type , the cathode of all LEDs are tied together to a single terminal which is usually labeled as com and the anode of all LEDs are left alone as individual pins labeled as a, b, c, d, e, f, g & h (or dot) . In common anode type, 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 typical 7 segment LED display is shown in the image below.

7 segment LED display

Digit drive pattern.


Digit drive pattern of a seven segment LED display is simply the different logic combinations of its terminalsa to h in order to display different digits and characters. The common digit drive patterns (0 to 9) of a seven segment display are shown in the table below. Digit a b c d e f g 0 1 1 1 1 1 1 0 1 0 1 1 0 0 0 0 2 1 1 0 1 1 0 1 3 1 1 1 1 0 0 1 4 0 1 1 0 0 1 1 5 1 0 1 1 0 1 1 6 1 0 1 1 1 1 1 7 1 1 1 0 0 0 0 8 1 1 1 1 1 1 1 9 1 1 1 1 0 1 1

Interfacing seven segment display to 8051.

Interfacing 7 segment display to 8051

The circuit diagram shown above is of an AT89S51 microcontroller based 0 to 9 counter which has a 7 segment LED display interfaced to it in order to display the count. This simple circuit illustrates two things. How to setup simple 0 to 9 up counter using 8051 and more importantly how to interface a seven segment LED display to 8051 in order to display a particular result. The common cathode seven segment display D1 is connected to the Port 1 of the microcontroller (AT89S51) as shown in the circuit diagram. R3 to R10 are current limiting resistors. S3 is the reset switch and R2,C3 forms a debouncing circuitry. C1, C2 and X1 are related to the clock circuit. The software part of the project has to do the following tasks. Form a 0 to 9 counter with a predetermined delay (around 1/2 second here). Convert the current count into digit drive pattern. Put the current digit drive pattern into a port for displaying. All the above said tasks are accomplished by the program given below.

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

MOV R0,#0AH //Register R0 initialized as counter which counts from 10 to 0

About the program.


Instruction MOVC A,@A+PC is the instruction that produces the required digit drive pattern for the display. Execution of this instruction will add the value in the accumulator A with the content of the program counter(address of the next instruction) and will move the

data present in the resultant address to A. After this the program resumes from the line after MOVC A,@A+PC. In the program, initial value in A is 00001001B. Execution of MOVC A,@A+PC will add oooo1001B to the content in PC ( address of next instruction). The result will be the address of command DB 3FH (line15) and the data present in this address ie 3FH (digit drive pattern for 0) gets moved into the accumulator. Moving this pattern in the accumulator to Port 1 will display 0 which is the first count. At the next count, value in A will advance to 00001010 and after the execution of MOVC A,@+PC ,the value in A will be 06H which is the digit drive pattern for 1 and this will display 1 which is the next count and this cycle gets repeated for subsequent counts. The reason why accumulator is loaded with 00001001B (9 in decimal) initially is that the instructions from line 9 to line 15 consumes 9 bytes in total. The lines 15 to 24 in the program which starts with command DB can be called as a Look Up Table (LUT). Command DB is known as Define Byte which defines a byte. This table defines the digit drive patterns for 7 segment display as bytes (in hex format). MOVC operator fetches the byte from this table based on the result of adding PC and contents in the accumulator. Register B is used as a temporary storage of the initial value of the accumulator and the subsequent increments made to accumulator to fetch each digit drive pattern one by one from the look up table(LUT). Note:- In line 6, Accumulator is incremented by 1 each time (each loop iteration) to select the next digit drive pattern. Since MOVC operator uses the value in A to fetch the digit drive pattern from LUT, value in ACC has to be incremented/manipulated accordingly. The digit drive patterns are arranged consecutively in LUT. Register R0 is used as a counter which counts from 10 down to 0. This ensures that digits from o to 9 are continuously displayed in the 7 segment LED. You may note lines 4, 11, 12, and 13 in the above program. Line 4 initializes R0 to 10 (OAh). When the program counter reaches line 11 for the first time, 7 segment LED has already displayed 0. So we can reduce one count and that is why we have written DEC Ro. We need to continuously check if R0 has reached full count (that is 0). In order to do that lines 12 and 13 are used. We move R0 to accumulator and then use the Jump if Zero (JZ) instruction to check if accumulator has reached zero. If Acc=0, then we makes the program to jump to START (initial state) and hence we restart the 7 segment LED to display from 0 to 9 again. If Acc not equal to zero, we continue the program to display the next digit (check line 14).

Multiplexing 7 segment display to 8051.


Suppose you need a three digit display connected to the 8051. Each 7 segment display have 8 pins and so a total amount of 24 pins are to the connected to the microcontroller and there will be only 8 pins left with the microcontroller for other input output applications. Also the maximum number of displays that can be connected to the 8051 is limited to 4 because 8051

has only 4 ports. More over three 3 displays will be ON always and this consumes a considerable amount of power. All these problems associated with the straight forward method can be solved by multiplexing . In multiplexing all displays are connected in parallel to one port and only one display is allowed to turn ON at a time, for a short period. This cycle is repeated for at a fast rate and due to the persistence of vision of human eye, all digits seems to glow. The main advantages of this method are Fewer number of port pins are required . Consumes less power. More number of display units can be interfaced (maximum 24). The circuit diagram for multiplexing 2 seven segment displays to the 8051 is shown below.

Multiplexing 7 segement display to 8051

When assembled and powered on, the circuit will display the number 16 and let us see how it is done. Initially the first display is activated by making P3.0 high and then digit drive

pattern for 1 is loaded to the Port 1. This will make the first display to show 1. In the mean time P3.1 will be low and so do the second display will be OFF. This condition is maintained for around 1ms and then P3.0 is made low. Now both displays will be OFF. Then the second display is activated by making P3.1 high and then the digit drive pattern for 6 is loaded to the port 1. This will make the second display to show 6. In the mean time P3.0 will be low and so the second display will be OFF. This condition is maintained for another 1ms and then port 3.1 is made low. This cycle is repeated and due to the persistence of vision you will feel it as 16. Transistor Q1 drives the first display (D1) and transistor Q2 drives the second display (D2). R11 and R12 are the base current limiting resistors of Q1 and Q2. The purpose of other components are explained in the first circuit.

Program.
ORG MOV MOV MOV MOV MOV MAIN: SETB "1" MOV ACALL CLR MOV SETB "2" MOV ACALL CLR DELAY: DEL1: DEL2: DJNZ RET DISPLAY: MOVC A,@A+DPTR // adds the byte in A to the address in DPTR and P1,A P3.1 // DELAY // moves // the pattern calls deactivates MOV MOV DJNZ for the the "2" into 1ms 2nd port 1 delay display R3,#02H R2,#0FAH R2,DEL2 R3,DEL1 P1,A P3.0 A,R7 P3.1 // DELAY // // // moves // "2" the pattern calls deactivates is activates for the the moved to 2nd "1" into 1ms 1st port 1 delay display accumulator display 000H P1,#00000000B R6,#1H R7,#6H P3,#00000000B DPTR,#LABEL1 MOV P3.0 // loads // // A,R6 // the "1" is activates // initial // // // clears adress of moved line to 1st clears stores stores port 29 to starting port address 1 "1" "6" 3 DPTR display

accumulator

ACALL DISPLAY // calls the display sub routine for getting the pattern for

ACALL DISPLAY // calls the display sub routine for getting the pattern for

SJMP MAIN // jumps back to main and cycle is repeated

loads RET LABEL1:DB DB DB DB DB DB DB DB DB DB 6FH END

with

data

present

in

the

resultant

address 3FH 06H 5BH 4FH 66H 6DH 7DH 07H 7FH

Got any doubts/questions? Ask here in comments!


You may also like:

Interfacing dot matrix LED display to 8051 Interfacing hex keypad to 8051 Delay using 8051 timer Software delay routine in 8051 microcontroller Random number generator using 8051 Program to seperate bytes to nibbles in 8085 Working of Plasma Display SCR Control circuits Variable power supply using 7805 Getting Started with Keil uVision
Search

We recommend:

Custom Search

Posted in 8051 Tags: interfacing 7 segment display to 8051, multiplexing 7 segment display to 8051

Leave a Reply
Name (required) Mail (will not be published) (required) Website

Submit Comment

26 Responses to Interfacing Seven segment display to 8051

samarnath dev
January 16, 2014 at 1:02 am

i use 4094b with common cathod fnd to 8051 #11010010B ;210D d2h for 4h show ,now i want to convert to hex so pleas help me as asm idia . Reply

laxmana rao
September 18, 2013 at 11:49 pm

sir, how to print 1 to 24 on seven segment display. here two switchs are there. first one is 1 to 24 print.(when ever this pin is press). second is number selection pin(when ever this pin is press). if it is 20 number select, clock will must be on . could plese send me source code thank you. Reply

suneel
August 31, 2013 at 11:11 pm

thank you sir for great description! (Code snippet edited by Administrator) while compiling the above program ,error(variable or constant not found)is comming.please tell me how to fix it Reply

jojo
September 5, 2013 at 4:32 am

Hi Suneel, I have edited the code snippet due to its length! However the error can be due to a reference to an undefined variable in the program. Just read through you codes twice to spot an undefined variable/constant. Reply

Jaisin jacob
November 30, 2012 at 1:33 am

In interfacing 7 sdgment 8051,there are some one are earthed.what this exactly do? Reply

Ashwani Kumar Sharma


September 21, 2012 at 10:10 pm

Thanks sir the way of writting the article is awesome,thinge become pretty much easy after studying the articles.The articles have their practical side of own. Reply
o

jojo
September 22, 2012 at 6:35 pm

Hello Ashwani, Thanks for the nice words. Keep looking for more articles. Reply

Marcelo
September 16, 2012 at 5:23 pm

dear sir, i dont understand very well the mova a,@a+pc, when the program is in this line, the pc is with value of 0bh, with the acc, will be 0bh+0aH = 15h, the db=3fh is in the 15h position? tks! Reply

hameed

August 11, 2012 at 3:40 am

i want to make a led display board which shows digits that are pressed on a tv remote .please guide.. Reply

kamlesh vaghela
July 22, 2012 at 11:27 pm

good project Reply

Manjinder
July 16, 2012 at 1:03 am

sir, due to the interrupt the brightness of seven segment displays(by using green leds) is decrease any idea to increase brightness of displays please help me Reply

namgvaerarak
June 28, 2012 at 4:53 am

hey , thanks for the code , it sure does look like it will work hey i was wondering , i recently read the book 8051 mc and embedded systems and on page no 99 we have another code ORG 0000H START : MOV R1,#10 MOV DPTR,#400H BACK : CLR A MOVC A,@A+DPTR MOV P1,A ACALL DELAY INC DPTR DJNZ R1, BACK SJMP START

ORG 0400H DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH END plzz let me know whether this code could also work thanks a ton Reply
o

jojo
July 2, 2012 at 1:23 am

@namgvaerarak Logically it should work. I havent seen any errors in particular. Reply
o

Rajesh
October 17, 2012 at 3:58 am

it will work, i guess. Reply


o

Sachin Shintre
October 21, 2012 at 6:09 pm

Sir I have connect the 7segment inter fessing ckt. but connect input as the microcontroller in IR transmeter using ic358 ckt. then how to changes in program Reply

G.Sai Pranav
June 25, 2012 at 8:39 pm

I have used edsim51 simulator to learn this module\run the program. But I have a faced a problem,in that simulator the 2s compliment of the instruction DB 3F i.e DB C0 has to be written for getting the the display for 0.That means for the L.E.D to glow 0 has to be given to the respective pin not 1. Is it the fault of simulator or Is it my fault? Reply
o

admin

June 26, 2012 at 12:44 am

@G.Sai Pranav we have tested the circuit in real environment. different simulators have different specifications and you have to adjust the code accordingly. Reply
o

Amy
October 11, 2012 at 9:29 pm

That is because the simulator follows a common anode configuration. So a low to the respective pin needs to be provided to make the LED glow Reply

Srihari Rao
June 22, 2012 at 8:24 pm

Okay anyway thanks for the response.. Reply

Waiting for more posts on microcontroller.

Srihari Rao
June 21, 2012 at 7:18 pm

If you have Multisim software then please check out this file.. http://www.mediafire.com/?83sb6eoe56a98rq Reply
o

Manjinder
July 16, 2012 at 3:44 am

You use wrong Seven segment display this is not CA this is CC Display Reply

Srihari Rao
June 21, 2012 at 7:04 pm

Sir i use NI Multisim 11.0 software to built these circuits in my PC. But when i checked this circuit in Multisim software it is not working. The seven segment is not displaying me the

numbers. But the assembler results is showing zero errors and zero warnings. I want to know weather it is software fault or the circuit fault. If it is the software fault then please recommend me some software to build circuits like these. Reply
o

jojo
June 21, 2012 at 10:07 pm

@shrihari rao We tested this circuit in a real environment. We have not used any simulators to test software/circuit. So I cant tell exactly which part is causing the problem. Reply

jojo
June 21, 2012 at 2:57 am

@shrihari -We have tested this circuit here in our lab. It worked really fine. The program we developed is perfect. Please tell whats the problem you face?? Reply

Srihari Rao
June 20, 2012 at 10:34 pm

https://www.facebook.com/groups/technotweets/permalink/399892846713713/ Please see this.. Help me.. Reply

Srihari Rao
June 20, 2012 at 8:52 pm

Thanks for info.. Reply

Want more posts like this..

GET DAILY UPDATES VIA EMAIL


Enter your email

Subscribe

LATEST ARTICLES

Line follower robot using 8051 microcontroller Invention History of Television

The Invention Story of Barcodes Invention History of the Telephone and the Controversies The Story Behind the Invention of Field Effect Transistors Invention Story of Mobile Phone The Story Behind the Accidental Invention of X-Ray The Invention History of Fuel Cells Invention Story of Fiber Optics Interfacing dot matrix LED display to 8051

CATEGORIES

101-Announcements 555 Timer IC 8051 8051 projects Amplifier Circuits Arduino Audio Circuits Automotive Circuits AVR Basic Electricity Basic Electronics Battery Circuits C plus plus C Programming Cable TV Circuits Camera Technology Clipping and Clamping Circuits Clocking & Timer Circuits Conversion Circuits Counter Circuits Counters Digital Electronics Education & Training Electronic Components Electronic Keys & Locks Electronics Books Electronics Jobs

Embedded Systems Equipment Reviews Events Fan Circuits Filter Circuits Fire Alarm Fun & Game Circuits Gadget Reviews Ham Radio Circuits High Voltage Circuits History Home Circuits Industrial Circuits Instruments Integrated Circuits Inverters Lab Manuals LED related Light Related Lighting Circuits MATLAB Microcontrollers Mobile Phone Related Motor Related Nanotechnology Oscillators Peripheral Interface Controller (PIC) Power Controller Circuits Power Electronics Power Supplies Project Ideas Projects Proximity Detectors Radio Circuits Radio Transmitters Raspberry Pi Relays Remote Circuits Reviews Robotics RTOS Security & Saftey Sensor Circuits Signal Conditioners Signal Generators Speed Controller Circuits State space analysis Switching Circuits Tech News Telephone Related Television Related Temperature Related Test & Measurement Circuits Testing Components

Three phase circuits Timer Circuits Tone generator circuits Tools and Softwares Transmitters Tutorials UPS USB Circuits Videos VLSI Voltage Regulators

LIKE US ON FACEBOOK RECENT COMMENTS


o o o
R D LAMBUD on Electronics Mini projects abubakar on 100 Watt sub woofer amplifier. T.ASAITHAMBI on Simple UPS SEOPost.com on Jet engine sound generator bittu on Simple electronics projects and circuits Seetharaman on 100W MOSFET power amplifier Seetharaman on Water level Controller Seetharaman on Single Chip FM Radio circuit Seetharaman on Single Chip FM Radio circuit Seetharaman on Mains Operated LED Circuit Fer on Modified lamp dimmer circuit mahesh on The Story Behind the Invention of Field Effect Transistors mahesh on The Story Behind the Invention of Field Effect Transistors colpitts oscillator on Hartley Oscillator lcd950 on Tweeter Crossover circuit

PAGES
About Advertise With Us Authors Buy Project Kits Datasheets Electronic Circuit Symbols Lab Manuals Electronic Circuits Lab Microcontroller lab Microprocessor Lab Privacy Policy Project Contests Sitemap Testing Components

Popular Tags
555 IC

555 timer Audio Amplifier Circuits Audio circuits circuit

design circuit

diagram Electronic Circuits Electronic Components Electronic InstrumentsFilter


Circuits History of Electronics hobby

circuits hobby projects Home

CircuitsIC Integrated Circuits Most Popular Circuits Nanotechnology NE555 timer Oscillators PICPower Supplies Radio Circuits SCR Simple Electronics Projects Tech News ThyristorsTutorials VLSI Voltage Regulators

Most Discussed

150 Watt amplifier circuit 100 Watt sub woofer amplifier. Mains Operated LED Circuit Automatic LED Emergency Light-Modified Version 2 km FM transmitter Suggest a Topic to Publish & Win a 8GB Pen Drive Automatic LED Emergency Light Copyright 2007 - 2011 Circuitstoday.com Designed by Web Design Cochin

Anda mungkin juga menyukai