|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2011-5-12 09:39:49
|
显示全部楼层
#include<reg52.h>
sbit Wei1 = P1^0;
sbit Wei2 = P3^7;
sbit Wei3 = P3^4;
sbit Wei4 = P3^5;
sbit Ajia = P3^1;
sbit Ajian = P3^0;
sbit Bjia = P3^2;
sbit Bjian = P3^3;
#define Gdisp Wei1 = 1; Wei2 = 1; Wei3 = 1; Wei4 = 1;
/* 数码牌 P0口段选
数码管是用热转印做的,先画好一个,另一个是用的镜像,所以码表不一样
H(高位) L(低位)
a a
--- ---
b| |f f | |b
| g | | g |
--- ---
c| |e e | |c
| | | |
--- ---
d d
/*L管脚映射 7 6 5 4 3 2 1
D E C G B F A */
/*H管脚映射 7 6 5 4 3 2 1
D C E G F B A */
//unsigned char Disp_table[]={0x11,0xd7,0x25,0x45,0xc3,0x49,0x09,0xd5,0x01,0x41}; //共阴极
//unsigned char Disp_tableL[]={0xee,0x28,0xda,0xba,0x3c,0xb6,0xf6,0x2a,0xfe,0xbe}; //共阳极
//unsigned char Disp_tableH[]={0xee,0x44,0xb6,0xd6,0x5c,0xda,0xfa,0x46,0xfe,0xde}; //共阳极
unsigned char Disp_tableL[]={0xef,0x29,0xdb,0xbb,0x3d,0xb7,0xf7,0x2b,0xff,0xbf}; //共阳极
unsigned char Disp_tableH[]={0xef,0x45,0xb7,0xd7,0x5d,0xdb,0xfb,0x47,0xff,0xdf}; //共阳极 因段码表不显示小数点,P1.0为位选,电路使用ULN2003驱动段码,所以码表都要加1,使P1.0输出高
unsigned char Ascore=0,Bscore=0;
//unsigned char Aflag=0 ,Bflag=0;
void Delay(unsigned int count)
{
unsigned int i,iTemp;
for(iTemp=0;iTemp<count;iTemp++)
for(i=0;i<110;i++);
}
void Ascore_Display(unsigned int i)
{
unsigned char ge,shi;
ge = i%10;
shi = i/10;
P1 = Disp_tableH[shi];
Wei3 = 0;
Delay(1);
Gdisp;
P1 = Disp_tableL[ge];
Wei4 = 0;
Delay(1);
Gdisp;
}
void Bscore_Display(unsigned int i)
{
unsigned char ge,shi;
ge = i%10;
shi = i/10;
P1 = Disp_tableH[shi];
Wei1 = 0;
Delay(1);
Gdisp;
P1 = Disp_tableL[ge];
Wei2 = 0;
Delay(1);
Gdisp;
}
void init_tc0()
{
TMOD=0X01;
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
EA=1;
ET0=1;
TR0=1;
}
void tc0_srv() interrupt 1
{
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
Ascore_Display(Ascore);
Bscore_Display(Bscore); // 分值没有变化
}
main()
{
unsigned int Atemp,Count_Temp,Jia_Temp,Jia_Temp1=0;
Jia_Temp = 600;
Ascore = 0;
Bscore = 0;
init_tc0();
while(1)
{
if(Ajia == 0) // Ascore加分
{
Delay(50);
if(Ajia == 0)
{
Ascore++;
if(Ascore == 100) Ascore = 0;
EA = 0; //CLOSE INERRUPT
for(Atemp=0;Atemp<3;Atemp++)
{
for(Count_Temp=0;Count_Temp<20;Count_Temp++)
{
Ascore_Display(Ascore);
Bscore_Display(Bscore);
Delay(8); // A B 都显示
}
for(Count_Temp=0;Count_Temp<20;Count_Temp++)
{
Bscore_Display(Bscore); // 只显示B,实现闪烁A的效果
Delay(8);
}
}
EA = 1;
if(Ajia == 0) //实现连续加功能
{
Delay(10);
while(Ajia == 0)
{
if(Jia_Temp1!=2)
{
Delay(300);
Ascore++;
Jia_Temp1++;
}
if(Jia_Temp1==2)
{
Delay(150);
Ascore++;
}
}
Jia_Temp1 = 0;
}
}
}
if(Ajian == 0) // Ascore减分
{
Delay(50);
if(Ajian == 0)
{
if(Ascore!=0)
{
Ascore--;
while(Ajian==0);
}
}
}
if(Bjia == 0) // Bscore加分
{
Delay(50);
if(Bjia == 0)
{
Bscore++;
if(Bscore == 100) Bscore = 0;
EA = 0; //CLOSE INERRUPT
for(Atemp=0;Atemp<3;Atemp++)
{
for(Count_Temp=0;Count_Temp<20;Count_Temp++)
{
Ascore_Display(Ascore);
Bscore_Display(Bscore);
Delay(8); // A B 都显示
}
for(Count_Temp=0;Count_Temp<20;Count_Temp++)
{
Ascore_Display(Ascore); // 只显示B,实现闪烁A的效果
Delay(8);
}
}
EA = 1;
if(Bjia == 0) //实现连续加功能
{
Delay(10);
while(Bjia == 0)
{
if(Jia_Temp1!=2)
{
Delay(300);
Bscore++;
Jia_Temp1++;
}
if(Jia_Temp1==2)
{
Delay(150);
Bscore++;
}
}
Jia_Temp1 = 0;
}
}
}
if(Bjian == 0) // Bscore减分
{
Delay(50);
if(Bjian == 0)
{
if(Bscore != 0)
{
Bscore--;
while(Bjian==0);
}
}
}
}
} |
|