缘由51单片机c语言秒表的仿真ISIS7 professional_嵌入式-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=0;
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,128};//0-9.
unsigned char Js=0,miao=0,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;if(w==1){LED1=1;LED2=0;}else {LED1=0;LED2=1;}while(++Xd);
}
void JiShi(/*时间计算*/)
{if(Js>=20){Js=0;k=~k;if(++miao>=60){miao=0;if(++fen>=60)fen=0;}}
}
void ZhongDuanSheZhi()
{TH0+=0X4c;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/TL0+=0X00; TMOD=0X01;TR0=1; ET0=1; //开启定时器EA=1; //全局中断开关
}
void main()
{unsigned char Xd=200,ss=0;unsigned int wei=0;ZhongDuanSheZhi();LED3=LED4=0;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,1,k?0:1);smxs(miao%10,8,k?1:0);JiShi();//一定要放在最后}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=0X4c;TL0+=0X00;
}