📄 test03.c
字号:
#include<reg52.h>
#define uchar unsigned char
#define ul unsigned long
sbit dula=P2^6;
sbit wela=P2^7;
uchar code tabledu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code tablewe[]={
0x01,0x02,0x04,0x08,
0x10,0x20
};
uchar temp;
ul n;
void delay(uchar);
void display(uchar,uchar,uchar);
void main()
{
while(1)
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
//-----------------------------;
if(temp!=0xf0)
{delay(20);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:n=1;n*=n;break;
case 0xd0:n=2;n*=n;break;
case 0xb0:n=3;n*=n;break;
case 0x70:n=4;n*=n;break;
}
while(temp!=0xf0)//detect losing hand
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0Xfd;
temp=P3;
temp=temp&0xf0;
//-----------------------------
if(temp!=0xf0)
{delay(20);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:n=5;n*=n;break;
case 0xd0:n=6;n*=n;break;
case 0xb0:n=7;n*=n;break;
case 0x70:n=8;n*=n;break;
}
while(temp!=0xf0)//detect losing hand
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0Xfb;
temp=P3;
temp=temp&0xf0;
//-----------------------------
if(temp!=0xf0)
{delay(20);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:n=9;n*=n;break;
case 0xd0:n=10;n*=n;break;
case 0xb0:n=11;n*=n;break;
case 0x70:n=12;n*=n;break;
}
while(temp!=0xf0)//detect losing hand
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0Xf7;
temp=P3;
temp=temp&0xf0;
//-----------------------------
if(temp!=0xf0)
{delay(20);
if(temp!=0xf0)
switch(temp)
{
case 0xe0:n=13;n*=n;break;
case 0xd0:n=14;n*=n;break;
case 0xb0:n=15;n*=n;break;
case 0x70:n=16;n*=n;break;
}
while(temp!=0xf0)//detect losing hand
{
temp=P3;
temp=temp&0xf0;
}
}
display(n/100,n%100/10,n%10);
}//while(1)
}
void display(uchar b,uchar s,uchar g)
{
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[b];
dula=1;
dula=0;
P0=tablewe[0];
wela=1;
wela=0;
delay(5);
//---------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[s];
dula=1;
dula=0;
P0=tablewe[1];
wela=1;
wela=0;
delay(5);
//--------------
P0=0x00;
wela=1;
wela=0;
P0=~tabledu[g];
dula=1;
dula=0;
P0=tablewe[2];
wela=1;
wela=0;
delay(5);
}
void delay(uchar x)
{uchar a,b;
for(a=x;a>0;a--)
for(b=255;b>0;b--);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -