缘由
#include "REG52.h"
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64,15,56}; //共阴0~F消隐减号
unsigned char Js=0, miao=0;//中断计时 秒 分 时 毫秒
unsigned int shu=0;
//bit Mb=0;//12/24切换 秒表
sbit k0=P1^3;
sbit k1=P1^4;
void smxs(unsigned char mz, unsigned char w)
{unsigned char Xd=0;P2=255;P2=255-smgduan[mz];P0=w;while(++Xd);
}
void ZhongDuanSheZhi()
{TH0+=(65536-9216*5)/256;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/TL0+=(65536-9216*5)%256; TMOD=0X01;//16位定时器/计数器TR0=1; //启动定时器T0。ET0=1; //开启定时器EA=1; //全局中断开关IT0 = 1;//下降沿触发EX0 = 1;//开外部中断
}
void main()
{unsigned char Xd=0,k=1;//消抖ZhongDuanSheZhi();while(1){if(k0==0&&++Xd==0){shu=miao=Js=0;TR0=1;while(k0==0);}if(k1==0&&++Xd==0){if(shu%10==3||shu%10==4)++miao;while(k1==0);}if(TR0==1){smxs(miao/10,1);smxs(miao%10,2);smxs(shu/10,4);smxs(shu%10,8);}else if(miao>10){smxs(12,1);smxs(miao/10,2);smxs(miao%10,4);smxs(18,8);}else{smxs(15,1);smxs(10,2);smxs(19,4);smxs(14,8);}if(Js>=10){Js=0;if(shu<100)++shu;else TR0=0;//&&miao<11}}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=0X4c;TL0+=0X00;
}
void WaiBuZhongDuan0() interrupt 0//外部中断0=0,1=2,引脚P3.2,INT0
{if(shu%10==3||shu%10==4)++miao;
}
#include "REG52.h"
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64,15,56}; //共阴0~F消隐减号
unsigned char Js=0, miao=0;//中断计时 秒 分 时 毫秒
unsigned int shu=0;
sbit k0=P1^3;
sbit k1=P1^4;
void smxs(unsigned char mz, unsigned char w)
{unsigned char Xd=0;P2=255;P2=255-smgduan[mz];P0=w;while(++Xd);
}
void ZhongDuanSheZhi()
{TH0+=(65536-9216*5)/256;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/TL0+=(65536-9216*5)%256; TMOD=0X01;//16位定时器/计数器TR0=1; //启动定时器T0。ET0=1; //开启定时器EA=1; //全局中断开关
}
void main()
{unsigned char Xd=0,k=1;//消抖ZhongDuanSheZhi();while(1){if(k0==0&&++Xd==0){shu=miao=Js=0;TR0=1;while(k0==0);}if(k1==0&&++Xd==0){if(shu%10==3||shu%10==4)++miao;while(k1==0);}if(TR0==1){smxs(miao/10,1);smxs(miao%10,2);smxs(shu/10,4);smxs(shu%10,8);}else if(miao>10){smxs(12,1);smxs(miao/10,2);smxs(miao%10,4);smxs(18,8);}else{smxs(15,1);smxs(10,2);smxs(19,4);smxs(14,8);}if(Js>=10){Js=0;if(shu<100)++shu;else TR0=0;//&&miao<11}}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=0X4c;TL0+=0X00;
}