<meta name="keywords" content="必胜时时彩开户,keywords" /> 10秒的秒表法式模范,带暂停
(玩电子) 电子手艺学习与研究

10秒的秒表法式模范模范,带暂停

作者:佚名   泉源:本站原创   点击数:x  更新时间:2013年11月03日   【字体:年夜

#include <reg51.h>
unsigned char code seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f} //数码管码表
unsigned char code tab[]={0xfe,0xfd};                                                                     //数码管位选
unsigned char cnt=0;                                                                                               //位选变量
unsigned char deta=0,sec=0;                                                                                  //0.01秒变量,和秒变量
sbit stop=P3^3;                                                                                                        //暂停键
void init()                                                                                                                 //准时初始化
{
TMOD=0x11;
TH1=0xd8;
TL1=0xf0;
TR1=1;
TH0=0xfc;
TL0=0x18;
TR0=1;
ET1=1;
ET0=1;
EA=1;
}
void time10ms()interrupt 3
{
TH1=0xd8;
TL1=0xf0;
deta++;
}

void show()interrupt 1  //扫描显示2位数码管
{
 TH0=0xfc;
 TL0=0x18;
 ++cnt;
 if(cnt>1)cnt=0;
 switch (cnt)
 {
 case 0:  P0=seg7[sec%10];P2=tab[0];break;
 case 1:  P0=seg7[sec/10];P2=tab[1];break;
 default:break;
 }
 }
 void showtime()     //时间显示
 {
  if((deta>10)&&stop){sec++;deta=0;}    //假定P3^3 不按下,则为高电平,不暂停时间。
  if(sec==99)sec=0;
  }
  void main()
  {
  init();
  while(1)
  {
  showtime();
  }
  }

文章议论

相关文章