Search Your Query

Custom Search

Monday 30 May 2011

Interfacing 7-Segment Display using lookup table


The Light Emitting Diode (LED), finds its place in many applications in this modern electronic fields. One of them is the Seven Segment Display. Seven-segment displays contains the arrangement of the LEDs in “Eight” (8) passion, and a Dot (.) with a common electrode, lead (Anode or Cathode). The purpose of arranging it in that passion is that we can make any number out of that by switching ON and OFF the particular LED’s. Here is the block diagram of the Seven Segment LED arrangement.
Pin configuration of a seven segment display:
7 segment pin configuration
LED’s are basically of two types:
  1. Common Cathode (CC)
    All the 8 anode legs uses only one cathode,  which is common.
  2. Common Anode (CA)
    The common leg for all the cathode is of Anode type.
For the discussion purpose, we use CC LED, where by just reversing the logical voltages we can implement the same for CA LED also.
In a CC LED, all the 8 legs (‘a’ through ‘h’) are of anode type and the common cathode will be connected to the GND of the supply. By energizing any of the legs with +5 Volts will lead to switch the correspondent segment ON. In the microprocessor binary system, 0Volts will be considered as Binary 0, and 5Volts will be considered as Binary1. Considering these two condition, we can make an arrangement as the microcontroller gives OUT the 0s and 1s through its ports, which is connected to the 8 legs of the LED. Of course, we can control the Port Output; implicitly we can Switch-ON required legs of the display.
There 2 methods of interfacing LED with the Microcontroller Intel 8051/8951.
  1. Using lookup table. This uses 7 output pins of microcontroller
  2. Using 7447 decoder. This method uses 4 output pins of microcontroller
The difference between the two main methods is simple and clear. In both the cases, microcontroller communicates with external world through its ports. But, in the 1st case, we connect all the 8 pins of the port directly to the LED and control the voltage through the ports manually to display the desired number.  But, in the second case, we send the BCD of the number that we wanted to display to a middleware IC 7447, the BCD to LED code converter, which by itself gives out the correspondent 7 segment codes to the LED.
Here we explain using lookup table. Click here for the method “using 7447 decoder”
Using Lookup Table:
As we discussed, this method uses the port of the microcontroller to display the desired number. The common cathode pin is connected to GND by external wire, if it is the CC LED and in the case of the common Anode LED, the Anode pin is connected to +Vcc. Here, other pins of the LED are connected to Port 2 of 8951. A table will be prepared which relates the BCD code to the LED display code (pattern). We call it as Lookup table. The table below explains how we construct the Lookup table. Circuit diagram is given below.
Circuit diagram for Common Anode 7-Segment Display:

7 segment circuit comon anode
Circuit diagram for Common Cathode 7-Segment Display:

7 segment circuit comon cathode
























Calculation of lookup table as follows:
The lookup table contains the input pattern for the LED legs, to display the corresponding digits.
The table shows the seven segment requirement pattern to display the Hex number, with the Seven segment conversion.
For example, Let us consider the display of the number 0, where we need to switch ON all the LEDs which are there at the boundary. i.e. for a CC LED, we  should supply 5 volts to these LEDs. The 6 LEDs (‘a’ through ‘f’) should get binary 1, the dot and the (middle) hyphen segment should get 0Volts or the binary Zero. Effectively the Seven segment pattern code will be (0011 1111) 3Fh. That is what we OUT through the port pins.
For a Common Anode LED, the display pattern will be the complement of that of Common Cathode pattern.
For Common Cathode :
Common Cathode Lookup Table
For common Anode:
Common Anode Lookup Table
ASM program:
This program displays characters 0 through 9 on seven-segment display connected directly to the port 2 of the microcontroller Intel8951.
Here, the look up table is stored from the memory location 19H of the microcontroller. The first set is the pattern code for common anode followed by the common cathode.

//Look up table for common Anode
 
org 0000
mov r0,#19h
mov @r0,#0c0fh // Code for the digit 0
inc r0
mov @r0,#0f9h // Code for the digit 1
inc r0
mov @r0,#0a4h // Code for the digit 2
inc r0
mov @r0,#0b0h // Code for the digit 3
inc r0
mov @r0,#099h // Code for the digit 4
inc r0
mov @r0,#092h // Code for the digit 5
inc r0
mov @r0,#082h // Code for the digit 6
inc r0
mov @r0,#0f8h // Code for the digit 7
inc r0
mov @r0,#0f0h // Code for the digit 8
inc r0
mov @r0,#98h // Code for the digit 9
 
//Look up table for common Cathode
 
org 0000
mov r0,#19h
mov @r0,#0bfh
inc r0
mov @r0,#86h
inc r0
mov @r0,#0dbh
inc r0
mov @r0,#0cfh
inc r0
mov @r0,#0e6h
inc r0
mov @r0,#0edh
inc r0
mov @r0,#fdh
inc r0
mov @r0,#87h
inc r0
mov @r0,#0ffh
inc r0
mov @r0,#0e7h
 
again: mov a,#00h ; Start form zero
up: mov r2,a
mov r0,#19h ; Load starting address of luck up table
add a,r0
mov r0,a
mov a,@r0 ; Get the LED equivalent
mov p2,a ; Move to Port 2
 
mov r3,#255 ; Delay
D1: mov r1,#255
D: djnz r1,D
djnz r3,D1
mov a,r2
inc a
cjne a,#0ah,up
sjmp again

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...