Sign In | Join Free | My brakesband.com
China micro-digital company logo
micro-digital company
ICP Remarked Supplier
Home >

Electronic Dice using 8051

Electronic Dice using 8051

Country/Region china

Company micro-digital company

Categories Plastic Dice Cup

Update 2017-02-14 15:29:06

ICP License Issued by the Chinese Ministry

Contact Now

Electronic Dice using 8051

Description

It’s an Electronic Dice Game using 8051 microcontroller. It is an interesting and basic learning project for student and hobbies. It describes how can we interface 8051 port pins for input and output.

Diagram

Click to Enlarge

Detail

It is a project that builds microcontroller programming interest in new student and hobbies. This project is a very simple one that can easily be built by new students. It uses 7 LEDs, 8051 microcontroller and an optional 5V power supply regulator part. It’s algorithm is also very simple.

1) Initially microcontroller displays 1 on LEDs display just like in real dice.

2) Then in main while loop it waits for switch attached to pin 0 of port 1 to be pressed.

3) Until switch remains pressed it generates random number from 1 to 6 and displays it on LEDs.

4) When button is released it generates and display a new random number on LEDs.

5) It repeats from step 2 to step 5 until power is applied to the system.

For further information of components and basic 8051 microcontroller circuit please visit
8051 Basic LED Flasher.

Code

// Start of code. /////////////////////////////////////////////////////////// // CompanyMicro Digital// // AddressOffice # C7 Raza Plaza// //DAV College Road// //Rawalpindi,// //Pakistan.// // Programmed ByRashid Mehmood// // Project NameElectronic Dice using 8051// // Crystal24.000000 MHz// // MicrocontrollerAT89C2051-C51-C52-C55-S2051-S51-S52 // /////////////////////////////////////////////////////////// // Header file for AT89x051 microcontrollers regiter definitions. #include <AT89x051.h> // Header file for random number generation functions. #include <stdlib.h> sbit Led1 = P1^1; sbit Led2 = P1^2; sbit Led3 = P1^3; sbit Led4 = P1^4; sbit Led5 = P1^5; sbit Led6 = P1^6; sbit Led7 = P1^7; // This function halts execution for // specified milliseconds. void delay_ms(unsigned int del) { unsigned int i,j; for(i = 0; i < del; i ++) for(j = 0; j < 1275; j ++); } // Rename or define P1.0 as Switch. sbit Switch = P1^0; // This function displays an integer value from // 0 to 6 on LEDs. void Display(char Value) { // Switch off all LEDs. Led1 = Led2 = Led3 = Led4 = Led5 = Led6 = Led7 = 1; switch(Value) { case 1Led4 = 0; break; case 2Led1 = Led7 = 0; break; case 3Led1 = Led4 = Led7 = 0; break; case 4Led1 = Led3 = Led5 = Led7 = 0; break; case 5Led1 = Led3 = Led4 = Led5 = Led7 = 0; break; case 6Led1 = Led2 = Led3 = Led5 = Led6 = Led7 = 0; break; } } // Define macro or formulae for random number // generation from 1 to 6. #define GetRandomNumber() ((rand() % 6) + 1) void main() { char RandomNumber; Switch = 1; Display(1); srand(50); while(1) { // Wait until switch is pressed. while(Switch); // Until switch is released. while(!Switch) { // Generate random number. RandomNumber = GetRandomNumber(); // Display this number on LEDs. Display(RandomNumber); // Give some delay. delay_ms(10); } // Generate random number last time. RandomNumber = GetRandomNumber(); // Finally display this number on LEDs. Display(RandomNumber); } } // End of code.

This code can also be executed on AT89C2051 microcontroller a small brother of AT89C51.

Related Projects

8051 Basic LED Flasher

2-Way Traffic Signal Controller

8051 To Seven Segment Display Interfacing

More Projects


Product Tags:

eight sided dice

      

hundred sided dice

      

nine sided dice

      
China Electronic Dice using 8051

Electronic Dice using 8051 Images

Inquiry Cart 0
Send your message to this supplier
 
*From:
*To: micro-digital company
*Subject:
*Message:
Characters Remaining: (0/3000)