Vous êtes sur la page 1sur 10

7-Segment Numeric LED Displays

In industrial PLC applications, one of the old, but simpler methods of displaying numeric information is to
use one or more 7-Segment numeric displays connected to an output card of a PLC... Although it is
possible to build such a display yourself, it is far more common to employ a pre-manufactured product
such as the 4-digit panel mount unit shown at the top of this page...
To correctly interface a PLC to such a display, it helps to first understand what basic electronic
components are typically employed in their makeup, and how this effects our task of interfacing to, and
programming such a unit... Although both LED and LCD numeric displays are readily available, and
interfaced similarly, we'll concentrate on the more common LED units in the examples to follow...



BCD to 7-Segment Decoder c/w 4-bit Latch
Once 7-Segment LED displays became readily available, a simple IC known as a "BCD to 7-Segment
decoder" was quickly developed to simplify their use... Binary formatted data presented to this IC's inputs
results in the IC's outputs being placed into the correct state to display the equivalent numeral (0 to 9) on
a 7-Segment display...
Although BCD to 7-Segment decoder ICs are available without built in latches, this particular IC includes
a built in 4-bit latch which we will make use of in later examples... For now the latch is set to simply allow
input data to freely pass through to the decoder...

In the above diagram, the 4 toggle switches, SW0 to SW3 are used to select the desired numeral (0-9)
that will appear on the 7-Segment display... By using a decoder, it's now simply a matter of setting the
correct 4-bit BCD pattern feeding the inputs of the decoder, and the decoder takes care of the rest...

BCD Input Data
SW3 SW2 SW1 SW0 Numeral Displayed
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9

The decoder section also has two additional inputs... Lamp Test (LT) turns all segments on so you can
verify at once that all display segments are working, or identify display units that need to be replaced...
This input is normally left at logic 1... The Blanking (BL) input is just the reverse; it forces the entire
display off... This is used in many cases to blank out leading or trailing zeros from a long display... LT will
override BL so you can test even blanked-out display digits...
One should also note that the same circuit could conceivably be controlled by a PLC, if 4 output bits from
a 5VDC PLC output card were used in place of the 4 switches shown... If an 8-bit output card were
available, then two such circuits (2 digits) could be controlled... A 16-bit card would in turn allow us to
control four such circuits (4 digits)..etc...
Multiplexed Digits
By making use of the 4-bit latches that are built into the 4511 IC, we can easily multiplex the digits if so
desired... By properly controlling the state of each latch enable pin (LE) we can use the same input data
lines (4 switches) to selectively write to each 7-Segment display independently... With just a minor
modification to our circuit, we will be able to essentially treat each digit as a unique 4-bit memory location
where BCD data of our choosing can be stored and retained...

In the above schematic diagram, each display may be written to separately... First the BCD equivalent of
the desired numeral (0-9) is set using the 4 data switches... If SW1 is then closed, the current BCD input
data will enter the latch of the upper 4511 IC, and will be passed on to the decoder causing the numeral
to displayed... if SW1 is then opened, the latch will retain the current data, but will now ignore any
changes on it's inputs... The desired numeral will continue to be displayed by the upper LED display until
power is lost, or SW1 is again closed and new data is allowed to enter it's latch...
The Lower 7-Segment display may be written to in a similar fashion... Set the BCD equivalent of the
desired digit using the 4 data switches, then close SW2 momentarily to store and retain the current BCD
data... We might say that we are strobing the data into the display...
We could readily replace the 4 data switches and 2 latch switches if we had 6 5VDC outputs available on
our PLC... If we wished to add additional digits, we would require 1 more PLC output for each digit
added... By multiplexing the data in this fashion we would only require 8 PLC outputs to control a 4 digit
display...






#include < at89C2051.h > /* Include 89C2051 header file */

char num[ ] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void wait (void) /* wait function */

{ ; }

void main( void ){

unsigned char cnt, right;

unsigned int i;

P1 = 0; /* ZERO port P1 & port P3 */

P3 = 0;

for( ;; ){

for (right=0;right<3;right++)

{

P3 = right;

for (cnt=0;cnt<10;cnt++)

{

P1 = num[cnt];

for (i = 0; i < 10000; i++)

{

wait(); /* delay for half second */

}

}

}

}

}






#include<p89v51rd2.h>
#include<7seg.h> /* 7 segment display decode data */

main()
{
while(1)
{
P1 = ZERO; /* To Display "0" in 7 segment display*/
delay(1000); /* 1 second time delay*/
P1 = ONE ;
delay(1000);
P1 = TWO;
delay(1000);
P1 = THREE;
delay(1000);
P1 = FOUR;
delay(1000);
P1 = FIVE;
delay(1000);
P1 = SIX;
delay(1000);
P1 = SEVEN;
delay(1000);
P1 = EIGHT;
delay(1000);
P1 = NINE;
delay(1000);
}
}
<strong>7seg.h
</strong>
// Name : 7seg.h
// Compiler : SDCC
// Target IC : P89v51RD2BN
// Hardware : 7-segment LED
// Oscillator : 20MHz
// Description : program to demonstrate 7-segment LED display.

#define ZERO 0x0C0
#define ONE 0x0F9
#define TWO 0x0A4
#define THREE 0x0B0
#define FOUR 0x99
#define FIVE 0x92
#define SIX 0x82
#define SEVEN 0x0F8
#define EIGHT 0x80
#define NINE 0x90

void delay(unsigned int ms); /* Function for delay routine */
void delayms(); /* function for 1 ms delay*/

/*---------------------------------------------------------------------------
----
Delay Function
delay(unsigned int ms)
-----------------------------------------------------------------------------
--*/
void delay(unsigned int ms)
{
while(ms--)
{
delayms(); /* call the 1 ms delay function for multiple routine*/
}
}

/*---------------------------------------------------------------------------
----
Delay Function for 1 ms with 20Mhz clock
delay(unsigned int ms)
-----------------------------------------------------------------------------
--*/
void delayms() /* 1 ms delay function for 20MHz clock frequency
- this Values are calculated using "TIME8051.exe". */
{
_asm
MOV R2,#4
MOV R1,#57
TT1: DJNZ R1,TT1
DJNZ R2,TT1
_endasm;
}
*************************************************


Push button keypad and 7-segment interfacing:
Hardware:-8 push buttons are connected with P2 with one terminal as common
ground. A common anode type 7-segment display is connected to P0. the program
displays number 1 to 8 on 7-segment depending upon the key is pressed

#include<reg51.h>
void main(void)
{
loop:P2=0xFF; // send all 1's to P1
while(P21==0xFF); // remain within loop till key is not pressed
switch(P1) // when key pressed detect is
{
case 0xFE:
P0=0xF9; // and display digit from 1 to 8
break;
case 0xFD:
P0=0xA4;
break;
case 0xFB:
P0=0xB0;
break;
case 0xF7:
P0=0x99;
break;
case 0xEF:
P0=0x92;
break;
case 0xDF:
P0=0x82;
break;
case 0xBF:
P0=0xF8;
break;
case 0x7F:
P0=0x80;
break;
}
goto loop;
}

Vous aimerez peut-être aussi