Sie sind auf Seite 1von 51

Mini Project

On

DIGITAL DICE GAME USING 8051


MICROCONTROLLER

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.

2.3 Definition of a Microcontroller


Microcontroller, as the name suggests, are small controllers. They are like single chip computers that are
often embedded into other systems to function as processing/controlling unit. For example, the remote
control you are using probably has microcontrollers inside that do decoding and other controlling

functions. They are also used in automobiles, washing machines, microwave ovens, toys ... etc, where
automation is needed.
The key features of microcontrollers include:

High Integration of Functionality

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.

Field Programmability, Flexibility

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.

Most microcontrollers will also combine other devices such as:

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.

2.5 Memory unit


Memory

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.

Figure2.2: Simplified model of a memory unit

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).

2.6 Central Processing Unit


Let add 3 more memory locations to a specific block that will have a built in capability to multiply,
divide, subtract, and move its contents from one memory location onto another. The part we just added
in is called "central processing unit" (CPU). Its memory locations are called registers.

11

Figure2.3: Simplified central processing unit with three registers

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.

2.8 Input-output unit


Those locations we've just added are called "ports". There are several types of ports: input, output or
bidirectional ports. When working with ports, first of all it is necessary to choose which port we need to
work with, and then to send data to, or take it from the port.

13

Figure2.5: Simplified input-output unit communicating with external world

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.

2.9 Serial communication


Beside stated above we've added to the already existing unit the possibility of communication with an
outside world. However, this way of communicating has its drawbacks. One of the basic drawbacks is
the number of lines which need to be used in order to transfer data. What if it is being transferred to a
distance of several kilometers? The number of lines times number of kilometers doesn't promise the
economy of the project. It leaves us having to reduce the number of lines in such a way that we don't
lessen its functionality. Suppose we are working with three lines only, and that one line is used for
sending data, other for receiving, and the third one is used as a reference line for both the input and the
output side. In order for this to work, we need to set the rules of exchange of data. These rules are called
protocol. Protocol is therefore defined in advance so there wouldn't be any misunderstanding between
the sides that are communicating with each other. For example, if one man is speaking in French, and
the other in English, it is highly unlikely that they will quickly and effectively understand each other.
Let's suppose we have the following protocol. The logical unit "1" is set up on the transmitting line until
transfer begins. Once the transfer starts, we lower the transmission line to logical "0" for a period of time
(which we will designate as T), so the receiving side will know that it is receiving data, and so it will
activate its mechanism for reception. Let's go back now to the transmission side and start putting logic
14

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).

Figure2.6: Serial unit sending data through three lines only

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.10 Timer unit


Since we have the serial communication explained, we can receive, send and process data.

Figure2.7: Timer unit generating signals in regular time intervals


However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer
block which is significant to us because it can give us information about time, duration, protocol etc.
The basic unit of the timer is a free-run counter which is in fact a register whose numeric value
increments by one in even intervals, so that by taking its value during periods T1 and T2 and on the
basis of their difference we can determine how much time has elapsed. This is a very important part of
the microcontroller whose understanding requires most of our time.

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.

2.12 Analog to Digital Converter


As the peripheral signals usually are substantially different from the ones that microcontroller can
understand (zero and one), they have to be converted into a pattern which can be comprehended by a
microcontroller. This task is performed by a block for analog to digital conversion or by an ADC. This
block is responsible for converting an information about some analog value to a binary number and for
follow it through to a CPU block so that CPU block can further process it.

Figure2.9: Block for converting an analog input to digital output


Finally, the microcontroller is now completed, and all we need to do now is to assemble it into an
electronic component where it will access inner blocks through the outside pins. The picture below
shows what a microcontroller looks like inside.

17

Figure2.10: Physical configuration of the interior of a microcontroller


Thin lines which lead from the center towards the sides of the microcontroller represent wires
connecting inner blocks with the pins on the housing of the microcontroller so called bonding lines.
Chart on the following page represents the center section of a microcontroller.

18

Figure2.11: Microcontroller outline with basic elements and internal connections


