走时2.c

 

/*************************************************
pslyjvm工作室
http://hi.youkuaiyun.com/space.html
Copyright 2009 pslyjvm's mcustudio
All rights Reserved
作者:pslyjvm  
走时2.c
钟表走时程序 ,fosc=12MHZ。本程序在“走时.c”的
基础上进行了进一步的优化。计时更加精确。
最后是以10进制向外输出
*************************************************/
#include<reg52.h>
unsigned char code CharTab[]={0xC0,0xF9,0xA4,0xB0,  //字型码
                              0x99,0x92,0x82,0xF8,
                              0x80,0x98,0x88,0x83,
                              0xC6,0xA1,0x86,0x8E};
unsigned char code LedSel[6]={0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char DispBuf[6];
unsigned char ss,mm,hh;
unsigned char pBuf;
unsigned int COUNT;


void InitTO(void)
{
  TMOD=0x02;
  TH0=0x37;
  TL0=0;
  TR0=1;
  ET0=1;
}

 

void TO_Srv(void) interrupt 1 using 1
{
   COUNT++;
}

 

void main()
{
  char i;
  for(i=0;i<6;i++)  {DispBuf[i]=0;}
  EA=1;
  InitTO();  
  while(1)
  {
  if(COUNT==5000)
 {
   COUNT=0;
   ss++;
   if(ss==60)  {mm++;ss=0;}
   if(mm==60)  {hh++;mm=0;}
   if(hh==24)  hh=0;
   DispBuf[0]=ss%10;
   DispBuf[1]=ss/10;
   DispBuf[2]=mm%10;
   DispBuf[3]=mm/10;
   DispBuf[4]=hh%10;
   DispBuf[5]=hh/10;

  }
     P0=0xff;
     P2=0xff;
     P0=CharTab[DispBuf[pBuf]];
     P2=LedSel[pBuf];
     if(++pBuf==6) pBuf=0;
   }
}

 

 

 

附:原理图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值