Beruflich Dokumente
Kultur Dokumente
On
By
M.PRATYUSHA - 07241A0224
C.APARNA
- 07241A0228
List of Contents
Abstract
1. Microcontroller
2.1 Introduction
2.2 History
2.3 Definition of a Microcontroller
2.4 Microcontrollers vs Microprocessors
2.5 Memory Unit
2.6 Central Processing Unit
2.7 Bus
2.8 Input Output Unit
2.9 Serial Communication
2.10 Timer Unit
2.11 Watch Dog
2.12 Analog to Digital Converter
2. Introduction to Seven segment display
3. Introduction to 16X2 LCD Display
4. Project Description
4.1 Block diagram
4.2 General working
4.3 Coding
5. Project Methodology
5.1 Components
5.2 Softwares used
5.3 Equipments used
5.4 Procedure of building the digital dice game
5.5 Using the digital dice game
5.6 Hardware schematic
6. Result and Conclusion
7. Advantages
8. Future Scope
9. References and Bibliography
ABSTRACT
All of us have played the game of gambling and are well aware of the working of the dice. Here we
are presenting a circuit to design a digital dice game using an electronic digital dice with the help of a
seven segment display controlled by an 8051 microcontroller. The game designed is a two player one
in which each of the player gets his turn to play with the dice and the player who reaches the target
score(here it is taken to be 39) fastest is declared to be the winner .Both the players have one push
button each which when pressed freezes the count on the digital dice and highlights it on the seven
segment display.In order to record this score and add it up in the successive turns,each player has to
submit the score by pressing the submit score button.The score of both the players and the status of
who leads till that turn is displayed on the LCD screen.Initially a message game start push button
appears on the LCD display.Player 1 begins the game by pressing his button.A score appears and it
gets recorded and displayed on the LCD when he/she submits it.Then a message appears on the LCD
which says player 2 choice.Player 2 repeats the same process as player1 .The status of who leads is
displayed on the LCD after every players turn.Now when player1 gets his next turn his present score
gets added to his previous score and total score is displayed on the LCD.This process continues till
either of the players crosses the preset target score in the programming,(here it is taken to be 39).This
can be changed to any value by changing the preset value in the program.
This project is based on C language programming. The software platform used in this project is Keil
uVision3 and PROTEUS.The unit consists of one LCD, 3 push buttons, a seven segment display, 8051
microcontroller as the main components.
The circuit can be divided into three units: the microcontroller unit , seven segment unit and the LCD
display unit. The microcontroller unit contains a microcontroller circuit ,the seven segment unit
contains a seven segment circuit which is interfaced to the controller and the LCD display unit
contains a 16X2 LCD display interfaced to the microcontroller unit. This seven segment display
displays the numbers from 1 to 9 continuously and it halts at the position user wants.Seven Segment
displays are used in a number of systems to display the numeric information. The seven segment can
display one digit at a time. Thus the no. of segments used depends on the no. of digits in the number to
be displayed. As our idea is to develop a dice game, where the dice count ranges from 0 to 9,we make
use of only one seven segment display.The conventional cubical dice contains numbers from 1 to 6 on
its six faces whereas on an electronic dice it can vary from 0 -9. Interfacing seven segment with a
4
controller or MCU is tricky. The project also explains the interfacing of seven segment display and
16X2 LCD display with MCU AT89C51. It displays the digits 0 to 9 continuously at a predefined time
delay. A seven segment consists of eight LEDs which are aligned in a manner so as to display digits
from 0 to 9 when proper combination of LED is switched on. Seven segment uses seven LEDs to
display digits from 0 to 9 and the eighth LED is used for the dot. Since the seven segment display
works on negative logic, we will have to provide logic 0 to the corresponding pin to make an LED
glow.
The game can further be altered by changing the program and the number of players can also be
increased by adding a little bit of hardware and enhancing the program.
2. MICROCONTROLLERS
2.1 Introduction
Circumstances that we find ourselves in today in the field of microcontrollers had their beginnings in the
development of technology of integrated circuits. This development has made it possible to store
hundreds of thousands of transistors into one chip. That was a prerequisite for production of
microprocessors, and the first computers were made by adding external peripherals such as memory,
input-output lines, timers and other. Further increasing of the volume of the package resulted in creation
of integrated circuits. These integrated circuits contained both processor and peripherals. That is how the
first chip containing a microcomputer, or what would later be known as a microcontroller came about.
2.2 History
It was year 1969, and a team of Japanese engineers from the BUSICOM Company arrived to United
States with a request that a few integrated circuits for calculators be made using their projects. The
proposition was set to INTEL, and Marcian Hoff was responsible for the project. Since he was the one
who has had experience in working with a computer (PC) PDP8, it occurred to him to suggest a
fundamentally different solution instead of the suggested construction. This solution presumed that the
5
function of the integrated circuit is determined by a program stored in it. That meant that configuration
would be simpler, but that it would require far more memory than the project that was proposed by
Japanese engineers would require. After a while, though Japanese engineers tried finding an easier
solution, Marcian's idea won, and the first microprocessor was born. In transforming an idea into a ready
made product, Frederico Faggin was a major help to INTEL. He transferred to INTEL, and in only 9
months had succeeded in making a product from its first conception. INTEL obtained the rights to sell
this integral block in 1971. First, they bought the license from the BUSICOM Company who had no
idea what treasure they had. During that year, there appeared on the market a microprocessor called
4004. That was the first 4-bit microprocessor with the speed of 6 000 operations per second. Not long
after that, American company CTC requested from INTEL and Texas Instruments to make an 8-bit
microprocessor for use in terminals. Even though CTC gave up this idea in the end, Intel and Texas
Instruments kept working on the microprocessor and in April of 1972, first 8-bit microprocessor
appeared on the market under a name 8008. It was able to address 16Kb of memory, and it had 45
instructions and the speed of 300 000 operations per second. That microprocessor was the predecessor of
all today's microprocessors. Intel kept their developments up in April of 1974, and they put on the
market the 8-bit processor under a name 8080 which was able to address 64Kb of memory, and which
had
75
instructions,
and
the
price
began
at
$360.
In another American company Motorola, they realized quickly what was happening, so they put out on
the market an 8-bit microprocessor 6800. Chief constructor was Chuck Peddle, and along with the
processor itself, Motorola was the first company to make other peripherals such as 6820 and 6850. At
that time many companies recognized greater importance of microprocessors and began their own
developments. Chuck Peddle leaved Motorola to join MOS Technology and kept working intensively on
developing
microprocessors.
At the WESCON exhibit in United States in 1975, a critical event took place in the history of
microprocessors. The MOS Technology announced it was marketing microprocessors 6501 and 6502 at
$25 each, which buyers could purchase immediately. This was so sensational that many thought it was
some kind of a scam, considering that competitors were selling 8080 and 6800 at $179 each. As an
answer to its competitor, both Intel and Motorola lowered their prices on the first day of the exhibit
down to $69.95 per microprocessor. Motorola quickly brought suit against MOS Technology and Chuck
Peddle for copying the protected 6800. MOS Technology stopped making 6501, but kept producing
6502. The 6502 was an 8-bit microprocessor with 56 instructions and a capability of directly addressing
6
64Kb of memory. Due to low cost, 6502 becomes very popular, so it was installed into computers such
as: KIM-1, Apple I, Apple II, Atari, Commodore, Acorn, Oric, Galeb, Orao, Ultra, and many others.
Soon appeared several makers of 6502 (Rockwell, Sznertek, GTE, NCR, Ricoh, and Comodore takes
over MOS Technology) which was at the time of its prosperity sold at rate of 15 million processors a
year!
Others were not giving up though. Frederico Faggin leaves Intel, and starts his own Zilog Inc. In 1976
Zilog announced the Z80. During the making of this microprocessor, Faggin made a pivotal decision.
Knowing that a great deal of programs have been already developed for 8080, Faggin realized that many
would stay faithful to that microprocessor because of great expenditure which redoing of all of the
programs would result in. Thus he decided that a new processor had to be compatible with 8080, or that
it had to be capable of performing all of the programs which had already been written for 8080. Beside
these characteristics, many new ones have been added, so that Z80 was a very powerful microprocessor
in its time. It was able to address directly 64 Kb of memory, it had 176 instructions, a large number of
registers, a built in option for refreshing the dynamic RAM memory, single-supply, greater speed of
work etc. Z80 was a great success and everybody converted from 8080 to Z80. It could be said that Z80
was without a doubt commercially most successful 8-bit microprocessor of that time. Besides Zilog,
other new manufacturers like Mostek, NEC, SHARP, and SGS also appeared. Z80 was the heart of
many
computers
like
Spectrum,
Partner,
TRS703,
Z-3.
In 1976, Intel came up with an improved version of 8-bit microprocessor named 8085. However, Z80
was so much better that Intel soon lost the battle. Although a few more processors appeared on the
market (6809, 2650, SC/MP etc.), everything was actually already decided. There weren't any more
great improvements to make manufacturers convert to something new, so 6502 and Z80 along with 6800
remained as main representatives of the 8-bit microprocessors of that time.
functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where
automation is needed.
The key features of microcontrollers include:
Microcontrollers sometimes are called single-chip computers because they have on-chip memory
and I/O circuitry and other circuitries that enable them to function as small standalone computers
without other supporting circuitry.
Microcontrollers often use EEPROM or EPROM as their storage device to allow field
programmability so they are flexible to use. Once the program is tested to be correct then large
quantities of microcontrollers can be programmed to be used in embedded systems.
Easy to Use
Assembly language is often used in microcontrollers and since they usually follow RISC
architecture, the instruction set is small. The development package of microcontrollers often
includes an assembler, a simulator, a programmer to "burn" the chip and a demonstration board.
Some packages include a high level language compiler such as a C compiler and more
sophisticated libraries.
A Timer module to allow the microcontroller to perform tasks for certain time periods.
A serial I/O port to allow data to flow between the microcontroller and other devices such as a
PC or another microcontroller.
An ADC to allow the microcontroller to accept analogue input data for processing.
Figure 2.1: Showing a typical microcontroller device and its different subunits
The heart of the microcontroller is the CPU core. In the past this has traditionally been based on an 8-bit
microprocessor unit.
2.4 Microcontrollers versus Microprocessors
Microcontroller differs from a microprocessor in many ways. First and the most important is its
functionality. In order for a microprocessor to be used, other components such as memory, or
components for receiving and sending data must be added to it. In short that means that microprocessor
is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one.
No other external components are needed for its application because all necessary peripherals are
already built into it. Thus, we save the time and space needed to construct devices.
is
part
of
the
microcontroller
whose
function
is
to
store
data.
The easiest way to explain it is to describe it as one big closet with lots of drawers. If we suppose that
we marked the drawers in such a way that they can not be confused, any of their contents will then be
easily accessible. It is enough to know the designation of the drawer and so its contents will be known to
us for sure.
Memory components are exactly like that. For a certain input we get the contents of a certain addressed
memory location and that's all. Two new concepts are brought to us: addressing and memory location.
Memory consists of all memory locations, and addressing is nothing but selecting one of them. This
means that we need to select the desired memory location on one hand, and on the other hand we need to
wait for the contents of that location. Besides reading from a memory location, memory must also
provide for writing onto it. This is done by supplying an additional line called control line. We will
designate this line as R/W (read/write). Control line is used in the following way: if r/w=1, reading is
10
done, and if opposite is true then writing is done on the memory location. Memory is the first element,
and we need a few operation of our microcontroller.
The amount of memory contained within a microcontroller varies between different microcontrollers.
Some may not even have any integrated memory (e.g. Hitachi 6503, now discontinued). However, most
modern microcontrollers will have integrated memory. The memory will be divided up into ROM and
RAM, with typically more ROM than RAM.
Typically, the amount of ROM type memory will vary between around 512 bytes and 4096 bytes,
although some 16 bit microcontrollers such as the Hitachi H8/3048 can have as much as 128 Kbytes of
ROM type memory.
ROM type memory, as has already been mentioned, is used to store the program code. ROM memory
can be ROM (as in One Time Programmable memory), EPROM, or EEPROM.
The amount of RAM memory is usually somewhat smaller, typically ranging between 25 bytes to 4
Kbytes.
RAM is used for data storage and stack management tasks. It is also used for register stacks (as in the
microchip PIC range of microcontrollers).
11
Registers are therefore memory locations whose role is to help with performing various mathematical
operations or any other operations with data wherever data can be found. Look at the current situation.
We have two independent entities (memory and CPU) which are interconnected, and thus any exchange
of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two
memory locations and return the result again back to memory, we would need a connection between
memory and CPU. Simply stated, we must have some "way" through data goes from one block to
another.
2.7 Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires.
There are two types of buses: address and data bus. The first one consists of as many lines as the amount
of memory we wish to address and the other one is as wide as data, in our case 8 bits or the connection
line. First one serves to transmit address from CPU memory, and the second to connect all blocks inside
the microcontroller.
12
Figure2.4: Showing connection between memory and central unit using buses
As far as functionality, the situation has improved, but a new problem has also appeared: we have a unit
that's capable of working by itself, but which does not have any contact with the outside world, or with
us! In order to remove this deficiency, let's add a block which contains several memory locations whose
one end is connected to the data bus, and the other has connection with the output lines on the
microcontroller which can be seen as pins on the electronic component.
13
When working with it the port acts like a memory location. Something is simply being written into or
read from it, and it could be noticed on the pins of the microcontroller.
zeros and ones onto the transmitter line in the order from a bit of the lowest value to a bit of the highest
value. Let each bit stay on line for a time period which is equal to T, and in the end, or after the 8th bit,
let us bring the logical unit "1" back on the line which will mark the end of the transmission of one
data. The protocol we've just described is called in professional literature NRZ (Non-Return to Zero).
As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at the
same time. So called full-duplex mode block which enables this way of communication is called a serial
communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series of bits
what defines the term serial communication comes from. After the reception of data we need to read it
from the receiving location and store it in memory as opposed to sending where the process is reversed.
Data goes from memory through the bus to the sending location, and then to the receiving unit according
to the protocol.
15
2.11 Watchdog
One more thing is requiring our attention is a flawless functioning of the microcontroller
during its run-time. Suppose that as a result of some interference (which often does occur in industry)
our microcontroller stops executing the program, or worse, it starts working incorrectly.
Figure2.8: Watchdog
16
Of course, when this happens with a computer, we simply reset it and it will keep working. However,
there is no reset button we can push on the microcontroller and thus solve our problem. To overcome
this obstacle, we need to introduce one more block called watchdog. This block is in fact another freerun counter where our program needs to write a zero in every time it executes correctly. In case that
program gets "stuck", zero will not be written in, and counter alone will reset the microcontroller upon
achieving its maximum value. This will result in executing the program again, and correctly this time
around. That is an important element of every program to be reliable without man's supervision.
17
18
19
Pinout Description
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most registers.
In other words, the positive voltage on this pin resets the microcontroller. By applying logic zero to this
pin, the program starts execution from the beginning.
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as general input or output. Besides, all
of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication clock
output.
Pin 12: INT0 Interrupt 0 input.
Pin 13: INT1 Interrupt 1 input.
Pin 14: T0 Counter 0 clock input.
20
21
Pin 32-39: Port 0 Similar to P2, if external memory is not used, these pins can be used as general
inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin is driven high
(1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: VCC +5V power supply.
All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as inputs or
outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to be connected to
peripheral devices are available for use.
Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends on its logic
state. In order to configure a microcontroller pin as an input, it is necessary to apply a logic zero (0) to
appropriate I/O port bit. In this case, voltage level on appropriate pin will be 0.
Similarly, in order to configure a microcontroller pin as an input, it is necessary to apply a logic one (1)
to appropriate port. In this case, voltage level on appropriate pin will be 5V (as is the case with any TTL
input). This may seem confusing but don't loose your patience. It all becomes clear after studying simple
electronic circuits connected to an I/O pin.
Input/Output (I/O) pin
Figure above illustrates a simplified schematic of all circuits within the microcontroler connected to one
of its pins. It refers to all the pins except those of the P0 port which do not have pull-up resistors built-in.
Output pin
A logic zero (0) is applied to a bit of the P register. The output FE transistor is turned on, thus
connecting the appropriate pin to ground.
Input pin
A logic one (1) is applied to a bit of the P register. The output FE transistor is turned off and the
appropriate pin remains connected to the power supply voltage over a pull-up resistor of high resistance.
22
Logic state (voltage) of any pin can be changed or read at any moment. A logic zero (0) and logic one
(1) are not equal. A logic one (0) represents a short circuit to ground. Such a pin acts as an output.
A logic one (1) is loosely connected to the power supply voltage over a resistor of high resistance.
Since this voltage can be easily reduced by an external signal, such a pin acts as an input.
Port 0
The P0 port is characterized by two functions. If external memory is used then the lower address byte
(addresses A0-A7) is applied on it. Otherwise, all bits of this port are configured as inputs/outputs.
The other function is expressed when it is configured as an output. Unlike other ports consisting of pins
with built-in pull-up resistor connected by its end to 5 V power supply, pins of this port have this resistor
left out. This apparently small difference has its consequences:
If any pin of this port is configured as an input then it acts as if it floats. Such an input has unlimited
input resistance and indetermined potential.
Ports
There are 4 8-bit ports: P0, P1, P2 and P3.
PORT P1 (Pins 1 to 8): The port P1 is a general purpose input/output port which can be used for a
variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or additional functions
associated with them based upon the context of their usage.
PORT P3 (Pins 10 to 17): PORT P3 acts as a normal IO port, but Port P3 has additional functions such
as, serial transmit and receive pins, 2 external interrupt pins, 2 external counter inputs, read and write
pins for memory access.
PORT P2 (pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port when no external
memory is present, but if external memory access is required then PORT P2 will act as an address bus in
conjunction with PORT P0 to access external memory. PORT P2 acts as A8-A15, as can be seen from
fig 1.1
23
PORT P0 (pins 32 to 39) PORT P0 can be used as a general purpose 8 bit port when no external
memory is present, but if external memory access is required then PORT P0 acts as a multiplexed
address and data bus that can be used to access external memory in conjunction with PORT P2. P0 acts
as AD0-AD7, as can be seen from fig 1.1
Oscillator Circuits
The 8051 requires the existence of an external oscillator circuit. The oscillator circuit usually runs
around 12MHz, although the 8051 (depending on which specific model) is capable of running at a
maximum of 40MHz. Each machine cycle in the 8051 is 12 clock cycles, giving an effective cycle rate
at 1MHz (for a 12MHz clock) to 3.33MHz (for the maximum 40MHz clock).
Internal Architecture
24
A seven segment display, as its name indicates, is composed of seven elements. Individually on or off,
they can be combined to produce simplified representations of the arabic numerals. Often the seven
segments are arranged in an oblique (slanted) arrangement, which aids readability. In most applications,
the seven segments are of nearly uniform shape and size (usually elongated hexagons, though trapezoids
and rectangles can also be used), though in the case of adding machines, the vertical segments are longer
and more oddly shaped at the ends in an effort to further enhance readability.
Each of the numbers 0, 6, 7 and 9 may be represented by two or more different glyphs on seven-segment
displays.
The seven segments are arranged as a rectangle of two vertical segments on each side with one
horizontal segment on the top, middle, and bottom. Additionally, the seventh segment bisects the
rectangle horizontally. There are also fourteen-segment displays and sixteen-segment displays (for full
alphanumerics); however, these have mostly been replaced by dot-matrix displays.
26
The segments of a 7-segment display are referred to by the letters A to G, as shown to the right, where
the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers.
It can also be used to display the common glyphs of the ten decimal numerals and the six hexadecimal
"letter digits" (AF). It is an image sequence of a "LED" display, which is described technology-wise in
the following section. Notice the variation between uppercase and lowercase letters for AF; this is done
to obtain a unique, unambiguous shape for each letter (otherwise, a capital D would look identical to an
0 (or less likely O) and a capital B would look identical to an 8).
Seven segments are, effectively, the fewest required to represent each of the ten Hindu-Arabic numerals
with a distinct and recognizable glyph. Bloggers have experimented with six-segment and even fivesegment displays with such novel shapes as curves, angular blocks and serifs for segments; however,
these often require complicated and/or non-uniform shapes and sometimes create unrecognizable glyphs.
A seven segment display, as its name indicates, is composed of seven elements. Individually on or off,
they can be combined to produce simplified representations of the arabic numerals. Often the seven
segments are arranged in an oblique (slanted) arrangement, which aids readability. In most applications,
the seven segments are of nearly uniform shape and size (usually elongated hexagons, though trapezoids
and rectangles can also be used), though in the case of adding machines, the vertical segments are longer
and more oddly shaped at the ends in an effort to further enhance readability.
Each of the numbers 0, 6, 7 and 9 may be represented by two or more different glyphs on seven-segment
displays.
The seven segments are arranged as a rectangle of two vertical segments on each side with one
horizontal segment on the top, middle, and bottom. Additionally, the seventh segment bisects the
rectangle horizontally. There are also fourteen-segment displays and sixteen-segment displays (for full
alphanumerics); however, these have mostly been replaced by dot-matrix displays.
The segments of a 7-segment display are referred to by the letters A to G, as shown to the right, where
the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers.
It can also be used to display the common glyphs of the ten decimal numerals and the six hexadecimal
"letter digits" (AF). It is an image sequence of a "LED" display, which is described technology-wise in
the following section. Notice the variation between uppercase and lowercase letters for AF; this is done
27
to obtain a unique, unambiguous shape for each letter (otherwise, a capital D would look identical to an
0 (or less likely O) and a capital B would look identical to an 8).
Seven segments are, effectively, the fewest required to represent each of the ten Hindu-Arabic numerals
with a distinct and recognizable glyph. Bloggers have experimented with six-segment and even fivesegment displays with such novel shapes as curves, angular blocks and serifs for segments; however,
these often require complicated and/or non-uniform shapes and sometimes create unrecognizable glyphs.
Seven-segment displays may use a liquid crystal display (LCD), arrays of light-emitting diodes (LEDs),
or other light-generating or controlling techniques such as cold cathode gas discharge, vacuum
fluorescent, incandescent filaments, and others. For gasoline price totems and other large signs, vane
displays made up of electromagnetically flipped light-reflecting segments (or "vanes") are still
commonly used. An alternative to the 7-segment display in the 1950s through the 1970s was the coldcathode, neon-lamp-like nixie tube. Starting in 1970, RCA sold a display device known as the Numitron
that used incandescent filaments arranged into a seven-segment display.
In a simple LED package, typically all of the cathodes (negative terminals) or all of the anodes (positive
terminals) of the segment LEDs are connected together and brought out to a common pin; this is referred
to as a "common cathode" or "common anode" device. Hence a 7 segment plus decimal point package
will only require nine pins (though commercial products typically contain more pins, and/or spaces
where pins would go, in order to match industry standard pinouts).
Integrated displays also exist, with single or multiple digits. Some of these integrated displays
incorporate their own internal decoder, though most do not each individual LED is brought out to a
connecting pin as described. Multiple-digit LED displays as used in pocket calculators and similar
devices used multiplexed displays to reduce the number of IC pins required to control the display. For
example, all the anodes of the A segments of each digit position would be connected together and to a
driver pin, while the cathodes of all segments for each digit would be connected. To operate any
particular segment of any digit, the controlling integrated circuit would turn on the cathode driver for the
selected digit, and the anode drivers for the desired segments; then after a short blanking interval the
next digit would be selected and new segments lit, in a sequential fashion. In this manner an eight digit
display with seven segments and a decimal point would require only 8 cathode drivers and 8 anode
drivers, instead of sixty-four drivers and IC pins. Often in pocket calculators the digit drive lines would
be used to scan the keyboard as well, providing further savings; however, pressing multiple keys at once
would produce odd results on the multiplexed display.
28
Seven segment displays can be found in patents as early as 1908 (in U.S. Patent 974,943, F W Wood
invented an 8-segment display, which displayed the number 4 using a diagonal bar), but did not achieve
widespread use until the advent of LEDs in the 1970s. They are sometimes even used in unsophisticated
displays like cardboard "For sale" signs, where the user either applies color to pre-printed segments, or
(spray)paints color through a seven-segment digit template, to compose figures such as product prices or
telephone numbers.
For many applications, dot-matrix LCDs have largely superseded LED displays, though even in LCDs
7-segment displays are very common. Unlike LEDs, the shapes of elements in an LCD panel are
arbitrary since they are formed on the display by a kind of printing process. In contrast, the shapes of
LED segments tend to be simple rectangles, reflecting the fact that they have to be physically moulded
to shape, which makes it difficult to form more complex shapes than the segments of 7-segment
displays. However, the high common recognition factor of 7-segment displays, and the comparatively
high visual contrast obtained by such displays relative to dot-matrix digits, makes seven-segment
multiple-digit LCD screens very common on basic calculators.
Numbers to 7-segment-code
A single byte can encode the full state of a 7-segment-display. The most popular bit encodings are
gfedcba and abcdefg - both usually assume 0 is off and 1 is on.
This table gives the hexadecimal encodings for displaying the digits 0 to A:
29
30
PIN DESCRIPTION:
31
PIN DESCRIPTION:
Pin No.
Name Description
Pin no. 1
D7
Pin no. 2
D6
Pin no. 3
D5
Pin no. 4
D4
Pin no. 5
D3
Pin no. 6
D2
Pin no. 7
D1
Pin no. 8
D0
Pin no. 9
EN1
Pin no. 10
R/W
Pin no. 11
RS
32
Pin no. 12
VEE
Contrast adjust
Pin no. 13
VSS
Pin no. 14
VCC
Pin no. 15
EN2
Pin no. 16
NC
Not Connected
EN (ENABLE):
The EN line is called "Enable". This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should first set this line high (1) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely ready, bring
33
EN low (0) again. The 1-0 transition tells the 44780 to take the data currently found on the other control
lines and on the data bus and to treat it as a command.
The 8-bit data pins, D0-D7 are used to send information to the LCD or read the content of
the LCDs internal registers. To display letters and numbers, we send ASCII codes for the letters A-Z, az and numbers 0-9 to these pins while making RS=1. There are also instruction command codes that can
be sent to the LCD to clear the display or force the cursor to the home position or blink the cursor. We
also use RS=0 to check the busy flag bit to see if the LCD is ready to receive the information. The busy
flag is D7 and can be read when R/W = 1 and RS=0, as follows: if R/W = 1, RS = 0. When D7=1 (busy
flag = 1), the LCD is busy taking care of internal operations and will not accept any new information.
When D7 = 0, the LCD is ready to receive new information.
CODE (HEX)
RETURN HOME
DISPLAY OFF,CURSOR ON
34
10
14
18
1C
80
C0
ADVANTAGES:
LCD interfacing with 8051 is a real-world application. In recent years the LCD is finding widespread
use replacing LEDs (seven segment LEDs or other multi segment LEDs).
This is due to following reasons:
The declining prices of LCDs.
The ability to display numbers, characters and graphics. This is in contrast to LEDs, which are
limited to numbers and a few characters. An intelligent LCD displays two lines, 20 characters
per line, which is interfaced to the 8051.
Incorporation of a refreshing controller into the LCD, thereby relieving the CPU to keep
displaying the data.
4. PROJECT DESCRIPTION
4.1 Block Diagram:
35
36
Step 3:A message showing that its player 2s turn is displayed on the LCD
37
Step 4:When player 2 presses the button his score gets freezed and displayed on the LCD.
Step 6:This process continues till either of the player crosses the target score and that player is declared the
winner and message is displayed on the LCD.
CODING
#include<reg51.h>
sfr ldata=0x90;
sbit start=P3^0;
sbit intr=P3^2;
sbit intr1=P3^3;
sbit rs=P0^7;
sbit rw=P0^6;
40
sbit en=P0^5;
void delay(int );
void lcdcmd(char );
void lcddata1(char *);
void lcddata(char);
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
for(j=0;j<100;j++);
}
void main()
{int i=0,j=0,v,l=0,v1,m=1,n=1;
char a[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xf8,0x00,0x10};
//char b[8]={"player1="};
//char c[8]={"player2="};
lcdcmd(0x38);
delay(10);
lcdcmd(0x0e) ;
delay(10);
lcdcmd(0x01);
lcdcmd(0x06) ;
41
delay(20)
42
lcddata(v1);
lcddata(v);
delay(800);
lcdcmd(0x01);
if(j>l)
lcddata1(" Player1 leads");
else
lcddata1(" Player2 leads");
delay(800);
lcdcmd(0x01);
lcddata1(" Player2 choice");}
if(intr1==0&n==1)
{
l=l+i;
delay(10);
n=0;m=1;
while(start==1)
{
P2=a[i];
delay(10);
P2=0xff;
delay(10);
43
}
v1=(l/10)+0x30;
v=(l%10)+0x30;
lcdcmd(0x01);
lcddata1(" player2=");
lcddata(v1);
lcddata(v);
delay(800);
P2=a[i];
lcdcmd(0x01);
if(j>l)
lcddata1(" Player1 leads");
else
lcddata1(" Player2 leads");
delay(800);
lcdcmd(0x01);
lcddata1(" Player1 choice");
}
i++;
if(i==10)
i=0;
if(j>=39){
44
45
int i;
for(i=0;value[i]!='\0';i++)
{
ldata=value[i];
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
}
void lcddata(char value)
{
ldata=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
46
5. PROJECT METHODOLOGY
5.1 Components:
Component Name
Quantity
Microcontroller 8051
Push buttons
5V DC adapter
33pf capacitor
10f capacitor
4.7f capacitor
10K Resistor
1K Resistor
48
Step 1: Block diagram and layout of the proposed system is designed and finalized.
Step 2: All the components and software platform to be used are selected which are also mentioned above.
Step 3: All the hardware components are soldered on their respective general purpose boards with the help of
soldering ion, solder and flux according to the hardware schematic
Step 4: The logic flow of the whole system is decided and accordingly flow-charts are being created
Step 5: According to the flow-charts drawn, code/program of the proposed system is developed using assembly
language with the help of software platform (Keil u vision3).
Step 6: The hex code of the program being created by the software platform is burnt into the flash code memory
of our microcontroller IC.
Step 7: Testing is done at various levels to finalize the appropriate program for the most proper working of the
system
5.5 Using the Digital Dice Game:
Initially a message game start push button appears on the LCD display.
Player 1 has to begin the game by pressing his button.A score appears and it gets recorded and
displayed on the LCD when he/she submits it.It is mandatory to submit the score after every
players turn ,failing which the game doesnot proceed further and the score doesnot get recorded.
Then a message appears on the LCD which says player 2 choice.Player 2 repeats the same
process as player1 .
The status of who leads is displayed on the LCD after every players turn.
Now when player1 plays his next turn his present score gets added to his previous score and total
score is displayed on the LCD.
This process continues till either of the players crosses the preset target score in the
49
7. IMPORTANT FEATURES
Number of players could be increased by making small changes in the programming and incorporating
few additional hardware units
The score of the players can be viewed on the LCD.
The status of the game and the information of which players turn is displayed on the LCD
The maximum score limit can easily be changed by
programming.
8. FUTURE SCOPE
Number of players could be increased by making small changes in the programming and incorporating few
additional hardware units like push buttons.
Certain aspects of the system can be modified as operational experience is gained with it. As the users work
with the system, they develop various new ideas for the development and enhancement of the project and
many interesting games and applications can be developed.
50
WEBSITES VIEWED:
www.engineersgarage.com
www.wikipedia.com
www.8051projects.net
www.electronics-project-design.com
www.electrofriends.com
www.wikibooks.com
www.hobbyprojects.com
www.atmel.com
51