For a real application, a microcontroller alone is not enough. Beside a microcontroller, we need a
program that would be executed, and a few more elements which make up interface logic towards the
elements of regulation

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

Pin 15: T1 Counter 1 clock input.


Pin 16: WR Write to external (additional) RAM.
Pin 17: RD Read from external RAM.
Pin 18, 19: X2, X1 Internal oscillator input and output. A quartz crystal which specifies operating
frequency is usually connected to these pins. Instead of it, miniature ceramics resonators can also be
used for frequency stability. Later versions of microcontrollers operate at a frequency of 0 Hz up to over
50 Hz.
Pin 20: GND Ground.
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins are configured as
general inputs/outputs. In case external memory is used, the higher address byte, i.e. addresses A8-A15
will appear on this port. Even though memory with capacity of 64Kb is not used, which means that not
all eight port bits are used for its addressing, the rest of them are not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it every
time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address byte
(A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the external
register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and uses it as a
memory chip address. Immediately after that, the ALU pin is returned its previous logic state and P0 is
now used as a Data Bus. As seen, port data multiplexing is performed by means of only one additional
(and cheap) integrated circuit. In other words, this port is used for both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address transmission
with no regard to whether there is internal memory or not. It means that even there is a program written
to the microcontroller, it will not be executed. Instead, the program written to external ROM will be
executed. By applying logic one to the EA pin, the microcontroller will use both memories, first internal
then external (if exists).

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.

Input/Output Ports (I/O Ports)

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

Internal schematics of the 8051.


25

SEVEN SEGMENT DISPLAY


A seven-segment display, or seven-segment indicator, is a form of electronic display device for
displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Sevensegment displays are widely used in digital clocks, electronic meters, and other electronic devices for
displaying numerical information.

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

16X2 LIQUID CRYSTAL DISPLAY (LCD):


A liquid crystal display (LCD) is a thin, flat panel used for electronically displaying information
such as text, images, and moving pictures. Its uses include monitors for computers, televisions, instrument panels,
and other devices ranging from aircraft cockpit displays, to every-day consumer devices such as video players,
gaming devices, clocks, watches, calculators, and telephones. The most commonly used LCDs found in the
market today are 1 Line, 2 Line or 4 Line LCDs which have only 1 controller and support at most of 80
characters. Among its major features are its lightweight construction, its portability, and its ability to be produced
in much larger screen sizes than are practical for the construction of cathode ray tube (CRT) display technology.
Its low electrical power consumption enables it to be used in battery-powered electronic equipment. It is an
electronically-modulated optical device made up of any number of pixels filled with liquid crystals and arrayed in
front of a light source (backlight) or reflector to produce images in color or monochrome. The earliest discovery
leading to the development of LCD technology, the discovery of liquid crystals, dates from 1888. By 2008,
worldwide sales of televisions with LCD screens had surpassed the sale of CRT units.

PIN DESCRIPTION:

31

PIN DESCRIPTION:
Pin No.

Name Description

Pin no. 1

D7

Data bus line 7 (MSB)

Pin no. 2

D6

Data bus line 6

Pin no. 3

D5

Data bus line 5

Pin no. 4

D4

Data bus line 4

Pin no. 5

D3

Data bus line 3

Pin no. 6

D2

Data bus line 2

Pin no. 7

D1

Data bus line 1

Pin no. 8

D0

Data bus line 0 (LSB)

Pin no. 9

EN1

Enable signal for row 0 and 1 (1stcontroller)

Pin no. 10

R/W

Pin no. 11

RS

0 = Write to LCD module


1 = Read from LCD module
0 = Instruction input
1 = Data input

32

Pin no. 12

VEE

Contrast adjust

Pin no. 13

VSS

Power supply (GND)

Pin no. 14

VCC

Power supply (+5V)

Pin no. 15

EN2

Enable signal for row 2 and 3 (2ndcontroller)

Pin no. 16

NC

Not Connected

VCC, VSS and VEE:


While VCC and VSS provide +5V and ground respectively, VEE is used for controlling LCD
contrast.
RS (REGISTER SELECT):
There are two important registers inside the LCD. When RS is low (0), the data is to be
treated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high
(1), the data that is sent is a text data which should be displayed on the screen. For example, to display
the letter "T" on the screen you would set RS high.
RW (READ/WRITE):
The RW line is the "Read/Write" control line. When RW is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are write
commands, so RW will almost be low.

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.

D0-D7 (DATA LINES):

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.

LCD COMMAND CODES:

CODE (HEX)

COMMAND TO LCD INSTRUCTION REGISTER

CLEAR DISPLAY SCREEN

RETURN HOME

DECREMENT CURSOR(SHIFT CURSOR TO LEFT)

INCREMENT CURSOR(SHIFT CURSOR TO RIGHT)

SHIFT DISPLAY RIGHT

SHIFT DISPLAY LEFT

DISPLAY OFF,CURSOR OFF

DISPLAY OFF,CURSOR ON

DISPLAY ON,CURSOR OFF

34

DISPLAY ON CURSOR BLINKING

DISPLAY ON CURSOR BLINKING

10

SHIFT CURSOR POSITION TO LEFT

14

SHIFT CURSOR POSITION TO RIGHT

18

SHIFT THE ENTIRE DISPLAY TO THE LEFT

1C

SHIFT THE ENTIRE DISPLAY TO THE RIGHT

80

FORCE CURSOR TO BEGINNING OF 1ST LINE

C0

FORCE CURSOR TO BEGINNING OF 2ND LINE

2 LINES AND 5x7 MATRIX

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.

Ease of programming for characters and graphics.

4. PROJECT DESCRIPTION
4.1 Block Diagram:

35

4.2 General Working:


Step 1:Initially a message is shown at the beginning of the game game start push button

36

Step 2:When button is pressed player 1s score is freezed and displayed.

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 5:The status of which player leads is displayed on the LCD.


38

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.

Again a new game can be started afresh


39

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)

