Seven Segment Multiplexing Using Pic Microcontroller

advertisement
CONSTRUCTION
DEEPAK GUPTA
Seven Segment
Multiplexing Using
Pic Microcontroller
Seven segment displays are very common for
electronic product to display numerical output.
Many common devices like calculators, watches,
electronic weighing scales,ovens and many other
household items use them. You must have also seen
lifts display the current floor numbers in seven
segment displays. They are primarily used to display
decimal numbers but they can also display a few
alphabets and other characters.Many display
boards ,advertising boards make use of seven
segment LEDs. A seven-segment display is so
named because it is divided into seven different
segments that can be switched on or off.It has an
special arrangement of 7 LED elements to form a
rectangular shape using two vertical segments on
each side with one horizontal segment on the top,
middle, and bottom. By individually turning the
segments on or off, numbers from 0 to 9 and some
letters can be displayed. Seven segment displays
sometime also have an eighth segment to display
the decimal point. Therefore, a seven-segment
display will require seven outputs from the
microcontroller to display a number, and one more
output if the decimal point is to be displayed too.
The figure shows a seven segment display and the
names of the various segments.
The segments are marked with non-capital letters:
a, b, c, d, e, f, g and dp, where dp is the decimal
point. For example if you want to display number 4
then segments that will be ‘on’ are {f,g,b,c} while
rest are ‘off’. The 8 LEDs inside the display can be
arranged with a common cathode or common
anode configuration Depending on whether anode
or cathode of all the leds are common they are of
EM TESTED
EM TESTED
TED
EM TES
Frontline Electronics,
Pvt. Ltd., Salem
two types. 1)
Common anode In common
anode displays, all the anodes are tied together and
the common anode is connected to the supply
voltage Vcc. Individual segments are turned on by
applying logic 0 to their cathodes.
2)
Common cathode With a common
cathode display, the cathodes of all the segment
LEDs are tied together and this common point must
be connected to the ground. A required LED
segment is then turned on by applying a logic 1 to its
anode.
The seven segments were driven individually
through separate I/O pins of the microcontroller. If
we do just like that then for 4 seven segment LED
displays, 28 I/O pins will be required, which is quite
a bit of resources and is not affordable by midrange PIC microcontrollers. That’s why when more
than one seven segment display is used, a
multiplexing technique is used to minimize the
required number of microcontroller pins.
Multiplexing is required when we want to interface 3
or 4 or even more such displays with MCUs since it
we go for normal way it will require lots of IO port.
So the smart way is multiplexingThe multiplexing
concept is based on the principle of persistence of
human vision. A human eye cannot detect a visual
change if the frames change at a rate of 25 (or
more) frames per sec. This means that if events
occur continuously with a time difference of less
than or equal to 0.04 sec (1/25 sec), then we
cannot notice the transition between those events.
Considering this, the seven-segments are switched
on one by one with a very small time delay. Thus,
even though only one segment glows at a time, it
appears that all the segments are glowing
together.Thus the key factor in multiplexing is
switching time of the segments.
Circuit Diagram
Shown below is the multiplexing of 4 common
anode type seven segment LED displays with a
CONSTRUCTION
P I C 1 6 F 6 2 8 A
+5V
microcontroller. The
0.1uF
seven segments are
Vdd
Vss
connected to PORTB
5
14
through current
RA0
+5v
limiting resistors Rs. A
RA1
particular segment is
RA2
active when the
10K
RA3
corresponding PORTB
MCLR
4
RB0
pin is low. However, it Reset
RB1
will not glow until it’s
RB2
anode is connected to
C1
RB3
Vcc. The anodes of the
4.0 MHz
RB4
OSC1
(16)
four LED displays are
RB5
not directly connected
OSC2 (15)
RB6
to Vcc. Instead, 4 PNP
C2
RB7
transistors are used as
PIC16F628A
switches to connect or
C1, c2 = 22pF
disconnect the anode
terminals from Vcc.
When the base of the transistor is high, the
transistor conducts and corresponding digit’s
common anode is connected to Vcc. Therefore, the
transistor selects which display is active. The
conduction of the transistors are controlled by RA0
through RA3 pins of PORTA.
Rb
Rs = 330 R, RB = 1K
Rb
Rb
Rb
+5V
Rs
T
Rs
Rs
T
T
T
T:BC557
a
Rs
Rs
Rs
Rs
dp
4 Common Anode Seven Segment LED Displays

High-performance RISC CPU.

Only 35 instructions to learn.

All instructions single-cycle except
branches.

DC to 20MHz operating speed.

Interrupt capability.

8-level deep hardware stack.
Working

