万历表(其中有两个程序,DS1302为测试程序,万历表程序为真正的程序)
单片机源程序如下:
- #include<reg52.h>
- #include"text.h"
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- uchar num[]={0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x6f};
- uchar duanxuan[8];
- void delay(uint t)
- {
- while(--t);
- }
- void zhuanhua()
- {
- read_time();
- duanxuan[1]=num[Time[0]/16];
- duanxuan[0]=num[Time[0]&0x0f];
- duanxuan[2]=0x40;
- duanxuan[4]=num[Time[1]/16];
- duanxuan[3]=num[Time[1]&0x0f];
- duanxuan[5]=0x40;
- duanxuan[7]=num[Time[2]/16];
- duanxuan[6]=num[Time[2]&0x0f];
- }
- void xianshi()
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- switch(i)
- {
- case 0:
- LSC=0,LSB=0,LSA=0;break;
- case 1:
- LSC=0,LSB=0,LSA=1;break;
- case 2:
- LSC=0,LSB=1,LSA=0;break;
- case 3:
- LSC=0,LSB=1,LSA=1;break;
- case 4:
- LSC=1,LSB=0,LSA=0;break;
- case 5:
- LSC=1,LSB=0,LSA=1;break;
- case 6:
- LSC=1,LSB=1,LSA=0;break;
- case 7:
- LSC=1,LSB=1,LSA=1;break;
- }
- P0=duanxuan[i];
- delay(100);
- P0=0x00;
- }
- }
- void main()
- {
- init();
- while(1)
- {
- zhuanhua();
- xianshi();
- }
- }
复制代码
所有资料51hei提供下载:
DS1302.zip
(82.68 KB, 下载次数: 6)
|