This is a 2 player game, based on the 8051 AT89S52 microcontroller . This game features two buttons (one for each player) and a set of 8 LEDs for each. It requires high reflexes, as you have to press the button as quickly as you can. Each press would help the successive LED to glow until all 8 LEDs were lit.
The competition is about how fast you can switch (Press and then release) the buttons , the faster the button pressing speed, the higher your chance of winning. As soon as either player reaches the last LED, the other player's button will be disabled, meaning they will not respond to the push. Additionally, the winner's LEDs will begin to alternate. This will ensure accurate results. To restart the game, press the reset button (button connected to pin 9 of the microcontroller).
Fig. 1: Fastest LED game prototype based on 8051 microcontroller
Figure 2: Image showing Fastest LED Game gameplay
The LEDs corresponding to PLAYER 1 are connected to PORT 2, while for PLAYER 2, the LEDs are connected to PORT 3. The buttons are connected to pins P1.1 and P1.2 for PLAYER 1 and PLAYER 2 respectively. I used integer variables “pressed (0) and pressed (1)” (in the coding part) to ensure that the microcontroller counts only those pushes that are made after releasing the button. This will ensure fair play.
I also declared an array arr , which comprises the hexadecimal values for the LEDs to glow successively. I also created a delay function: delay_msec , using TIMERS to provide delay (in milliseconds) whenever needed.
As 8051 cannot multitask, so to judge the 2 players individually, I wrote the code in such a way that it appears to multitask. This was necessary to count each perfect push and therefore result in a fair decision game.
Components and applications
REQUIREMENTS:
- AT89S52 (8051 microcontroller)
- 16 LEDs (8 for each player)
- Two good quality buttons (small)
- 1 Crystal: – 11.0592 MHz
- 7805 voltage regulator
- A 9V DC battery
FORMS:
· This can be used as a platform for two players to make a decision on fares from their contradictory views (it's similar to flipping a coin and making decisions, but with an electronic twist).
· A regular game can also be used for children to have fun and practice their reflexes.
Project source code
###
#includesbit B1=P1^1; sbit B2=P1^2; int arr ={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; void delay_msec(int time) { int i=0; while(i while(TF1==0); TR1=0; TF1=0; i++; } } void main { int i=0,j=0,pressed(2)={0,0}; B1=B2=1; P1=0x00; P2=0x00; P3=0x00; while(1) { if(B1==0 && pressed(0)==1) {delay_msec(20);pressed(0)=0;} if(B2==0 && pressed(1)==1) {delay_msec(20);pressed(1)=0;} if(B1==1 && pressed(0)==0) {delay_msec(20); pressed(0)=1; P2=arr(i);i++; if(i==8) { P2=0x00; while(1) {P2=~P2;delay_msec(150);} } } if(B2==1 && pressed(1)==0) {delay_msec(20); pressed(1)=1; P3=arr(j);j++; if(j==8) { P3=0x00; while(1) {P3=~P3;delay_msec(150);} } } }}
###
Circuit diagrams
Circuit-Diagram-8051-Microcontroller-Based-Fastest-LED-Game | |
Circuit-Diagram-8051-Microcontroller-Based-Fastest-LED-Game_0 |