The basketball scoreboard mainly consists of two major parts: one part implements the countdown function, similar to the 60S countdown done in the experimental class. The other part implements the scoring function, which is fundamentally similar to a counter. Additionally, there are two parts for switching display functions.It is important to note that the pins in the program must match the pins in the schematic. When drawing the schematic, attention should also be paid to the reset circuit, crystal oscillator, power supply, and ensuring that the digital tube is connected to the correct pins on the chip. In the reset circuit, the RESET pin is connected to pin 9 of the chip, and in the crystal oscillator circuit, XTAL2 and XTAL1 are connected to pins 18 and 19 respectively, using the clock signal generated by the crystal oscillator as the timing signal. Pin 20 of the chip is connected to GND, while pins 40 and 31 are connected to VCC. The digital tube is a common cathode type.

- #include<reg52.H> //*****Header File*****//
- #define uchar unsigned char //*Define Variable*//
- #define uint unsigned int //*Define uint as unsigned integer variable*//
- unsigned t = 0x3cb0;
- uchar CZ=24; //*Initial value for timing*//
- uchar key=0;
- uchar score;
- uchar mode=1;//*Mode variable*//
- uchar score1=0; //*Team A score variable*//
- uchar score2=0; //*Team B score variable*//
- uchar bittime=0,bitdisplay=0; //*Define variables*//
- uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //*Segment codes for 0,1,2,3,4,5,6,7,8,9*//
- sbit J0=P3^0; //*Independent key*//
- sbit J1=P3^1;
- sbit J2=P3^2;
- sbit J3=P3^3;
- sbit J4=P3^4;
- sbit J5=P3^5;
- sbit J6=P3^6;
- sbit LED1 = P1^0;
- sbit LED2 = P1^1;
- sbit LED3 = P1^2;
- sbit LED4 = P1^3;
- sbit SPK=P1^7;
- /********Delay Function******/
- void delay(uchar z)
- {
- uchar x,y;
- for(x=z;x>0;x–)
- for(y=110;y>0;y–);
- }
- /* Service Program*/
- void timer0 (void) interrupt 1 using 0
- {
- TH0=0x3c; //*50ms*//
- TL0=0xb0;
- bittime++; //Each time an interrupt occurs, increment the interrupt count bittime by 1
- while(bittime==20)
- {
- bittime=0; //Call the display program once every second
- bitdisplay=1;
- if(bitdisplay)
- {
- bitdisplay = 0;
- CZ–;
- if(-1 == CZ) CZ=24;
- }
- }
- }
- /* Team A Score Display Function*/
- void display_1(uint z)
- {
- P2 = 0XFE; /*11111101 Team A unit score display*/
- P0 = tab[z%10];
- delay(10);
- P2 = 0XFD; /*11111110 Team A ten’s score display*/
- P0 = tab[z/10];
- delay(10);
- }
- /* Team B Score Display Function*/
- void display_2(uint z)
- {
- P2 = 0Xfb; /*11110111 Team B unit score display*/
- P0 = tab[z%10];
- delay(10);
- P2 = 0Xf7; /*11111011 Team B ten’s score display*/
- P0 = tab[z/10];
- delay(10);
- }
- /* Team A Score Processing Function*/
- int inc1()
- {
- if(~J3)
- {
- delay(10);
- score1= score1+1;
- }while(~J3);
- if(~J4)
- {
- delay(10);
- score1= score1+2;
- }while(~J4);
- if(~J5)
- {
- delay(10);
- score1= score1+3;
- }while(~J5);
- return score1;
- }
- /* Team B Score Processing Function*/
- int inc2()
- {
- if(~J3)
- {
- delay(10);
- score2= score2+1;
- }while(~J3);
- if(~J4)
- {
- delay(10);
- score2= score2+2;
- }while(~J4);
- if(~J5)
- {
- delay(10);
- score2= score2+3;
- }while(~J5);
- return score1;
- }
- /* Team A and B Score Switching Function*/
- uchar turn()
- {
- if(~J2)
- {
- delay(10);
- if(~J2)
- {
- delay(10);
- LED1 = 1;
- LED2 = 1;
- LED3 = 0;
- LED4 = 1;
- key = 1;
- }while(~J2);
- }
- if(~J6)
- {
- delay(10);
- if(~J6)
- {
- delay(10);
- LED1 = 1;
- LED2 = 1;
- LED3 = 1;
- LED4 = 0;
- key = 2;
- }while(~J6);
- }
- return key;
- }
- /* Score Display Function*/
- void marks()
- {
- turn();
- if(key == 1)
- {
- inc1();
- if(score1<100)
- {
- display_1(score1);
- display_2(score2);
- }
- else score1 =score1-100;
- }
- else if(key == 2)
- {
- inc2();
- if(score2<100)
- {
- display_1(score1);
- display_2(score2);
- }
- else score2 = score2-100;
- }
- }
- /* Mode Selection Function*/
- uchar mode_select()
- {
- if(~J0)
- {
- delay(10);
- if(~J0)
- {
- delay(10);
- mode = 1;
- LED1 = 0;
- LED2 = 1;
- LED3 = 1;
- LED4 = 1;
- } while(~J0);
- }
- if(~J1)
- {
- delay(10);
- if(~J1)
- {
- delay(10);
- mode = 2;
- LED1 = 1;
- LED2 = 0;
- LED3 = 1;
- LED4 = 1;
- } while(~J1);
- }
- return mode;
- }
- /* Countdown Processing*/
- void time_count()
- {
- TR0 = 1;
- P2 = 0XFB; /*11111010 Team A and B ten’s display*/
- P0 = tab[CZ/10];
- delay(10);
- P2 = 0XFD; /*11110101 Team A and B unit display*/
- P0 = tab[CZ%10];
- delay(10);
- }
- /* Main Function*/
- int main()
- {
- TMOD= 0x01;
- TH0=0x3c;
- TL0=0xb0;
- EA = 1; //Enable all interrupts
- ET0 =1;//Enable Timer T0 interrupt
- TR0 = 0;//Turn off Timer T0
- P2 = 0XF0;
- P0 = 0x3f;
- SPK=0;
- while(1)
- {
- mode_select();
- if(1 == mode) //Scoring Function
- {
- TR0 = 0;//Turn off timer
- CZ = 24; //Reset initial value to 24 seconds
- display_1(score1);
- delay(10);
- display_2(score2);
- marks();
- }
- if(2 == mode) //Timing Function
- {
- if(CZ == 0){TR0 = 0,SPK=1;delay(30);SPK = 0;
- foul_sever();
- }
- time_count();}
- }
- return 0;
- }
Source: Internet, copyright belongs to the original author. If there is any infringement, please contact for removal.