Sunteți pe pagina 1din 14

8051 HOW-TO GUIDE

Interfacing 7SEG with


8051

Contents at a Glance
8051 Primer Board ...........................................................3
I2C (Inter Integrated Circuit) . Error! Bookmark not defined.
Seven Segment Display ....................................................3
Interfacing Seven Segment Display ..................................4
Interfacing Seven Segment with 8051 ..............................5
Pin Assignment with 8051 ................................................6
Circuit Diagram to Interface 7 seg with 8051 ....................7
Source Code ....................................................................7
C Program to 7 Segment Display using 8051 .....................8

Join the Technical Community Today!


http://www.pantechsolutions.net

8051 Primer Board


The 8051 Primer board is specifically designed to help
students to master the required skills in the area of
embedded systems. The kit is designed in such way that all
the possible features of the microcontroller will be easily
used by the students. The kit supports in system
programming (ISP) which is done through serial port.
NXPs 8051 (AT89V51RD2), 8051 Primer Kit is proposed
to smooth the progress of developing and debugging of
various

designs

encompassing

of

speed

8-bit

Microcontrollers.
Seven Segment Display
A seven segment display is the most basic electronic
display device that can display digits from 0-9. The most
common configuration has an array of eight LEDs arranged
in a special pattern to display these digits. They are laid out
as a squared-off figure 8. Every LED is assigned a name
Join the Technical Community Today!
http://www.pantechsolutions.net

from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to
'g' are used to display the numerals while eighth LED 'h' is
used to display the dot/decimal.
Interfacing I2C - Seven Segment Display
Fig. 1 shows how to interface the seven segments with
microcontroller. Seven segments are generally available in
ten pin package. While eight pins correspond to the eight
LEDs, the remaining two pins (at middle) are common and
internally

shorted.

These

segments

come

in

two

configurations, namely, Common cathode (CC) and


Common anode (CA). In CC configuration, the negative
terminals of all LEDs are connected to the common pins.
The common is connected to ground and a particular LED
glows when its corresponding pin is given high. In CA
arrangement, the common pin is given a high logic and the
LED pins are given low to display a number.

Join the Technical Community Today!


http://www.pantechsolutions.net

Fig. 1 Interfacing I2C - 7segment to Microcontroller


Interfacing Seven Segment with 8051
We now want to display a four digit number in 8051
Primer Board by using seven segment displays. The seven
segment display is connected with 801 controllers.
In 8051 Primer Kit, 4 nos. of common anode seven
segment displays are controlled I/O Lines(p1.0-p1.7).The 7segmend display is powered from the 5V power supply
enabled by switch SW30.

Join the Technical Community Today!


http://www.pantechsolutions.net

7-SEG

8051 Pins

Digit - 1

P3.4

Digit 2

P3.5

Digit 3

P3.6

Digit - 4

P3.7

Seg - a

P1.0

VCC

2
3

Digit - 1

1K

Segment Lines

P1.2

Seg d

P1.3

Seg e

P1.4

Seg f

g b
e d c

P1.5

Seg g

P1.6

Seg dp

P1.7

seg-a
Seg-b
Seg-c
seg-d
seg-e
seg-f
seg-g
seg--dp

7
6
4
2
1
9
10
5

A
B
C
D
E
F
G
DP

U1

7 SEG DISP

Make high to - digit selection


Make low to - segment

+5V
SW30

Make switch SW30 to


7SEG label marking position

CA

Seg c

CA

P1.1

Seg b

7-Segment Display

Digit select lines

Pin Assignment with 8051

OFF 1

2
3
4

8 ON
7
6
5

7SEG
LCD
SM/RL
GLCD

PWR ON/OFF

Join the Technical Community Today!


http://www.pantechsolutions.net

Circuit Diagram to Interface 7 seg with 8051

Source Code
The Interfacing seven segment displays with 8051
program is very simple and straight forward that display a
four digit number in seven segment displays by using I/O
Lines. The C programs are developed in Keil software.

Join the Technical Community Today!


http://www.pantechsolutions.net

C Program to 7 Segment Display using 8051


***************************************************************************************
Title : Program to I2C - Seven Segment display
***************************************************************************************
#include<stdio.h>
#include<reg51.h>
unsigned char SetDisplay(unsigned char);
void delay();
sbit eseg1000 = P3^7;
sbit eseg100 = P3^6;
sbit eseg10 = P3^5;
sbit eseg1

= P3^4;

unsigned char d0,d1,d2,d3;

unsigned char SetDisplay(unsigned char value)


{
unsigned char segment[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98};
if(value<=10)
return segment[value];
else
return 0;

Join the Technical Community Today!


http://www.pantechsolutions.net

//-------------//Delay Function
//-------------void delay()
{
int i;
for(i=0; i<500; i++)
i = i + 0;
}

//-------------//Main Program
//-------------void main(void)
{
unsigned char count = 0;
unsigned long timer = 0;
int turn = 1;
P2 = 0xff;
while(1)
{
if(turn==1)

//7-Seg Display 0

Join the Technical Community Today!


http://www.pantechsolutions.net

eseg1000=0;
eseg100=0;
eseg10=0;
eseg1=1;
P1=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2)

//7-Seg Display 1

{
eseg1=0;
eseg1000=0;
eseg100=0;
eseg10=1;
P1=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3)

//7-Seg Display 2

{
eseg10=0;
eseg1=0;

Join the Technical Community Today!


http://www.pantechsolutions.net

eseg1000=0;
eseg100=1;

P1=SetDisplay(d2);
turn = 0;
delay();
}
else

//7-Seg Display 3

{
eseg100=0;
eseg10=0;
eseg1=0;
eseg1000=1;
P1=SetDisplay(d3);
turn = 1;
delay();
}

if(timer == 100){
d0++;
timer=0;
if(d0>=10){
d0=0;
d1++;

Join the Technical Community Today!


http://www.pantechsolutions.net

if(d1>=10){
d1=0;
d2++;

if(d2>=10){
d2=0;
d3++;
if(d3>=10){
d3=0;
}
}
}
}
}
timer++;
}
}

Join the Technical Community Today!


http://www.pantechsolutions.net

Did you enjoy the read?


Pantech solutions creates information packed technical
documents like this one every month. And our website is a rich
and trusted resource used by a vibrant online community of
more than 1,00,000 members from organization of all shapes
and sizes.

Join the Technical Community Today!


http://www.pantechsolutions.net

What do we sell?
Our products range from Various Microcontroller
development boards, DSP Boards, FPGA/CPLD boards,
Communication Kits, Power electronics, Basic electronics,
Robotics, Sensors, Electronic components and much more . Our
goal is to make finding the parts and information you need
easier and affordable so you can create awesome projects and
training from Basic to Cutting edge technology.

Join the Technical Community Today!


http://www.pantechsolutions.net

S-ar putea să vă placă și