bit rs=P1^0; //1602数据/命令选择引脚
sbit rw=P1^1; //1602读写引脚
sbit e =P1^5; //1602使能引脚
sbit s1=P2^0;//按钮
sbit s2=P2^1;
sbit s3=P2^2;
sbit s4=P2^3;
sbit s5=P2^4;
sbit s6=P2^5;
sbit s7=P2^6;
sbit s8=P2^7;
uchar time=0,start=0;//系统变量
uchar disp[]="T00:00 A:B 00:00";
uchar fen=0,miao=0,sec=0;//计时
uchar fena=0,fenb=0;//分数
uchar num=0;
//延时
void delay_uint(uint i)
{
while(i--);
}
//1602命令函数
void write_com(uchar com)
{
e=0;
rs=0;
rw=0;
P0=com;
delay_uint(20);
e=1;
delay_uint(20);
e=0;
}
//1602写数据函数
void write_data(uchar dat)
{
e=0;
rs=1;
rw=0;
P0=dat;
delay_uint(20);
e=1;
delay_uint(20);
e=0;
}
//改变液晶中某位的值
void write_string(uchar hang,uchar add,uchar *p)
{
if(hang==1)
write_com(0x80+add);
else
write_com(0x80+0x40+add);
while(1)
{
if(*p == '�') break;
write_data(*p);
p++;
}
}
//初始化1602液晶
void init_1602()
{
write_com(0x38); //数据总线为8位,显示2行,5x7点阵
write_com(0x0c); //开显示,有光标,光标闪烁
write_com(0x06); //光标自动右移
delay_uint(1000); //等待设置完成
}
//主函数
void main()
{
init_1602();
TMOD|=0X01;
TH0=0X3C;
TL0=0XB0;
ET0=1;//打开定时器0中断允许
EA=1;//打开总中断
TR0=1;//打开定时器
while(1)
{
if(start==1)//计分
{
if(!s1) //A队加分
{
if(fena<99)
fena++;
if(fena==11)
{
num++;start=2;
fena=0;fenb=0;
switch(num)
{
case 1:write_string(1,0,"1Awin");break;
case 2:write_string(1,5,"2Awin");break;
case 3:write_string(1,10,"3Awin");
}
if(num==3)
start=0;
}
while(!s1);
}
if(!s5) //A队减分
{
if(fena>0)
fena--;
write_string(1,0," ");
while(!s5);
}
if(!s2) //B队加分
{
if(fenb<99)
fenb++;
if(fenb==11)
{
num++;start=2;
fenb=0;fena=0;
switch(num)
{
case 1:write_string(1,0,"1Bwin");break;
case 2:write_string(1,5,"2Bwin");break;
case 3:write_string(1,10,"3Bwin");
}
if(num==3)
start=0;
}
while(!s2);
}
if(!s6) //B队减分
{
if(fenb>0)
fenb--;
while(!s6);
}
}
//开始
if(!s3)
{
start=1;
}
//暂停
if(!s4)
{
if(start==1)
{
start=2;
}
else
{
if(start==2)
{
start=1;
}
}
while(!s4);
}
//清零
if(!s7)
{
if(start==0)
{
miao=0;
fen=0;
fena=0;
fenb=0;
write_string(1,0,"
资料借鉴于此纷传
阅读全文