Basketball timing and scorer design based on 51 microcontroller

Based on 51 microcontroller basketball timing and scoring device design

(Simulation + Program + Circuit Diagram + Schematic + Design Report)

Function introduction

Specific functions:

1. It can record the game time of the entire schedule, and can modify and pause the game time.

2. The scores of the two teams in the schedule can be refreshed at any time.

3. When exchanging playing venues, the score positions of the two teams can be exchanged.

4. When the game time is over, an alarm command can be issued.

5. There is a 24-second countdown function, which can be reset to 24 seconds at any time by pressing the button. If the 24-second violation is exceeded, the buzzer alarm will be activated and the game time will be suspended. After processing, press the 24-second reset button and the game will continue.

#include<reg51.h>

#define LEDData P0

unsigned char code LEDCode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

int minit,second,count,count1; //minutes, seconds, counter
char min=15,sec=0;

sbit add1=P1^0; //Add points to pair A, 1 point is added for each press /Add time points when the game has not started
sbit dec1=P1^1; //Deduct points for pair A, 1 point is deducted for each press / time points are deducted when the game has not started
sbit exchange=P1^2; //Exchange venue
sbit add2=P1^3; //Add points for pair B, add 1 point for each press /Add time seconds when the game has not started
sbit dec2=P1^4; //Deduct points for pair B, 1 point will be deducted for each press / time seconds will be deducted when the game has not started.
sbit p24_sec=P1^5;
sbit secondpoint=P0^7; //second flash point
//----Light up the bits of the digital tube in sequence------
sbit led1=P2^7;
sbit led2=P2^6;
sbit led3=P2^5;
sbit led4=P2^4;
sbit led5=P2^3;
sbit led6=P2^2;
sbit led7=P2^1;
sbit led8=P2^0;
sbit led9=P3^7;
sbit led10=P3^6;
sbit led11=P3^5;
sbit led12=P3^4;

sbit alam=P1^7; //Alarm

bit playon=0; //The game progress flag, when it is 1, it means the game has started and the timing is on
bit timeover=0; //The end of the game flag, when it is 1, it means that the time has expired
bit AorB=0; //Pair A and B exchange position flags
bit halfsecond=0; //half second flag bit

unsigned int scoreA; //Team A’s score
unsigned int scoreB; //Team B’s score
char sec24=24;

void Delay5ms(void)
{
unsigned int i;
for(i=100;i>0;i--);
}


void display(void)
{
//----------Display time minutes--------------
LEDData=LEDCode[minit/10];
led1=0;
Delay5ms();
led1=1;
LEDData=LEDCode[minit];
led2=0;
Delay5ms();
led2=1;
//-------------Second flashing------------
if(halfsecond==1)
LEDData=0x7f;
else
LEDData=0xff;
led2=0;
Delay5ms();
led2=1;
secondpoint=0;
//----------Display time in seconds------------
LEDData=LEDCode[second/10];
led3=0;
Delay5ms();
led3=1;
LEDData=LEDCode[second];
led4=0;
Delay5ms();
led4=1;
//-----------Display the fractional digits of 1 group-------
if(AorB==0)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led5=0;
Delay5ms();
led5=1;
//---------------Display the tens digit of a group of fractions----------
if(AorB==0)
LEDData=LEDCode[(scoreA 0)/10];
else
LEDData=LEDCode[(scoreB 0)/10];
led6=0;
Delay5ms();
led6=1;

//---------------Display the ones digit of 1 group of fractions----------
if(AorB==0)
LEDData=LEDCode[scoreA];
else
LEDData=LEDCode[scoreB];
led7=0;
Delay5ms();
led7=1;

//-----------Display the hundreds place of 2 groups of fractions-------
if(AorB==1)
LEDData=LEDCode[scoreA/100];
else
LEDData=LEDCode[scoreB/100];
led8=0;
Delay5ms();
led8=1;
//-----------Display the tens digits of 2 groups of fractions----------
if(AorB==1)
LEDData=LEDCode[(scoreA 0)/10];
else
LEDData=LEDCode[(scoreB 0)/10];
led9=0;
Delay5ms();
led9=1;

//-----------Display the units digits of 2 groups of fractions-----------
if(AorB==1)
LEDData=LEDCode[scoreA];
else
LEDData=LEDCode[scoreB];
led10=0;
Delay5ms();
led10=1;

//----------Display time minutes--------------
LEDData=LEDCode[sec24/10];
led11=0;
Delay5ms();
led11=1;
LEDData=LEDCode[sec24];
led12=0;
Delay5ms();
led12=1;
}


//==========================Key detection program==================== ============================
void keyscan(void)
{
if(playon==0)
{
if(add1==0)
{
display();
if(add1==0);
{
if(minit<99)
minit + + ;
else
minit=99;
min=minit;
}
do
display();
while(add1==0);
\t\t\t
}

if(dec1==0)
{
display();
if(dec1==0);
{
if(minit>0)
minit--;
else
minit=0;
min=minit;
}
do
display();
while(dec1==0);
\t\t\t
}

if(add2==0)
{
display();
if(add2==0);
{
if(second<59)
second + + ;
else
second=59;
sec=second;
}
do
display();
while(add2==0);
\t\t\t
}

if(dec2==0)
{
display();
if(dec2==0);
{
if(second>0)
second--;
else
second=0;
sec=second;
}
do
display();
while(dec2==0);
\t\t\t
}

if(exchange==0)
{
display();
if(exchange==0);
{
TR1=0; //Close T1 counter
alam=1; //turn off alarm
   AorB=~AorB; //Enable exchange
minit=min; //And preset the time to 15:00
second=sec;
sec24=24;
}
do
display();
while(exchange==0);
}
}
else
{
if(add1==0)
{
display();
if(add1==0);
{
if(AorB==0)
{
if(scoreA<999)
scoreA + + ;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB + + ;
else
scoreB=999;
}
}
do
display();
while(add1==0);
}

if(dec1==0)
{
display();
if(dec1==0);
{
if(AorB==0)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec1==0);
}

if(add2==0)
{
display();
if(add2==0);
{
if(AorB==1)
{
if(scoreA<999)
scoreA + + ;
else
scoreA=999;
}
else
{
if(scoreB<999)
scoreB + + ;
else
scoreB=999;
}
}
do
display();
while(add2==0);
}

if(dec2==0)
{
display();
if(dec2==0);
{
if(AorB==1)
{
if(scoreA>0)
scoreA--;
else
scoreA=0;
}
else
{
if(scoreB>0)
scoreB--;
else
scoreB=0;
}
}
do
display();
while(dec2==0);
}
if(p24_sec==0)
{
display();
if(p24_sec==0)
{
sec24=24;
TR0=1;
alam=1;
while(p24_sec==0) display();
}
}
}
}

?

Hardware design

Components used:

Microcontroller: STC89C51;

(Note: The microcontroller is universal, whether it is 51 or 52, whether it is stc or at, the pin functions are the same. The program is also the same.)

Universal board 9*15; 40-pin IC holder;

0.36 four-in-one common anode digital tube;

0.36 trinity common positive digital tube*2;

0.36 two-in-one common positive digital tube;

10K resistor (103); 2.2K resistor*13;

10K resistor; 10uF capacitor;

Button*7; 12M crystal oscillator;

30P capacitor *2; 9012 transistor *13;

Buzzer; DC power socket;

Self-locking switch; wires: several;

?

Specific function implementation:

?

Design information

01 Simulation diagram

This design uses two versions of proteus7.8 and proteus8.7, and is backward compatible, no need to worry! Specifically as shown in the picture!

?

02 Schematic Diagram

The schematic diagram of this system is designed using Altium Designer19, as shown in the figure!

03 Program

This design is programmed using two versions of the software keil4 and keil5, so there is no need to worry! Specifically as shown in the picture!

?

04 Design Report

Seven thousand word design report, details are as follows!

05 Design information

All materials include simulation source files, programs (including comments), AD schematics, circuit diagrams, reference papers, etc. The specific content is as follows, the most complete on the entire network! !

The following is the open source 51 microcontroller design information

?Everyone learns and progresses together:

Link: https://pan.baidu.com/s/18j2D5R9OUBLKDF1PrZkypg?pwd=zbbc
Extraction code: zbbc

Like and share to learn and progress together! Grow together.