📄 count.c
字号:
#include <hardware.h>
//#include <data_code.h>
unsigned char data num=0;//
unsigned char data turn=1;
extern unsigned char data point;//
extern unsigned char data person;
extern char data keypoint;
unsigned int data pointperson[4];//每个人的分数
extern unsigned char code LED[10];
unsigned char data player=0;
unsigned char check();
void count();
void run4();
void run3();
void run2();
void run1();
//void countmain();
unsigned char win();
extern unsigned char scan_key();
extern unsigned char keyboard();
//extern unsigned int result();
extern void D4_light();
extern void D5_light();
extern void D6_light();
extern void D7_light();
extern void send_data();
extern void menu();
extern void initial89C52();
extern delay20ms();
extern void VOICE500HZ1S();
extern void VOICE500HZ2S();
extern void VOICE250HZ1S();
extern void VOICE250HZ2S();
extern void VOICE50HZ2S();
extern void VOICE50HZ4S();
extern void VOICE25HZ2S();
extern void VOICE25HZ4S();
extern unsigned char LED_DISPLAY[5][3];
/***************************************************************************************************************/
void count()
{
unsigned char i;
unsigned char t;
unsigned int numpoint=0;
for(t=0;t<3;t++)//每人三镖
{
switch(check())
{
case 0:
while(keyboard()==100)
{;}
num++;
num=num%4;//每轮镖数为4
if(num==0) num++;
if(num==1){LED1=1;LED2=0;LED3=0;}
if(num==2) {LED1=1;LED2=1;LED3=0;}
if(num==3) {LED1=1;LED2=1;LED3=1;}
if(point-keypoint>=0)//是否爆镖
{
if(keypoint>0x14)//一次打镖分超过20则使用250HZ2S/2次的声音
{
VOICE250HZ1S();
delay20ms();
delay20ms();
VOICE250HZ1S();
}
else VOICE250HZ1S();//否则使用250HZ1S的声音
//numpoint=numpoint+keypoint;//当前镖分
LED_DISPLAY[0][0]=LED[keypoint/100];//取百位数字
LED_DISPLAY[0][1]=LED[(keypoint%100)/10];//取十位数字
LED_DISPLAY[0][2]=LED[(keypoint%100)%10];//取个位数字
if(player==4)
{
pointperson[3]=pointperson[3]-keypoint;
LED_DISPLAY[4][0]=LED[pointperson[3]/100];
LED_DISPLAY[4][1]=LED[(pointperson[3]%100)/10];
LED_DISPLAY[4][2]=LED[(pointperson[3]%100)%10];
}
if(player==3)
{
pointperson[2]=pointperson[2]-keypoint;
LED_DISPLAY[3][0]=LED[pointperson[2]/100];
LED_DISPLAY[3][1]=LED[(pointperson[2]%100)/10];
LED_DISPLAY[3][2]=LED[(pointperson[2]%100)%10];
}
if(player==2)
{
pointperson[1]=pointperson[1]-keypoint;
LED_DISPLAY[2][0]=LED[pointperson[1]/100];
LED_DISPLAY[2][1]=LED[(pointperson[1]%100)/10];
LED_DISPLAY[2][2]=LED[(pointperson[1]%100)%10];
}
if(player==1)
{
pointperson[0]=pointperson[0]-keypoint;
LED_DISPLAY[1][0]=LED[pointperson[0]/100];
LED_DISPLAY[1][1]=LED[(pointperson[0]%100)/10];
LED_DISPLAY[1][2]=LED[(pointperson[0]%100)%10];
}
send_data();
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
}
else //爆镖
{
VOICE25HZ4S();//
for(i=0;i<5;i++)
{
LED1=LED2=LED3=0;
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
LED1=LED2=LED3=1;
// delay20ms();
}
// player++;//爆镖,直接换下一游戏者
}
break;
case 1://换人
// player++;//游戏者换人
VOICE25HZ2S();
// count();//从新开始
break;
case 2://满十轮3镖
win();
// break;
case 3://总分是否为零
win();
// break;
// case 4://是否爆镖
// player++;
// count();
}
}
// point=point-numpoint;
// point=numpoint;
}
/**************************************************************************************/
void run4()//四人十轮
{
unsigned char i,j;
unsigned char t;
// unsigned int testpoint=0x12d;
// point=0x12d;
pointperson[0]=pointperson[1]=pointperson[2]=pointperson[3]=0x12d;;
for(i=1;i<11;i++)//十轮
{
for(j=1;j<5;j++)//四人
{
player++;
player=player%5;//??????????????????????????????
if(player==0) player++;
if(player==1) D4_light();
if(player==2) D5_light();
if(player==3) D6_light();
if(player==4) D7_light();
// pointperson[j]=point;//????????????????????????????????
LED_DISPLAY[0][0]=0x8c;//display"P"
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[player];//DISP下一游戏者序号
send_data();
for(t=0;t<50;t++)//显示1秒
{
delay20ms();
}
LED_DISPLAY[0][0]=0x88;//display"R"
if(turn<10)
{
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[turn];//display"turn"
}
else
{
LED_DISPLAY[0][1]=0xF9;//display"1"
LED_DISPLAY[0][1]=0xC0;//display"0"
}
for(t=1;t<5;t++)
{
/* LED_DISPLAY[i][0]=LED[testpoint/100];
LED_DISPLAY[i][1]=LED[(testpoint%100)/10];
LED_DISPLAY[i][2]=LED[(testpoint%100)%10];*/
LED_DISPLAY[t][0]=LED[pointperson[t-1]/100];
LED_DISPLAY[t][1]=LED[(pointperson[t-1]%100)/10];
LED_DISPLAY[t][2]=LED[(pointperson[t-1]%100)%10];
}
send_data();
for(t=0;t<50;t++)
{
delay20ms();
}
LED1=LED2=LED3=0;
count();
}
turn++;
turn=turn%11;
if(turn==0)
turn++;
}
}
void run3()
{
unsigned char i,j;
pointperson[0]=pointperson[1]=pointperson[2]=pointperson[3]=point;
for(i=1;i<11;i++)//十轮
{
for(j=1;j<4;j++)//四人
{
player++;
player=player%4;//??????????????????????????????
if(player==0) player++;
if(player==1) D4_light();
if(player==2) D5_light();
if(player==3) D6_light();
// if(player==4) D7_light();
// pointperson[j]=point;//????????????????????????????????
LED_DISPLAY[0][0]=0x8c;//display"P"
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[player];//DISP下一游戏者序号
send_data();
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
LED_DISPLAY[0][0]=0x88;//display"R"
if(turn<10)
{
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[turn];//display"turn"
}
else
{
LED_DISPLAY[0][1]=0xF9;//display"1"
LED_DISPLAY[0][1]=0xC0;//display"0"
}
for(i=1;i<4;i++)
{
LED_DISPLAY[i][0]=LED[pointperson[i-1]/100];
LED_DISPLAY[i][1]=LED[(pointperson[i-1]%100)/10];
LED_DISPLAY[i][2]=LED[(pointperson[i-1]%100)%10];
}
LED_DISPLAY[4][0]=LED_DISPLAY[4][1]=LED_DISPLAY[4][2]=0xff;
send_data();
for(i=0;i<50;i++)
{
delay20ms();
}
LED1=LED2=LED3=0;
count();
}
turn++;
turn=turn%11;
if(turn==0)
turn++;
}
}
void run2()
{
unsigned char i,j;
pointperson[0]=pointperson[1]=pointperson[2]=pointperson[3]=point;
for(i=1;i<11;i++)//十轮
{
for(j=1;j<3;j++)//四人
{
player++;
player=player%3;//??????????????????????????????
if(player==0) player++;
if(player==1) D4_light();
if(player==2) D5_light();
// if(player==3) D6_light();
// if(player==4) D7_light();
// pointperson[j]=point;//????????????????????????????????
LED_DISPLAY[0][0]=0x8c;//display"P"
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[player];//DISP下一游戏者序号
send_data();
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
LED_DISPLAY[0][0]=0x88;//display"R"
if(turn<10)
{
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[turn];//display"turn"
}
else
{
LED_DISPLAY[0][1]=0xF9;//display"1"
LED_DISPLAY[0][1]=0xC0;//display"0"
}
for(i=1;i<3;i++)
{
LED_DISPLAY[i][0]=LED[pointperson[i-1]/100];
LED_DISPLAY[i][1]=LED[(pointperson[i-1]%100)/10];
LED_DISPLAY[i][2]=LED[(pointperson[i-1]%100)%10];
}
LED_DISPLAY[3][0]=LED_DISPLAY[3][1]=LED_DISPLAY[3][2]=0xff;
LED_DISPLAY[4][0]=LED_DISPLAY[4][1]=LED_DISPLAY[4][2]=0xff;
send_data();
for(i=0;i<50;i++)
{
delay20ms();
}
LED1=LED2=LED3=0;
count();
}
turn++;
turn=turn%11;
if(turn==0)
turn++;
}
}
void run1()
{
unsigned char i,j;
pointperson[0]=pointperson[1]=pointperson[2]=pointperson[3]=point;
for(i=1;i<11;i++)//十轮
{
for(j=1;j<2;j++)//四人
{
player++;
player=player%2;//??????????????????????????????
if(player==0) player++;
if(player==1) D4_light();
// if(player==2) D5_light();
// if(player==3) D6_light();
// if(player==4) D7_light();
// pointperson[j]=point;//????????????????????????????????
LED_DISPLAY[0][0]=0x8c;//display"P"
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[player];//DISP下一游戏者序号
send_data();
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
LED_DISPLAY[0][0]=0x88;//display"R"
if(turn<10)
{
LED_DISPLAY[0][1]=0xc0;//display"0"
LED_DISPLAY[0][2]=LED[turn];//display"turn"
}
else
{
LED_DISPLAY[0][1]=0xF9;//display"1"
LED_DISPLAY[0][1]=0xC0;//display"0"
}
LED_DISPLAY[1][0]=LED[pointperson[i-1]%100];
LED_DISPLAY[1][1]=LED[(pointperson[i-1]%100)/10];
LED_DISPLAY[1][2]=LED[(pointperson[i-1]%100)%10];
LED_DISPLAY[2][0]=LED_DISPLAY[2][1]=LED_DISPLAY[2][2]=0xff;
LED_DISPLAY[3][0]=LED_DISPLAY[3][1]=LED_DISPLAY[3][2]=0xff;
LED_DISPLAY[4][0]=LED_DISPLAY[4][1]=LED_DISPLAY[4][2]=0xff;
send_data();
for(i=0;i<50;i++)
{
delay20ms();
}
LED1=LED2=LED3=0;
count();
}
turn++;
turn=turn%11;
if(turn==0)
turn++;
}
}
/*****************************************************************************************************************/
unsigned char check()
{
unsigned char i;
if((scan_key()==1))//是否换人
i=1;
else i=0;
if(turn==10&num==3)//满10轮3镖
i=2;
else i=0;
if(pointperson[1]==0|pointperson[2]==0|pointperson[3]==0|pointperson[4]==0)//总分是否为0
i=3;
else i=0;
// if(point1<0|point2<0|point3<0|point4<0)//是否爆镖
// i=4;
// else i=0;
return i;
}
/**************************************************************************************************/
unsigned char win()//声音响的同时怎么让灯闪????????????????????????????
{
unsigned char temp;
unsigned char winner;
unsigned char i;
if ((pointperson[1])>(pointperson[2]))
{temp=pointperson[1];winner=1;}
else {temp=pointperson[2];winner=2;}//
if(temp>(pointperson[3]))
{
if(temp>pointperson[4])
//return temp;
return winner;
else winner=4;
}
else //
{
temp=pointperson[3];
if(temp>pointperson[4])//
winner=3;
else winner=4;
}
if(winner==1)//第一个人胜
{
D4_light();
LED_DISPLAY[0][0]=LED[pointperson[0]/100];
LED_DISPLAY[0][1]=LED[(pointperson[0]%100)/10];
LED_DISPLAY[0][2]=LED[(pointperson[0]%100)%10];
LED_DISPLAY[1][0]=LED_DISPLAY[0][0];
LED_DISPLAY[1][1]=LED_DISPLAY[0][1];
LED_DISPLAY[1][2]=LED_DISPLAY[0][2];//
LED_DISPLAY[2][0]=LED_DISPLAY[2][1]=LED_DISPLAY[2][2]=0xff;
LED_DISPLAY[3][0]=LED_DISPLAY[3][1]=LED_DISPLAY[3][2]=0xff;
LED_DISPLAY[4][0]=LED_DISPLAY[4][1]=LED_DISPLAY[4][2]=0xff;
/* for(i=0;i<5;i++)
for(j=0;j<3;j++)
{
LED_DISPLAY[i][j]=LED_DISPLAYTEMP1[i][j];
}*/
send_data();
for(i=0;i<50;i++)//显示1秒
{
delay20ms();
}
}
if(winner==2)
{
D5_light();
LED_DISPLAY[0][0]=LED[pointperson[0]/100];
LED_DISPLAY[0][1]=LED[(pointperson[0]%100)/10];
LED_DISPLAY[0][2]=LED[(pointperson[0]%100)%10];
LED_DISPLAY[1][0]=LED_DISPLAY[1][1]=LED_DISPLAY[1][2]=0xff;
LED_DISPLAY[2][0]=LED_DISPLAY[0][0];
LED_DISPLAY[2][1]=LED_DISPLAY[0][1];
LED_DISPLAY[2][2]=LED_DISPLAY[0][2];//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -