標題:
籃球記分系統(tǒng),新手
[打印本頁]
作者:
我會一直等你Z
時間:
2017-9-12 00:14
標題:
籃球記分系統(tǒng),新手
籃球記分系統(tǒng)
單片機源程序如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define GPIO_DIG P0
#define GPIO_PLACE P2
#define GPIO_KEY P1
uchar code DIG_PLACE[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code DIG_CODE[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code DIG_CODE_POINT[10] = {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
sbit buzzer= P3^0;
uchar KeyValue;
uchar second1=0,second2=0,minute1=0,minute2=0;
char score1=0,score2=0,score3=0,score4=0;
uint Count=0;
void Time0_Init()
{
TMOD = 0x01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
TR0 = 1;
ET0=1;
PT0=1;
}
void delay_ms(uint del)
{
uint i,j;
for(i=0; i<del; i++)
for(j=0; j<114; j++);
}
void Delay10ms(uint c)
{
uchar a, b;
for (;c>0;c--)
{
for (b=38;b>0;b--)
{
for (a=130;a>0;a--);
}
}
}
void DigDisplay(uchar i,uchar j)
{
GPIO_PLACE = DIG_PLACE[i];
if(i==1|i==5)
{
GPIO_DIG = DIG_CODE_POINT[j];
}
else
{
GPIO_DIG = DIG_CODE[j];
}
delay_ms(1);
GPIO_DIG = 0x00;
}
void KeyDown(void)
{
char a = 0;
GPIO_KEY=0x0f;
if(GPIO_KEY!=0x0f)
{
Delay10ms(1);
if(GPIO_KEY!=0x0f)
{
GPIO_KEY=0X0F;
switch(GPIO_KEY)
{
case(0X07): KeyValue=0;break;
case(0X0b): KeyValue=4;break;
case(0X0d): KeyValue=8;break;
case(0X0e): KeyValue=12;break;
}
GPIO_KEY=0XF0;
switch(GPIO_KEY)
{
case(0X70): KeyValue=KeyValue+3;break;
case(0Xb0): KeyValue=KeyValue+2;break;
case(0Xd0): KeyValue=KeyValue+1;break;
case(0Xe0): KeyValue=KeyValue;break;
}
while((a<50) && (GPIO_KEY!=0xf0))
{
Delay10ms(1);
a++;
}
}
}
}
void Displayall()
{
DigDisplay(7,second1);
delay_ms(1);
DigDisplay(6,second2);
delay_ms(1);
DigDisplay(5,minute1);
delay_ms(1);
DigDisplay(4,minute2);
delay_ms(1);
DigDisplay(3,score1);
delay_ms(1);
DigDisplay(2,score2);
delay_ms(1);
DigDisplay(1,score3);
delay_ms(1);
DigDisplay(0,score4);
delay_ms(1);
}
void main()
{
while(1)
{
KeyDown();
Displayall();
if(KeyValue==3)
{
Time0_Init();
}
if(KeyValue==5)
{
score1++;
Displayall();
if(score1>=10)
{
score1=0;
score2++;
Displayall();
}
}
if(KeyValue==6)
{
Displayall();
score3++;
if(score3>=10)
{
score3=0;
score4++;
Displayall();
}
}
if(KeyValue==1)
{
score1--;
Displayall();
if(score1<0)
{
score1=9;
score2--;
Displayall();
}
}
if(KeyValue==2)
{
score3--;
Displayall();
if(score3<0)
{
score3=9;
score4--;
Displayall();
}
}
Displayall();
KeyValue=0;
}
}
void Time0_Int() interrupt 1
{
TH0 = (65535-500)/256;
TL0 = (65535-500)%256;
Count++;
if(Count==2000)
{
Count=0;
second1++;
if(second1==10)
{
second2++;
second1=0;
}
if(second2==6&&second1==0)
{
minute1++;
second2=0;
}
if(minute1==10)
{
minute2++;
minute1=0;
}
}
if(minute2==2&&minute1==0||minute2==4&&minute1==0)
{
buzzer=~buzzer;
}
}
復制代碼
所有資料51hei提供下載:
Program.rar
(35.7 KB, 下載次數(shù): 10)
2017-9-12 00:13 上傳
點擊文件名下載附件
籃球記分系統(tǒng)
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1