• 大小: 73KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: 其他
  • 标签: c  

资源简介

下来就能直接用!有源程序,电路图以及编译文件!

资源截图

代码片段和文件信息

/**********************************************************************
* 程序名;  时钟实验1
* 功  能: 数码管通过动态扫描显示时间,时间可设定调整时间时时钟不走.
* 编程者: ZPZ
* 编程时间:2009/8/9
**********************************************************************/
#include
#define uint unsigned int 
#define uchar unsigned char
 
sbit  _led=P2^7;
sbit  key1=P2^0;
sbit  key2=P2^1;
sbit  key3=P2^2;
uchar  num=0temp=0count=0;
uchar  aa;
uchar hourminsec;
uchar code table[]={0xc00xf90xa40xb00x990x920x820xf80x800x90};

void  delay(uint z);
void  display(uchar auchar buchar cuchar duchar euchar fuchar aa);
void  read_key();
void  led();
void  time_change();

/****************** 主函数  *******************/
void main()
{
P2=0xff;
hour=12;
min=0;
sec=0;
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
aa=0xff;
    while(1)
    {
time_change();
        display(table[hour/10]table[hour%10]table[min/10]
         table[min%10]table[sec/10]table[sec%10]0xff);      
    }
}

  
/****************** 显示函数  *******************/
void display(uchar auchar buchar cuchar duchar euchar fuchar aa)
{
    if(num==1){P1=0x01&aa;P0=a;delay(2);}else{P1=0x01;P0=a;delay(2);}   //hour
    if(num==1){P1=0x02&aa;P0=b;delay(2);}else{P1=0x02;P0=b;delay(2);}  //hour
    if(num==2){P1=0x04&aa;P0=c;delay(2);}else{P1=0x04;P0=c;delay(2);} //min
    if(num==2){P1=0x08&aa;P0=d;delay(2);}else{P1=0x08;P0=d;delay(2);} //min
    if(num==3){P1=0x10&aa;P0=e;delay(2);}else{P1=0x10;P0=e;delay(2);} //sec
    if(num==3){P1=0x20&aa;P0=f;delay(2);}else{P1=0x20;P0=f;delay(2);} //sec

}

/************** 定时器0中断函数  ***************/
void timer0() interrupt 1 
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
temp++;

}

/************** 定时器1中断函数  ***************/
void timer1() interrupt 3 
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
count++;
if(count>=20)
count=0;

}

/****************** 延时子函数  *******************/
void delay(uint z)
{
   uint jk;
   for(j=z;j>0;j--)
     for(k=120;k>0;k--);
}

/****************** 读按键函数  *******************/
void read_key()
{
  if(key1==0)
  {  
    _led=0;
    delay(100);
    if(key1==0)
    { 
        delay(100);
_led=1;
num++;
    if(num>3){num=0;} 
while(1)
{
   
            

if(key1==0)
    {
    _led=0;
        delay(10);
        if(key1==0)
        {
          num++;
      if(num>3){num=0;break;}  
        }
while(!key1);
delay(10);
while(!key1);
_led=1;

}
    
if(key2==0)
    {
    _led=0;
        delay(80);
        if(key2==0)
        {
            if(num==1){hour++;if(hour==24)hour=0;}
            if(num==2){min++;if(min==60)min=0;}
            if(num==3){sec++;if(sec==60)sec=0;}
        }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     113774  2009-08-10 09:05  Last Loaded shizhong.DBK

     文件     113774  2009-08-10 09:05  shizhong.DSN

     文件        742  2010-04-13 21:04  shizhong.PWI

     文件       9426  2009-08-10 09:34  chengxu\shizhong

     文件       4263  2009-08-10 09:36  chengxu\shizhong.c

     文件       2557  2009-08-10 09:34  chengxu\shizhong.hex

     文件         64  2009-08-10 09:34  chengxu\shizhong.lnp

     文件      10476  2009-08-10 09:34  chengxu\shizhong.LST

     文件      12944  2009-08-10 09:34  chengxu\shizhong.M51

     文件      10459  2009-08-10 09:34  chengxu\shizhong.OBJ

     文件        905  2009-08-10 09:36  chengxu\shizhong.Opt

     文件        370  2009-08-10 09:36  chengxu\shizhong.plg

     文件       2161  2009-08-07 22:59  chengxu\shizhong.Uv2

     文件       8566  2009-08-10 08:55  chengxu\shizhong2

     文件       3568  2009-08-10 09:34  chengxu\shizhong2.c

     文件       2355  2009-08-10 08:55  chengxu\shizhong2.hex

     文件         66  2009-08-10 08:55  chengxu\shizhong2.lnp

     文件       7981  2009-08-10 08:55  chengxu\shizhong2.LST

     文件      11594  2009-08-10 08:55  chengxu\shizhong2.M51

     文件       9401  2009-08-10 08:55  chengxu\shizhong2.OBJ

     文件       1037  2009-08-10 09:34  chengxu\shizhong2.Opt

     文件       3965  2009-08-10 08:55  chengxu\shizhong2.plg

     文件       2160  2009-08-10 09:34  chengxu\shizhong2.Uv2

     文件          0  2009-08-10 08:45  chengxu\shizhong2_Uv2.Bak

     文件        901  2009-08-10 08:45  chengxu\shizhong_Opt.Bak

     文件       2157  2009-08-07 18:37  chengxu\shizhong_Uv2.Bak

     文件       6376  2005-03-22 15:22  chengxu\STARTUP.A51

     文件      14062  2009-08-10 09:34  chengxu\STARTUP.LST

     文件        749  2009-08-10 09:34  chengxu\STARTUP.OBJ

     目录          0  2010-04-13 21:30  chengxu

............此处省略3个文件信息

评论

共有 条评论