缘由C51的模拟羽毛球游戏设计求解_嵌入式-CSDN问答
#include "REG52.h"
sbit K2 = P1^6;
sbit K1 = P1^7;
bit k=1;
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,128};//0-9.
unsigned char Js=0,fen=0;//中断计时
unsigned int miao=8,dfj=0,dfy=0;
void smxs(unsigned char mz,unsigned char w,unsigned char d)
{unsigned char Xd=0;P0=255;P0=255-(d==1?SmZiFu[mz]:(SmZiFu[mz]|0x80));//小数点闪烁P2=w;while(++Xd);
}
void JiShi(/*时间计算*/)
{if(Js>=20){Js=0;if(k)miao*=2;else miao/=2;}
}
void ZhongDuanSheZhi()
{TH0+=0X4c;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/TL0+=0X00; TMOD=0X01;TR0=1; ET0=1; //开启定时器EA=1; //全局中断开关
}
void main()
{unsigned char Xd=200;unsigned int wei=0;ZhongDuanSheZhi();while(1){if(K1==0&&++Xd==0){if(miao>=8&&miao<=128)k=1;else {++dfy;miao=2048;k=0;}Xd=200;}//while(K1==0);if(K2==0&&++Xd==0){if(miao<=2048&&miao>=256)k=0;else {++dfj;miao=8;k=1;}Xd=200;}//while(K2==0);if(k&&miao>2048){k=1;++dfj;miao=8;}if(!k&&miao<8){k=0;++dfy;miao=2048;}smxs(dfj/10%10,1,1);smxs(dfj%10,2,0);smxs(dfy/10%10,4,1);smxs(dfy%10,8,1);P3=(miao>=8?miao/8:0);JiShi();//一定要放在最后}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=0X4c;TL0+=0X00;
}