Aqui va el relajo completo:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, CPort, StdCtrls, ComCtrls, Grids, Menus, Mask, Buttons;
type
TBuffer = array[$0000..$FFFF] of Byte;
type
TForm1 = class(TForm)
ComPort: TComPort;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
StringGrid1: TStringGrid;
Button4: TButton;
MainMenu1: TMainMenu;
Archivo1: TMenuItem;
Puerto1: TMenuItem;
StaticText1: TStaticText;
Edit1: TEdit;
GroupBox1: TGroupBox;
ProgressBar1: TProgressBar;
GroupBox2: TGroupBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
Edit2: TEdit;
Edit3: TEdit;
StaticText2: TStaticText;
StaticText3: TStaticText;
Edit4: TEdit;
StaticText4: TStaticText;
DEVICE1: TMenuItem;
AT89S511: TMenuItem;
AT89S521: TMenuItem;
About1: TMenuItem;
Edit5: TEdit;
StaticText5: TStaticText;
procedure FormCreate(Sender: TObject);
procedure ComPortRxChar(Sender: TObject; Count: Integer);
procedure Memo1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Puerto1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure AT89S511Click(Sender: TObject);
procedure AT89S521Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
procedure InicializaGridBuffer;
public
end;
const
BufferSize = 4096;
var
Form1: TForm1;
Cuantos, CuentaB : Integer;
Contador, ByteCnt : Integer;
LineaMemo : String;
Count : Integer;
Buffer: TBuffer;
BuffReceptor: TBuffer;
implementation
{$R *.dfm}
function Insertar(Str: String; var Buffer: TBuffer): String;
var
i,j,k: Integer;
begin
Result:= EmptyStr;
Str:= Trim(Str);
if Copy(Str,1,1) = ':' then
if TryStrToInt('$' + Copy(Str,2,2),i) then
if Length(Str) = ((2*i) + 11) then
if TryStrToInt('$' + Copy(Str,4,4),j) then
if TryStrToInt('$' + Copy(Str,8,2),k) then
if k = 0 then
begin
Str:= Copy(Str,10,2*i);
for k:= j to (j + i - 1) do
begin
Buffer[k]:= StrToInt('$' + Copy(Str,1,2));
Delete(Str,1,2);
end;
end;
end;
procedure TForm1.InicializaGridBuffer;
var
i,r,j,k,l: integer;
begin
StringGrid1.ColWidths[0] := 35;
StringGrid1.Cells[0,0] := 'Addr';
for i := 0 to 15 do
StringGrid1.Cells[i+1,0] := IntTohex(i,2);
for j := 0 to (BufferSize div 16)-1 do begin
k := j;
StringGrid1.Height := StringGrid1.Height + 1;
StringGrid1.RowCount := StringGrid1.RowCount + 1;
StringGrid1.Cells[0,k+1] := IntToHex(l,4);
l := l + 16;
for r := 1 to 16 do
StringGrid1.Cells[r,k+1] := IntToHex(255,2);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if not ComPort.Connected then
ComPort.Open;
Comport.WriteStr(#2#0);
end;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin
ComPort.ReadStr(Str, Count);
if Str= 'Hi-LOGIC' then
Edit2.Text:=('Programmer detected........OK !')
else if Str = #1 then
begin
case Cuantos of
1: begin ComPort.WriteStr(#2#2);
Cuantos := 2;
end;
2: begin ComPort.WriteStr(#2#3);
Cuantos := 3;
end;
3: begin sleep(500);
Edit2.Text:=('Chip Erasing....... OK!')
end;
4: begin ComPort.WriteStr(#2#2);
Cuantos := 5;
end;
5: begin ComPort.WriteStr(#6#4#0#0#16#0);
ComPort.Write(Buffer[0],1);
Contador := 1;
end;
6: begin ComPort.WriteStr(#2#2);
Cuantos := 7;
end;
7: begin ComPort.WriteStr(#6#5#0#0#16#0);
end;
end;
end
else if Str = #2 then
begin
end
else if Str = #83 then
begin
if contador <= 4095 then
begin
ComPort.Write(Buffer[Contador],1);
ProgressBar1.Position := Contador;
Inc(Contador);
Edit5.Text := IntToStr(Contador);
end
else if contador = 4096 then
Edit2.Text:=('Flash Programmed........OK !')
end
else if (cuantos = 7) then
begin
BuffReceptor[CuentaB] := StrToInt(Str);
Inc(CuentaB);
if (CuentaB >= 4096) AND (Cuantos = 7) then
begin
cuantos := 0;
ShowMessage('Lectura de Chip terminada');
end ;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if not ComPort.Connected then
ComPort.Open;
Comport.WriteStr(#4#1#0#1);
Edit2.Text:=('>>>>>> >>>>>> >>>>>> >>>>>> >>>>>');
Cuantos := 1;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
if not ComPort.Connected then
ComPort.Open;
Comport.WriteStr(#4#1#0#1);
Cuantos := 4;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j,indice: integer;
Str: String;
begin
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
Edit2.Text:=('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
Edit2.Text:=('Load File..................OK !');
Memo1.Clear;
with TStringList.Create do
try
if FileExists(Edit1.Text) then
begin
LoadFromFile(Edit1.Text);
FillChar(Buffer,Sizeof(Buffer),#255);
for i:= 0 to Count - 1 do
Insertar(Strings[i],Buffer);
j:= StrToInt(Label2.caption);
Str:= EmptyStr;
end;
begin
indice := 0; for i := 1 to 255 do begin for j := 1 to 16 do begin stringgrid1.Cells[j,i] := inttohex(Buffer[indice],2);
inc(indice);
end;
end;
end;
Str:= Str + #32 + IntToHex(Buffer[i],2);
if ((i+1) mod 16 = 0) then
begin
Memo1.Lines.Add(Str);
Str:= EmptyStr;
end;
if Str <> EmptyStr then
Memo1.Lines.Add(Str);
finally
Free;
end;
end;
procedure TForm1.Memo1Change(Sender: TObject);
begin
if (Length(Memo1.Lines.Text) mod 26) = 0 then
begin
Memo1.Lines.Add(''); Memo1.SelStart := Length(Memo1.Lines.Text); end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
InicializaGridBuffer;
CuentaB := 0;
end;
procedure TForm1.Puerto1Click(Sender: TObject);
begin
ComPort.ShowSetupDialog ;
end;
procedure TForm1.AT89S511Click(Sender: TObject);
begin
Edit3.Text:=('AT89S51');
Edit4.Text:=('4096');
end;
procedure TForm1.AT89S521Click(Sender: TObject);
begin
Edit3.Text:=('AT89S52');
Edit4.Text:=('8192');
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
if not ComPort.Connected then
ComPort.Open;
Comport.WriteStr(#4#1#0#1);
Cuantos := 6;
end;
end.
Lo que decia son las declaraciones globales las que no los deja copilar.
Un Saludo.