lcddata1("game start push button");


while(10)
{
P2=a[i];
if(intr==0&m==1)
{
j=j+i;
m=0;n=1;
delay(10);
while(start==1)
{
P2=a[i];
delay(10);
P2=0xff;
delay(10);
}
v1=(j/10)+0x30;
v=(j%10)+0x30;
//lcddata1("submit score");
lcdcmd(0x01);
lcddata1(" player1=");

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

lcddata1(" Player1 won ");


delay(50);
lcdcmd(0x01); }
if(l>=39)
{
lcddata1(" Player2 won");
delay(50);
lcdcmd(0x01);}
}
}

void lcdcmd(char value)


{
ldata=value;
rs=0;
rw=0;
en=1;
delay(2);
en=0;
}
void lcddata1(char *value)
{

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

Seven segment display(common anode)

LCD display 16x2

Push buttons

40 pin microcontroller base

Crystal (11.0592 M Hz)

5V DC adapter

Pull up resistors (1K)

33pf capacitor

10f capacitor

4.7f capacitor

10K Resistor

1K Resistor

5.2 Softwares used:


Keil uVision3.
PROTEUS.
C Flash.

5.3 Equipments used:


47

1. Soldering iron, solder, flux.


2. Personal computer.
3.

Microcontroller program dumping kit

48

5.4 Procedure of building the Digital Dice Game:

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

programming,(here it is taken to be 39).

49

6. RESULT AND CONCLUSION


The desired digital dice game has been designed and the complete system (including all the hardware components
and software routines) is working as per the initial specifications and requirements of our project. Even certain
aspects of the system can be modified as operational experience is gained with it. As the users play with the
system, they develop various new ideas for the development and enhancement of the project.

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

making very slight modification in the

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

9. REFRENCES AND BIBLIOGRAPHY


TEXT BOOKS REFERRED:
1. The 8051 Microcontroller and Embedded Systems by Muhammad Ali Mazidi and Janice
Gillispie Mazidi, Pearson Education.
2. 8051 Microcontroller Architecture, programming and application by KENNETH J.AYALA

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

Das könnte Ihnen auch gefallen