缘由怎么在单片机上实现这个功能呢_有问必答-CSDN问答
#include "REG52.h"
sbit K1 = P1^5;
sbit K2 = P1^6;
sbit K3 = P1^7;
sbit K4 = P1^4;
//sbit LED1=P1^0;
//sbit LED2=P1^1;
//sbit LED3=P1^2;
//sbit LED4=P1^3;
bit k=1;
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,128};//0-9.
unsigned char Js=0,miao=1,fen=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>=10)
{
Js=0;
if(!k)
{
if(++fen>=4){k=1;fen=0;}
}
else
miao*=2;
}
}
void ZhongDuanSheZhi()
{
TH0+=0X4c;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/
TL0+=0X00;
TMOD=0X01;
TR0=1;
ET0=1; //开启定时器
EA=1; //全局中断开关
}
void main()
{
unsigned char Xd=1,ss=0,jx=0;
unsigned int wei=0;
ZhongDuanSheZhi();
while(1)
{
// if(K1==0&&++Xd==0){++miao;while(K1==0);Xd=200;}
// if(K2==0&&++Xd==0){--miao;while(K2==0);Xd=200;}
// if(K3==0&&++Xd==0){TR0=~TR0;while(K3==0);Xd=200;}
// if(K4==0&&++Xd==0){TR0=0;miao=0;while(K4==0);Xd=200;}
// smxs(miao/10%10,4,k?0:1);
// smxs(miao%10,8,k?1:0);
if(k)P3=ss+miao;else P3=(fen%2==0?0:255);
if((!ss&&miao==128)||(miao==jx/2)){ss+=miao;jx=miao;miao=1;}
if(ss>=255&&k){k=0;jx=ss=miao=0;}
JiShi();//一定要放在最后
}
}
void ZhongDuan() interrupt 1
{
++Js;
TH0+=0X4c;
TL0+=0X00;
}