//这是我用SPCOMM控件写的时间校正,可以把当前计算机时间传给单片机,不知对你是否有帮助//
var
yearout,monthout,dayout,weekout,hourout,minout,secout,msecout:string;
w:integer;
year,month,day,hour,min,sec,msec:word;
begin
decodedate(now,year,month,day);
if month > 9 then monthout:='$'+inttostr(month);
if month <10 then monthout:='$'+'0'+inttostr(month);
if day > 9 then dayout:='$'+inttostr(day);
if day < 10 then dayout:='$'+'0'+inttostr(day);
if dayofweek(now) < 8 then
begin
w:=dayofweek(now)-1;
if w=0 then w:=8;
end;
weekout:='$'+'0'+inttostr(w);
yearout:='$'+inttostr(year);
decodetime(now,hour,min,sec,msec);
if hour > 9 then hourout:='$'+inttostr(hour);
if hour < 10 then hourout:='$'+'0'+inttostr(hour);
if min > 9 then minout:='$'+inttostr(min);
if min <10 then minout:='$'+'0'+ inttostr(min);
if sec > 9 then secout:='$'+inttostr(sec);
if sec < 10 then secout:='$'+'0'+inttostr(sec);
sbuf[1]:=byte($F0);//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(secout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(minout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(hourout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(dayout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(monthout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(weekout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte(strtoint(yearout));//帧头
senddata;//调用发
sleep(100);
sbuf[1]:=byte($F8);//帧尾
senddata;//调用发