欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

定時(shí)器定時(shí)模擬數(shù)字鐘顯示

作者:佚名   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年11月04日   【字體:


#include <reg52.h>

#define uchar unsigned char 
sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
 
static unsigned char second,minute,hour;
unsigned int tcount;
unsigned char m;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
                        0xf8,0x80,0x90};
void delay(uchar i)
{
  uchar j,k; 
  for(j=i;j>0;j--)
    for(k=125;k>0;k--);
}
 
void display()
{
  
   P0=table[minute/10];
   P2_0 = 0;
   delay(5);
   P2_0 = 1;
 
   P0=(table[minute%10]& 0x7f);
   P2_1 = 0;
   delay(5);
   P2_1 = 1;
 
   P0=table[second/10];
   P2_2 = 0;
   delay(5);
   P2_2 = 1;
 
    P0=table[second%10];
   P2_3 = 0;
   delay(5);
   P2_3 = 1;
   
}
 
/*演示主程序*/
void main(void)
{
    unsigned int  a;
    TMOD=0x02;
    TH0=0x06;
    TL0=0x06;
    TR0=1;
    ET0=1;
    EA=1;
   
 while(1)
 {
 
   for(a=100;a>0;a--)
   {
     display();
   }
 
 }
}
 
 
/*
********************************************************************************
** 函數(shù)名稱 : t0(void) interrupt 1 using 0
** 函數(shù)功能 : 定時(shí)器中斷
********************************************************************************
*/
 
 void t0(void) interrupt 1 using 0 
  { tcount++;
 
    if(tcount==4000)
      {tcount=0;
        second++;
 
         if(second==60)
          {second=0;
           minute++;
 
            if(minute==60)
             {minute=0;
              hour++;
 
              if(hour==24)
               {hour=0;
          }
        }
          }
      }
    }


 

關(guān)閉窗口

相關(guān)文章