- UID
- 195693
- 阅读权限
- 30
- 推广
-
- 幽默
-
- 注册时间
- 2011-5-10
- 最后登录
- 1970-1-1
|
注册家电维修技术论坛,与同行畅聊维修技术,享更多技术论坛功能。
您需要 登录 才可以下载或查看,没有帐号?快速注册
x
简易数字钟
#include <at89x51.h>
#include <DS1302.h>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
unsigned char time[]={0,0,0,0,0,0};//用来储存时间
SYSTEMTIME time1; //在ds1302.h文件中已经定义了一个名字为SYSTEMTIME的结构体,在这里我们定义一个变量名
//为time的SYSTEMTIME结构体
void delay(unsigned char i) //延时子程序
{
unsigned char j;
while((i--)!=0)
{
for(j=123;j>0;j--);
}
}
void display(qian,bai,shi,ge,fen,miao) //显示子程序
unsigned char qian,bai,shi,ge,fen,miao;
{
P2=0xfe;
SBUF=dispcode[qian];
P3_2=1;
delay(3);
P3_2=0;
P2=0xfd;
SBUF=dispcode[bai];
P3_2=1;
delay(3);
P3_2=0;
P2=0xfb;
SBUF=0x40;
P3_2=1;
delay(3);
P3_2=0;
P2=0xf7;
SBUF=dispcode[shi];
P3_2=1;
delay(3);
P3_2=0;
P2=0xef;
SBUF=dispcode[ge];
P3_2=1;
delay(3);
P3_2=0;
P2=0xdf;
SBUF=0x40;
P3_2=1;
delay(3);
P3_2=0;
P2=0xbf;
SBUF=dispcode[fen];
P3_2=1;
delay(3);
P3_2=0;
P2=0x7f;
SBUF=dispcode[miao];
P3_2=1;
delay(3);
P3_2=0;
}
void main()
{
Initial_DS1302(); //初始化DS1302这个时钟芯片,
while(1) //无限地循环
{
DS1302_GetTime(&time1); //读取时间参数
time[5]=(time1.Second)%10; //把秒的个位数据存入time[5]
time[4]=(time1.Second)/10; //把秒的十位数据存入time[4]
time[3]=(time1.Minute)%10; //把分的个位数据存入time[3]
time[2]=(time1.Minute)/10; //把分的十位数据存入time[2]
time[1]=(time1.Hour)%10; //把时的个位数据存入time[1]
time[0]=(time1.Hour)/10; //把时的十位数据存入time[0]
display(time[0],time[1],time[2],time[3],time[4],time[5]); //显示时间
}
}
void uart() interrupt 4
{
TI=0;
} |
-
|