Consider the following code:
Code: Select all
type TTimeDate =
record
Hours, Mins, Secs, WeekDay, Day, Month: byte;
Year: word;
end;
var Str, Str2: string[20];
TimDat: TTimeDate;
...
procedure BcdByteToStr_(Val_: byte; S: ^byte);
begin
S^ := (Val_ shr 4) + Ord('0');
inc(S);
S^ := (Val_ and $0F) + Ord('0');
end;
procedure RTCC_TimeDateStr(var TimeDate: TTimeDate; var Ts: string[8]; var Ds: string[10]);
begin
// ------------ time --------------------
// hours
BcdByteToStr_(TimeDate.Hours, @Ts[0]);
Ts[2] := ':';
// minutes
BcdByteToStr_(TimeDate.Mins, @Ts[3]);
Ts[5] := ':';
// seconds
BcdByteToStr_(TimeDate.Secs, @Ts[6]);
Ts[8] := 0;
// ------------ date --------------------
// day
BcdByteToStr_(TimeDate.Day, @Ds[0]);
Ds[2] := '/';
// month
BcdByteToStr_(TimeDate.Month, @Ds[3]);
Ds[5] := '/';
// year
BcdByteToStr_(hi(TimeDate.Year), @Ds[6]); // <---- here Ds[6] and Ds[7] seem to get a wrong value
BcdByteToStr_(lo(TimeDate.Year), @Ds[8]);
Ds[10] := 0;
end;
procedure RTCC_Fill_TimeDate(var TimeDate: TTimeDate; Hours, Mins, Secs, WeekDay, Day, Month: byte; Year: word);
begin
TimeDate.Hours := Hours;
TimeDate.Mins := Mins;
TimeDate.Secs := Secs;
TimeDate.WeekDay := WeekDay;
TimeDate.Day := Day;
TimeDate.Month := Month;
TimeDate.Year := Year;
end;
....
// call to procedure
RTCC_Fill_TimeDate(TimDat, $18, $30, $15, $4, $25, $11, $2011);
RTCC_TimeDateStr(TimDat, Str, Str2);
The "Str2" however is assumed to hold the string representation of the date (should be "25/11/2011"), but it is wrong: the "20" of the "year" is something else, like '??' (so "25/11/??11"). Always Str2[6] and Str2[7] are wrong, the others are always correct.
The problem goes away if
- SSA is switched off
- I make a procedure which only handles the date, not the time (so the first part of RTCC_TimeDateStr is deleted).
Thanks in advance!
Solved in v5.40