Sie sind auf Seite 1von 21

DIGITAL DICE USING AT89C51

A Report submitt ed to MSRIT Bangalore, For partial requirement of award of degree of


Bachelor of Engineering in Computer Science and Engineering

By

Chaitra Sagar (1MS09CS022), Divya Ravisankar (1MS09CS028), Himica Khurana(1MS09CS036)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING M. S. RAMAIAH INSTITUTE OF TECHNOLOGY (Autonomous Institute, Affiliated to VTU) May 2012

Department of Com puter

Science and Enginee ring,

M. S. Ramaiah Institute of Technolog y Bangalore - 54

CERTIFICATE
This is to certify that the following students, who were working under our guidance, have completed their work as per our satisfaction with the topic DIGITAL DICE using AT89C51. To the best of our und erstanding the work to be submitt ed in this report does not contain any work, which has been previously carried out by others and submitted by the candidates for themselves for the award of any degree anywhere.

CHAITRA SAGAR 09CS022 DIVYA RAVISANKAR 09CS028 HIMICA KHURANA 09CS036

Department of Com puter

Scienc e and Enginee ring, 54

M. S. Ramaiah Institute of Technolog y Bangalore -

DECLARATION

We hereby declare that the entire work embodied in this report has been carried out by us at M S Ramaiah Institute of Technology under the supervision of Mrs. Kavitha Jayaram. degree of this or any other University. This report has not been submitt ed in part or full for the award of any diploma or

CHAITRA SAGAR 09CS022 DIVYA RAVISANKAR 09CS028 HIMICA KHURANA 09CS036

This work is dedicated to Ashton Kutcher. The force behind all our zeal

Acknowledgements

The motivation behind this project has always been Mrs. Kavitha Jayaram for she introduced the wonderful world of Embedded Computing and got us completely engaged with it. Further, Mrs. Sini Anna Alex has been extremely kind and cooperative, thoroughly accommodating and persistent with us. The project wouldnt have been a success without them.

Abstract

Gambling, they say, is the oldest game played. Predicated on chance, gambling employs the services of the humble dice in order to achieve them. Here we are presenting a circuit to make an Electronic Digital Dice with the help of a seven segment display controlled by an AT89C51 microcontroller, the seven segment circuit interfaced with it. The circuit can be divided into two units: the microcontroller unit and the seven segment unit. The microcontroller unit contains a microcontroller circuit and the seven segment unit contains a seven segment circuit which is interfaced to the controller. This circuit displays the numbers from 1 to 6 rapidly and it halts the instant the Player presses the Stop switch, generating a number within the aforementioned boundaries of play. It starts again for the next Player when he presses the Start switch after he has reset the dice by pressing the Reset switch.

Contents
1 Introdu ction 1.1 The Device . . . . . . . . . . . . . . . . . . . . . . 1.1.1 The Components . . . . . . . . . . . . . . . 1.1.2 The Circuit . . . . . . . . . . . . . . . . . . . . 1.1.3 The Code . . . . . . . . . . . . . . . . . . . . 2 Scope for Futur e Wor k 1 . . . . . . . . . . . 2 2 5 7 9

vi

Introdu ction
The Digital Dice had to incorporate the two things essential for its use: the probability of any one the six numbers appearing should be equal and as an extension, there must be no other factors influencing the occurrence of this event. We implemented a code which quickly runs through the random variables set, which in this case is the set of natural numbers from 1 to 6, with a time delay between each lesser than the time for human response to stimuli. This would rule out any calculated move to get a particular number on a turn. To implement this, we used the circuit of seven segment display interfacing. We are used four extra pins of the microcontroller as input pins for stopping a dice at one position (Pause), starting it again from the same position (Start) and starting it from the beginning (Reset) enabling the seven segment displays (Enable). The three pins i.e. P3^3, P1^1 and P3^2 of the microcontrollers are made the input pins and assigned to variable Reset, Start and Pause respectively. The pin P1^0 is made output and assigned to variable Enable. Whenever, there is a high given from the Vcc on the Pause pin, the seven segment display shows a number and keeps showing that number. As soon as you give high on the Reset pin, the seven segment starts displaying the numbers from the beginning i.e. it starts again, displaying numbers from one (1). As soon as you give high on the Start pin, the seven segment display begins displaying the numbers starting from the next number at which it was paused. The seven segment display displays the data assigned to it only and only when there is a high on its (Enable) pin.

1.1

The Device

