Jogo DIY: acenda todos os LEDs primeiro!

DIY game: light up all the LEDs first!

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

Protótipo do jogo LED mais rápido baseado em microcontrolador 8051

Fig. 1: Fastest LED game prototype based on 8051 microcontroller

Imagem mostrando a jogabilidade do Fastest LED Game

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:

  1. AT89S52 (8051 microcontroller)
  2. 16 LEDs (8 for each player)
  3. Two good quality buttons (small)
  4. 1 Crystal: – 11.0592 MHz
  5. 7805 voltage regulator
  6. 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

###

 #include 
sbit 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

Project video

Conteúdo Relacionado

A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.