Direct, indirect and relative addressing
The trick is to activate only one digit at a time. All the
modes.
segments of each four digit are connected in

Power-saving sleep mode.
parallel and common of each four digit is tried to

3.5K bytes (2048 x 14-bit words) of Flash
MCUs i/o port via transistors. That means MCU
can select any digit and put the segment data which
program memory.
drives the segments. Only the selected digit will

224 bytes of SRAM data memory.
light up. Then next digit is selected and segment

128 bytes of EEPROM data memory.
data is changed according to the digit that must be

16 I/O pins with individual direction
shown in that place. Similarly each digit is selected
control.
and shown. This is done fast enough that the

High current source/sink for direct LED
human eye cannot see the movement. We can see
drive.
all four digit lit at the same time.
Component Used

Two analog comparators.

PIC16F628A

Two 8-bit timer/counters and one 16-bit
PIC16F628A is one of the very basic and small
timer/counter.
microcontrollers offered by Microchip. It features

Capture, compare, PWM (CCP) module.
3.5K bytes of program memory, 224 bytes of SRAM

USART module.
and 128 bytes of EEPROM data memory, 16 I/O

In-circuit serial programming (ICSP) via
pins, two analog comparators, two 8-bit and one
two pins.
16-bit counter/timers, a capture/compare/PWM
module and USART module. This part is supplied in

5V operation.
an 18-pin DIP package, has an operating speed up

Operating temperature range of-40°C to
to 20MHz, an operating temperature range of +85°C.
40°C to +85°C, and is for 5V operation.

18-pin DIP package.
Features
CONSTRUCTION
count,num0,num1,num2,num3,num4;
TRISA=0;
// Configure PortA as output
port
LATA=0;
TRISB=0;
// Configure PortB as output
port
LATB=0;
for(count=0;count<9999;count++)
// Counter from 0 to 9999
{
num0=count;
These devices target portable devices (MP3
players, glucose meters, tape recorders), intelligent
sensing (smoke, leak or gas detectors, security
systems, thermostats, furnace shut-off), utility
metering (gas, water, and electric, data loggers),
motor control (stepper, fan control, brushless DC,
AC induction, switch reluctance), automobile
controls (dash, door, seats) and toys.
BC547 BC547 is an NPN bi-polar junction
transistor. A transistor, stands for transfer of
resistance, is commonly used to amplify current. A
small current at its base controls a larger current at
collector & emitter terminals.
BC547 is mainly used for amplification and
switching purposes. It has a maximum current gain
of 800. Its equivalent transistors are BC548 and
BC549.
The transistor terminals require a fixed DC voltage
to operate in the desired region of its characteristic
curves. This is known as the biasing. For
amplification applications, the transistor is biased
such that it is partly on for all input conditions. The
input signal at base is amplified and taken at the
emitter. BC547 is used in common emitter
configuration for amplifiers. The voltage divider is
the commonly used biasing mode. For switching
applications, transistor is biased so that it remains
fully on if there is a signal at its base. In the absence
of base signal, it gets completely off.
Program Code
#define seg_port LATD
#define seg_unit LATA.F0
#define seg_decade LATA.F1
#define seg_hundred LATA.F2
#define seg_thousand LATA.F3
unsigned int i=0,j=0,k=0;
void main(void)
{
u n s i g n e d
i n t
value[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF
8,0x80,0x90};
u n s i g n e d
i n t
num1=num0%10;
Extract the value of unit digit
num0=num0-num1;
num0=num0/10;
/
/
num2=num0%10;
/
/
Extract the value of decade digit
num0=num0-num2;
num0=num0/10;
n u m 3 = n u m 0 % 1 0 ;
// Extract the value of hundred digit
num0=num0-num3;
num0=num0/10;
n u m 4 = n u m 0 % 1 0 ;
// Extract the value of thousand digit
num0=num0-num4;
num0=num0/10;
for(i=0;i<10;i++)
/
/
Delay= ((5msx4)x10) = 200ms
{
seg_unit=1;
seg_decade=0;
seg_hundred=0;
seg_thousand=0;
// Display unit digit
seg_port=value[num1];
Delay_ms(5);
seg_unit=0;
seg_decade=1;
seg_hundred=0;
seg_thousand=0;
// Display decade digit
seg_port=value[num2];
Delay_ms(5);
seg_unit=0;
seg_decade=0;
seg_hundred=1;
seg_thousand=0;
// Display hundred digit
seg_port=value[num3];
Delay_ms(5);
seg_unit=0;
seg_decade=0;
seg_hundred=0;
seg_thousand=1
// Display thousand digit
seg_port=value[num4];
Delay_ms(5);
}
}
}
Download