{
Unsigned char dat1, dat2;
Dat1=dat/16;
Dat2=16 dat %;
Dat=dat1 * 10 + dat2;
Return dat.
}
Unsigned char Dat_CHG_BCD unsigned char (dat)
{
Unsigned char dat1, dat2;
Dat1=dat/10;
Dat2=dat % 10;
Dat=16 + dat2 dat1 *;
Return dat.
}
Void DS1302_Init (unsigned char * Time)
{
Write_Ds1302 (0 x8e, 0 x00);
Write_Ds1302 (0 x80, Dat_CHG_BCD (Time [0]));
Write_Ds1302 (0 x82, Dat_CHG_BCD (Time [1]));
Write_Ds1302 (0 x84, Dat_CHG_BCD (Time [2]));
Write_Ds1302 (0 x8e, 0 x80);
}
Void Ds1302_Read (unsigned char * Time)
{
Write_Ds1302 (0 x8e, 0 x00);
Time [0]=BCD_CHG_Dat (Read_Ds1302 x81 (0));
Time [1]=BCD_CHG_Dat (Read_Ds1302 (0 x83));
Time [2]=BCD_CHG_Dat (Read_Ds1302 (0 x85));
Write_Ds1302 (0 x8e, 0 x80);
}
CodePudding user response:
This code can't read? Entry-level code ohCodePudding user response:
First two function is used to mutual conversion, BCD and hexadecimal third function is to initialize DS1302 into BCD code, the last function is read DS1302 and will read into BCD converted to hexadecimal,In general is DS1302 to send and receive data encoding format is BCD, but you actually processing data to hexadecimal number, so be transformed to him,