The principle is super simple, Baidu is OK.
Give you a reference program.
I hope it helps you.
Voids 1302 _ limit(void)// initialization
{
ds 1302 _ write enable();
ds 1302 _ OSC enable();
for(ds 1302 _ b = 0; ds 1302 _ b & lt; 7; ds 1302_b++)
ds 1302 _ SendByte(ds _ sec+2 * ds 1302 _ b,d 1302[ds 1302 _ b]); //Assignment initialization
}
Uchar ds 1302 _ read (uchar address)//read clock
{
uchar dat
ds 1302 _ write enable();
Switch (address)
{ case 0:dat = ds 1302 _ receive byte(ds _ sec+ 1);
Break;
case 1:dat = ds 1302 _ receive byte(ds _ min+ 1);
Break;
Case 2: DAT = ds1302 _ receivebyte (ds _ hour+1);
Break;
Case 3: DAT = DS1302 _ RECEIVE Byte (DS _ DAY+1);
Break;
Case 4: DAT = DS1302 _ receivebyte (DS _ week+1);
Break;
Case 5: DAT = DS1302 _ receivebyte (DS _ month+1);
Break;
Case 6: dat = ds1302 _ receivebyte (ds _ year+1);
Break;
}
ds 1302 _ write disable();
return(dat);
}
Voids1302 _ write (uchar address, uchar dat)
{
ds 1302 _ write enable();
Switch (address)
{
Case 0: ds1302 _ send byte (ds _ sec, dat);
Break;
Case1:ds1302 _ sendbyte (ds _ min, dat);
Break;
Case 2: DS 1302_SendByte(ds_hour, dat);
Break;
Case 3: DS 1302_SendByte(ds_day, dat);
Break;
Case 4: DS 1302_SendByte(ds_week, dat);
Break;
Case 5: ds1302 _ send byte (ds _ month, dat);
Break;
Case 6: DS 1302_SendByte(ds_year, dat);
Break;
}
ds 1302 _ write disable();
}
Ds 1302pro() // reading data
{
nian 0 1 = ds 1302 _ receive byte(ds _ year+ 1);
yue 0 1 = ds 1302 _ receive byte(ds _ month+ 1);
ri 0 1 = ds 1302 _ receive byte(ds _ day+ 1);
Xiaoshi 0 1 = ds 1302 _ receive byte(ds _ hour+ 1);
sec 0 1 = ds 1302 _ receive byte(ds _ sec+ 1); //Countdown information
min 0 1 = ds 1302 _ receive byte(ds _ min+ 1); //Read information
Stephen Chow = ds1302 _ receivebyte (ds _ week+1);
d 1302 _ transfer(); //Numerical processing extracts the value to be displayed.
}
Voids 1302 _ send byte (uchar command, uchar xmtdat)// data sending program, which sends 1 byte to the controlled ds1302.
{
Ucal I;
RST = 0;
_ nop _();
SCLK = 0;
_ nop _();
RST = 1;
for(I = 0; I<8; i++)
{
IO_DATA= (bit) (command & amp0x01);
Command = Command & gt& gt 1;
SCLK = 1;
_ nop _();
SCLK = 0;
}
for(I = 0; I<8; i++)
{
IO_DATA= (bit) (xmtdat & amp0x01);
XmtDat = XmtDat & gt& gt 1;
SCLK = 1;
_ nop _();
SCLK = 0;
}
RST = 0;
}
Uchards1302 _ receivebyte (uchar command)//data receiver; Receive 1 byte data from the controlled DS 1302.
{
uchar i,rcv dat = 0;
RST = 0;
_ nop _();
SCLK = 0;
_ nop _();
RST = 1;
for(I = 0; I<8; i++)
{
IO_DATA= (bit) (command & amp0x01);
Command = Command & gt& gt 1;
SCLK = 1;
_ nop _();
SCLK = 0;
}
for(I = 0; I<7; i++)
{
if(IO _ DATA)rcv dat | = 0x 80;
RcvDat = RcvDat & gt& gt 1;
SCLK = 1;
_ nop _();
SCLK = 0;
}
if(IO _ DATA)rcv dat | = 0x 80;
RST = 0;
Return to RcvDat
}
Voids1302 _ write enable (void)//allows data to be written into the register.
{
DS 1302_SendByte(ds_com,00);
}
Voids1302 _ write disable (void)//prohibit data from being written into the register.
{
DS 1302_SendByte(ds_com,0x 80);
}
Voids1302 _ oscenable (void)//Start clock operation.
{
DS 1302_SendByte(ds_sec,0x 00);
}
Voids1302 _ OSC disable (void)//Stop the clock operation.
{
DS 1302_SendByte(ds_sec,0x 80);
}
Void d d1302 _ transfer (void)//data conversion function
{
Year 02 = year 01&; 0x0f
nian 0 1 = nian 0 1 & gt; & gt4;
Yue 02 = Yue 01& 0x0f
yue 0 1 = yue 0 1 & gt; & gt4;
ri02 = ri 0 1 & amp; 0x0f
ri 0 1 = ri 0 1 & gt; & gt4;
Xiaoshi 02 = Xiaoshi 0 1 & amp; 0x0f
Xiaoshi 1 = Xiaoshi 1 & gt; & gt4;
min 02 = min 0 1 & amp; 0x0f
min 0 1 = min 0 1 & gt; & gt4;
sec 02 = sec 0 1 & amp; 0x0f// Take the lower four bits of the Miao language signal.
sec 0 1 = sec 0 1 & gt; & gt4; //Take four high digits.
}
Void delay 1302(int i) // delay function
{
uchar x,j;
for(x = 0; X< me; x++)
{
for(j = 0; j & lt 125; j++){; }
}
}
Speech is recognized as a language art. To make your speech sound impressive and attractive, you must have an excellent beginning. Many celebrities pay attention to the wonderfu