// cocher la librairie Systeme ...Time #include "../common/timelib.h" //avec DS1307 void Read_Date_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *month, char *year) { I2C2_Start(); I2C2_Wr(DS1307); I2C2_Wr(0); I2C2_Repeated_Start(); I2C2_Wr(DS1307+1); // lecture en BCD *sec =I2C2_Rd(1); *min =I2C2_Rd(1); *hr =I2C2_Rd(1); *week_day =I2C2_Rd(1); *day =I2C2_Rd(1); *month=I2C2_Rd(1); *year =I2C2_Rd(0); I2C2_Stop(); } void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *month, char *year) { // (BCD + Masquage ) to Decimal *sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F); *min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F); *hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F); *week_day =(*week_day & 0x07); *day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F); *month = ((*month& 0x10) >> 4)*10 + (*month& 0x0F); *year = ((*year & 0xF0)>>4)*10+(*year & 0x0F); } void Prepare_Display_Time(char sec, char min, char hr, char week_day, char day, char monthn, char year) { // decimal -> Ascii Date[0]=(day / 10) + 48; Date[1]= (day % 10) + 48; Date[2]='/'; Date[3]=(month/ 10) + 48; Date[4]=(month% 10) + 48; Date[5]='/'; Date[6]='2'; Date[7]='0'; Date[8]=(year / 10) + 48; Date[9]=(year % 10) + 48; Date[10]=0; Time[0]=(hr / 10) + 48; Time[1]=(hr % 10) + 48; Time[2]=':'; Time[3]=(min / 10) + 48; Time[4]=(min % 10) + 48; Time[5]=':'; Time[6]=(sec / 10) + 48; Time[7]=(sec % 10) + 48; Time[8]=0; } TimeStruct ts1, ts2 ,ts3; long epoch=0L ; long epoch1=0L ; long epoch2=0L ; long Ecart=0L ; unsigned char NbH=0; unsigned char NbM=0; unsigned char NbS=0; char Val_Ecart[16]; char Val_epoch1[16]; char Val_epoch2[16]; ts1.ss = sec; ts1.mn = min1 ; ts1.hh = hr ; ts1.md = day ; ts1.mo = month ; ts1.yy = 2000+year ; ts2.ss = 00 ; ts2.mn = 00 ; ts2.hh = 00 ; ts2.md = 01 ; ts2.mo = 01 ; ts2.yy = 2020 ; epoch1 = Time_dateToEpoch(&ts1) ; epoch2 = Time_dateToEpoch(&ts2) ; Ecart = Time_dateDiff(&ts1, &ts2) ; UART1_Write_CText(" Date &t1 Now = "); LongWordToStr(epoch1,CRam1); UART1_Write_Text(CRam1); CRLF1() ; UART1_Write_CText(" Date &T2 au 31/12/19 23:59:59 = "); LongToStr(epoch2,CRam1); // entier long signé !! UART1_Write_Text(CRam1); CRLF1() ; UART1_Write_CText(" Difference = "); LongToStr(Ecart, Val_Ecart); Ltrim(Val_Ecart); UART1_Write_Text(Val_Ecart); UART1_Write_CText(" soit => "); k=( Ecart/3600); WordToStr(k,CRam1); UART1_Write_Text(CRam1); UART1_Write_CText(" Heures\r\n");