#include <STC15F2K60S2.H>
#include <ds1302.h>
unsigned char wirter[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c};
unsigned char read[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
//20Äê18ÈÕ ÖÜÁù 23.59.24
unsigned char Timer[7]={0x24,0x59,0x23,0x18,0x04,0x06,0x20};
unsigned char code Duan[22]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e,0xbf,0x7f,0XC1,0X8C,0XC8,0xc3};
void Delaysmg(unsigned int t)
{
while(t--);
}
void Ds1302()
{
char i;
Write_Ds1302_Byte(0x8e,0x00);
for (i=0;i<7;i++)
{
Write_Ds1302_Byte(wirter[i],Timer[i]);
}
Write_Ds1302_Byte(0x8e,0x80);
}
void readds()
{
char i;
for(i=0;i<7;i++)
{
Timer[i]=Read_Ds1302_Byte(read[i]);
}
}
void suocun(unsigned char n)
{
switch(n)
{
case 4:P2=(P2 & 0x1f)|0x80;break;
case 5:P2=(P2 & 0x1f)|0xa0;break;
case 6:P2=(P2 & 0x1f)|0xc0;break;
case 7:P2=(P2 & 0x1f)|0xe0;break;
case 0:P2=(P2 & 0x1f)|0x00;break;
}
}
void smg(unsigned char wei,unsigned char shu)
{
suocun(6);
P0=0x01<<wei;
suocun(7);
P0=Duan[shu];
Delaysmg(500);
P0=0xff;
}
void xianshi()
{
smg(0,Timer[2]/16);
Delaysmg(100);
smg(1,Timer[2]%16);
Delaysmg(100);
smg(3,Timer[1]/16);
Delaysmg(100);
smg(4,Timer[1]%16);
Delaysmg(100);
smg(6,Timer[0]/16);
Delaysmg(100);
smg(7,Timer[0]%16);
Delaysmg(100);
}
void main()
{
Ds1302();
while(1)
{
readds();
xianshi();
}
}
DS1302
最新推荐文章于 2025-03-23 11:00:35 发布