Here is the routine for write one line of Intel Hex file (file format for the Intel 8-bit only)
General Intel HEX format (8 bit)
The information of Intel HEX format read here
function writeline(ADDR,RECLEN,RECTYPE:integer;
To test the above routine use this example
General Intel HEX format (8 bit)
The information of Intel HEX format read here
function writeline(ADDR,RECLEN,RECTYPE:integer;
var buf:buffer):string; var i:integer; CHKSUM:byte; begin CHKSUM:=0; result:=':'+inttohex(RECLEN,2)+ inttohex(ADDR,4)+inttohex(RECTYPE,2); CHKSUM:=RECLEN+lo(ADDR)+hi(ADDR); for i:=0 to RECLEN-1 do begin result:=result+inttohex(buf[ADDR+i],2); CHKSUM:=CHKSUM+buf[ADDR+i]; end; result:=result+inttohex(256-CHKSUM,2); end; function write_eof:string; begin result:=':00'+'0000'+'01'+'FF'; // :00000001FF end;
To test the above routine use this example
procedure TForm1.Button2Click(Sender: TObject); var Fname,line:string; Fp : textfile; ErrorCode,StartAddr,ByteCnt:integer; A_Line,EOF_HEX:string; begin StartAddr:=$0000; // start address ByteCnt:=3; // 3 bytes SetLength(HexBufOut,ByteCnt); HexBufOut[0]:=$01; HexBufOut[1]:=$02; HexBufOut[2]:=$03; Fname:='test1.hex'; AssignFile(Fp,Fname); { File selected in dialog } Rewrite(Fp); // write 16 bytes in HexBuf A_Line:=writeline(StartAddr,ByteCnt,$00,HexBufOut); EOF_HEX:=':00'+'0000'+'01'+'FF';// write end of HEX file writeln(Fp,A_Line); writeln(Fp,EOF_HEX); closefile(Fp); end;
No comments:
Post a Comment