#include "reg52.h"
#include<intrins.h>
//#include "math.h"
sbit QiTin = P3^0;//启停按键
sbit TiaoJ = P3^1;//调节按键
sbit duan = P2^6;//数码段
sbit wei = P2^7;//数码位
unsigned char code ShuMaGuan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00,0X80};//0~9隐.小数点
unsigned char code WeiXuanBiao[] = { 0x00,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f };
void ShuMaXianShi(unsigned char s,unsigned char w,unsigned char d)
{
unsigned char YanShi=255;
P0=WeiXuanBiao[w];
wei=1;
wei=0;
P0=ShuMaGuan[s]|ShuMaGuan[d];//d显示小数点11,10关闭
duan=1;
while(YanShi--);
ShuMaGuan[10];
duan=0;
}
void ZhengShuXianShi(unsigned char wei,unsigned long i/*整数拆分到数码管显示*/)
{
do
{
ShuMaXianShi(i % 10,wei--,10);
}while(i/=10);
}
unsigned char TiaoJieAnJian(unsigned char JZhi)
{
unsigned char YS=4;
if(!QiTin||!TiaoJ)
{
while(YS--)ZhengShuXianShi(8,JZhi);
if(!QiTin&&JZhi<50)++JZhi;
if(!TiaoJ&&JZhi)--JZhi;
while(!QiTin||!TiaoJ)ZhengShuXianShi(8,JZhi);
}
return JZhi;
}
void main()
{
unsigned char JZhi=0,a=25;
unsigned int YS=54;
while(1)
{
P1=P1<<1;
if(!QiTin||!TiaoJ)a=TiaoJieAnJian(a);
YS=54-a;while(YS--)ZhengShuXianShi(8,a);
if(!P1)P1=255;
}
}