Chinaunix首页 | 论坛 | 博客
  • 博客访问: 417497
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-11 12:17
个人简介

www.vibexie.com vibexie@qq.com

文章分类

全部博文(121)

文章存档

2015年(55)

2014年(66)

我的朋友

分类: C/C++

2014-03-30 10:44:32

可以设置hou_num,min_num,sec_num的值来设置起始时间

点击(此处)折叠或打开

  1. #include<reg52.h>

  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. sbit dula=P2^6;
  5. sbit wela=P2^7;

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

  7. uchar code table_dp[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};

  8. void display(uchar,uchar,uchar,uchar,uchar,uchar);
  9. void delayms(uint);

  10. uchar num1,num2,sec_num,min_num,hou_num,sec_shi,sec_ge,min_shi,min_ge,hou_shi,hou_ge;

  11. int main()
  12. {
  13.     TMOD=0x11;
  14.     TH0=(65535-45872)/256;
  15.     TL0=(65535-45872)%256;
  16.     TH1=(65535-45872)/256;
  17.     TL1=(65535-45872)%256;

  18.     EA=1;
  19.     ET0=1;
  20.     ET1=1;
  21.     TR0=1;
  22.     TR1=1;
  23.     
  24.     P1=0x00;
  25.     while(1)
  26.     {
  27.         display(sec_shi,sec_ge,min_shi,min_ge,hou_shi,hou_ge);
  28.     }

  29.     return 0;
  30. }

  31. void display(uchar sec_shi,uchar sec_ge,uchar min_shi,uchar min_ge,uchar hou_shi,uchar hou_ge)
  32. {
  33.     //second
  34.     dula=1;
  35.     P0=table[sec_shi];
  36.     dula=0;
  37.     P0=0xff;

  38.     wela=1;
  39.     P0=0xef;
  40.     wela=0;
  41.     delayms(1);

  42.     dula=1;
  43.     P0=table[sec_ge];
  44.     dula=0;
  45.     P0=0xff;
  46.     
  47.     wela=1;
  48.     P0=0xdf;
  49.     wela=0;
  50.     delayms(1);

  51.     //minute
  52.     dula=1;
  53.     P0=table[min_shi];
  54.     dula=0;
  55.     P0=0xff;

  56.     wela=1;
  57.     P0=0xfb;
  58.     wela=0;
  59.     delayms(1);

  60.     dula=1;
  61.     P0=table_dp[min_ge];
  62.     dula=0;
  63.     P0=0xff;
  64.     
  65.     wela=1;
  66.     P0=0xf7;
  67.     wela=0;
  68.     delayms(1);

  69.     //hour
  70.     dula=1;
  71.     P0=table[hou_shi];
  72.     dula=0;
  73.     P0=0xff;

  74.     wela=1;
  75.     P0=0xfe;
  76.     wela=0;
  77.     delayms(1);

  78.     dula=1;
  79.     P0=table_dp[hou_ge];
  80.     dula=0;
  81.     P0=0xff;
  82.     
  83.     wela=1;
  84.     P0=0xfd;
  85.     wela=0;
  86.     delayms(1);
  87. }

  88. void delayms(uint xms)
  89. {
  90.     uint i,j;
  91.     for(i=xms;i>0;i--)
  92.         for(j=112;j>0;j--);
  93. }

  94. void T0_time() interrupt 1
  95. {
  96.     TH0=(65535-45872)/256;
  97.     TL0=(65535-45872)%256;
  98.     num1++;
  99.     if(num1>=10)
  100.     {
  101.         num1=0;
  102.         P1=~P1;
  103.     }
  104. }

  105. void T1_time() interrupt 3
  106. {
  107.     TH1=(65535-45872)/256;
  108.     TL1=(65535-45872)%256;
  109.     num2++;
  110.     if(num2>=20)
  111.     {
  112.         num2=0;
  113.         sec_num++;
  114.         if(sec_num==60)
  115.         {
  116.             sec_num=0;
  117.             min_num++;
  118.             if(min_num==60)
  119.             {
  120.                 min_num=0;
  121.                 hou_num++;
  122.                 if(hou_num==24)
  123.                 {
  124.                     hou_num=0;
  125.                 }
  126.             }
  127.         }
  128.         
  129.         sec_shi=sec_num/10;
  130.         sec_ge=sec_num%10;

  131.         min_shi=min_num/10;
  132.         min_ge=min_num%10;

  133.         hou_shi=hou_num/10;
  134.         hou_ge=hou_num%10;
  135.     }
  136. }

阅读(1539) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~