標(biāo)題: 時(shí)鐘 跑秒 [打印本頁(yè)]

作者: @風(fēng)行者@    時(shí)間: 2015-4-5 16:57
標(biāo)題: 時(shí)鐘 跑秒
#include<reg51.h>
#include<intrins.h>
#define uchar  unsigned  char
#define uint   unsigned  int

uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5c,0x79,0x71};

uint  num,aa,fhz;
uchar  shi,ge,bai,qian,sh,sh0,fen0,fen,sh1,fen1;
void  delayms(int);

void  intin();
void  main()
{  
intin();         
   while(1)
   {
         
         
   }       
}
void  intin()
{
  TMOD=0x01;
  TH0=0x3c;
  TL0=0xb0;
  EA=1;
  ET0=1;
  TR0=1;
  while(1)
   {

        if(aa==2)
        {                 
                aa=0;        
            num++;
            if(num==600)   
                  {
                    num=0;       
                    fen++;
                        if(fen==60)
                        {                          
                          fen=0;                          
                          sh++;                          
                          if(sh==12)
                          {
                            sh=1;
                            
                          }                         
                        }
                  }
        }                
        bai=num/100;   
        shi=num%100/10;
        ge=num%10;
       
        fen1=fen/10;
        fen0=fen%10;

        sh1=sh/100;
        sh0=sh%10;

        P2=0xfb;      
        P0=table[bai];
        delayms(1);

        P2=0xfd;          //打開第二位
        P0=table[shi];         //送十位段數(shù)據(jù)
        delayms(1);
       
        P2=0xfe;        //打開第一位
        P0=table[ge];           //送各位段數(shù)據(jù)
        delayms(1);

        P2=0x7f;
        P0=table[sh1];                //時(shí)
        delayms(1);
        P2=0xbf;
        P0=table[sh0];
        delayms(1);

        P2=0xef;
        P0=table[fen1];          //分
        delayms(1);
        P2=0xf7;
        P0=table[fen0];
        delayms(1);
       
        }
}
void delayms(int xsm)
{
  int i,j;
   for(i=xsm;i>0;i--)
     for(j=110;j>0;j--);
}
void  time0()  interrupt  1
{
          TH0=0x3c;
    TL0=0xb0;
        aa++;
}



作者: admin    時(shí)間: 2015-4-5 16:59
謝謝分享,要是上了個(gè)圖片就更好了
作者: 12377    時(shí)間: 2016-6-2 19:47
謝謝分享
作者: supao    時(shí)間: 2016-6-2 20:16
很好,學(xué)習(xí)一下
作者: houniao    時(shí)間: 2019-7-25 09:37
謝謝分享,要是上了個(gè)圖片就更好




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1