The detailed description of the device follows: 1. Components : their specifications, their role. 2. Circuit : the rigging 3. Code : the software

1.1.1

Components
The principal components used in the making are: 1. Seven segment display (Common Anode)

A seven segment display is the most basic electronic display device that can display digits from 0-9. They find wide application in devices that display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. 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 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. A seven segment is 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.

2. AT89C51 Microcontroller

In 40 pin AT89C51, there are four ports designated as P1, P2, P3 and P0. All these ports are 8-bit bi-directional ports, i.e., they can be used as both input and output ports. Except P0 which needs external pull-ups, rest of the ports have internal pullups. When 1s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressable and so their bits can also be accessed individually. Port P0 and P2 are also used to provide low byte and high byte addresses, respectively, when connected to an external memory. Port 3 has multiplexed pins for special functions like serial communication, hardware interrupts, timer inputs and read/write operation from external memory. AT89C51 has an inbuilt UART for serial communication. It can be programmed to operate at different baud rates. Including two timers & hardware interrupts, it has a total of six interrupts. Pin diagram:

Pin No Function 1 2 3 4 8 bit input/output port (P1) pins 5 6 7 8 9 Reset pin; Active high 10 Input (receiver) for serial communication RxD Output (transmitter) for serial 11 TxD communication 12 External interrupt 1 Int0 8 bit input/output 13 External interrupt 2 Int1 port (P3) pins 14 Timer1 external input T0 15 Timer2 external input T1 16 Write to external data memory Write 17 Read from external data memory Read 18 Quartz crystal oscillator (up to 24 MHz) 19 20 Ground (0V) 21 22 23 8 bit input/output port (P2) pins 24 / High-order address bits when interfacing with external memory 25 26 27 28 29 Program store enable; Read from external program memory Address Latch Enable 30 Program pulse input during Flash programming External Access Enable; Vcc for internal program executions 31 Programming enable voltage; 12V (during Flash programming) 32 33 34 8 bit input/output port (P0) pins 35 Low-order address bits when interfacing with external memory 36 37 38 39 40 Supply voltage; 5V (up to 6.6V)

Name P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 Reset P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 Crystal 2 Crystal 1 Ground P2.0/ A8 P2.1/ A9 P2.2/ A10 P2.3/ A11 P2.4/ A12 P2.5/ A13 P2.6/ A14 P2.7/ A15 PSEN ALE Prog EA Vpp P0.7/ AD7 P0.6/ AD6 P0.5/ AD5 P0.4/ AD4 P0.3/ AD3 P0.2/ AD2 P0.1/ AD1 P0.0/ AD0 Vcc

1.1.2

Circuit Diagram

We start with choosing a port for the output to the 7 segment display and fixing the pins to receive signals for start, stop and reset. The following diagram shows the negative logic used by the 7 segment display and its corresponding hexadecimal value used in our code in order to display Arabic numerals.

The common anode 7 segment display has the pin configuration as shown in the second figure.

The circuit diagram is as shown.

1.1.3

Code
#include <reg51.h> sbit reset=P3^3; sbit start=P1^1; sbit pause=P3^2; sbit enable=P1^0; int current=0; char num[]={0xF9,0X24,0x30,0x19,0x12,0x02}; void delay(int time) { int i, j; for(i=0;i<time;i++) for(j=0;j<1275;j++); } void pausefn() interrupt 0 //pause using ext int 0 { IE=0x84; P2=num[current]; while(1) { if(start == 0) break; if(reset == 0) { enable = 1; current = 0; P2 = num[current]; while(start == 1); return; } enable = 1; delay(25); if(start==0) break; if(reset == 0) { enable = 1; current = 0; P2 = num[current]; while(start == 1); return; } enable = 0; delay(25); } enable=1; } void resetfn() interrupt 2 //reset using timer interrupt 2

{ current = 0; P2 = num[current]; while(start==1); enable = 1; } void main() { enable = 1; while(1) { IE=0x85; if(current > 5) { current = 0; } P2 = num[current]; delay(15); current++; } }

Sco pe for Future Work


The Digital Dice can be incorporated into all board games that involve using a Dice. Further programming can be done on the IC AT89C51 to count the number of steps once player has to advance and light up that path using a set of LEDs, making the board easier to follow and increasing its aesthetic appeal. We see a full blown incorporation of this in Casinos all over as the scope for foul play in such a dice is very little, and additional functionality can be easily added to it to regulate any attempt to tamper with it.