📄 main.pas
字号:
beep;
End;
end;
end;
Procedure Tform1.CreateImgFile(BufSize:Integer);
begin
AssignFile(ImageFileSave,FileNameSave); { Open output file }
{$I-}
Rewrite(ImageFileSave, 1);
{$I+}
if IOResult = 0 then
begin
BlockWrite(ImageFileSave, ImageBuffer, BufSize);
CloseFile(ImageFileSave);
End
else
MessageDlg('N鉶 pude gravar o arquivo !', mtWarning, [mbOk], 0);
end;
function TForm1.OpenImgFile(FileSize:Integer) : boolean;
var
rslt: Boolean;
begin
rslt:= False;
AssignFile(ImageFileLoad,FileNameOpen); { Open output file }
{I-}
Reset(ImageFileLoad, 1);
{I+}
if IOResult = 0 then
begin
BlockRead(ImageFileLoad, ImageBuffer, FileSize,NumRead);
CloseFile(ImageFileLoad);
rslt:=true;
end
else
MessageDlg('N鉶 pude ler o arquivo !', mtWarning, [mbOk], 0);
OpenImgFile:=Rslt;
end;
procedure TForm1.SysTimerTimer(Sender: TObject);
begin
Inc(SysDelay);
end;
procedure TForm1.MC_BURNClick(Sender: TObject);
begin
if Mctype then
begin
ResetBuffer;
if OpenDialog1.Execute then
begin
FilenameOpen:=OpenDialog1.Filename;
if (OpenImgFile(ChipSize)) then
begin
// if Notblank(cptr) then // Apaga mem髍ia se necess醨io antes de gravar
// MCErase;
// FastDelay(100);
MCProgram(Cptr,NumRead);
if (Burn_Compare.Checked = true) then
begin
MCRead(cptr,NumRead,1);
Show_dif.ShowModal;
end;
beep;
end
end
end;
end;
Procedure TForm1.ResetBuffer;
Begin
FillChar(ImageBuffer, SizeOf(ImageBuffer), $0ff);
FillChar(CompareBuffer, SizeOf(CompareBuffer), $0ff);
end;
procedure Tform1.MCProgram(Apointer:pointer;count:word);
var
address:word;
order_byte : boolean;
pos : integer;
begin
Address:=0;
pos:=0;
order_byte := false;
Status.Font.Color:=clRed;
Status.Caption:=' Gravando microcontrolador !';
// MCProg_enable;
while Address < (count div 2) do
begin
if order_byte = false then
begin
if ImageBuffer[pos] <> $FF then
begin
SetAdfunc(cptr,WRITE_DATA_AT90S2313,Address );// apply address
SendSerial(ImageBuffer[pos]);
FastDelay(4000);
end;
end
else
begin
if ImageBuffer[pos + 1] <> $FF then
begin
SetAdfunc(Cptr, $8 xor WRITE_DATA_AT90S2313,address ); // apply address
SendSerial(ImageBuffer[pos + 1]);
FastDelay(4000);
end;
end;
Application.ProcessMessages;
if order_byte = false then
order_byte := true
else
begin
Status.Caption:=' Endere鏾 : '+(inttohex(address,4))+#13+' Dado : '+(inttohex(ImageBuffer[address],2));
pos := pos + 2;
inc(address);
order_byte := false;
end;
end;
Status.Caption:=' Fim!';
end;
procedure Tform1.EEPromProgram(Apointer:pointer;count:word);
var
address:word;
pos : integer;
begin
Address:=0;
pos:=0;
Status.Caption:=' Gravando EEProm do microcontrolador !';
// MCProg_enable;
while Address < count do
begin
SetAdfunc(cptr,WRITE_E2PDATA_AT90S2313,Address );// apply address
SendSerial(ImageBuffer[pos]);
FastDelay(4000);
Application.ProcessMessages;
inc(address);
inc(pos);
end;
Status.Caption:=' Fim!';
end;
procedure TForm1.LockBits(Apointer:Pointer;LBit:Byte);
begin
MCReset(cptr); // float signals, Vpp=5v
Case LBit of // select function
1: SetAdfunc(cptr, WRITE_LOCK_1,$030); // apply function, address
2: begin
SetAdfunc(cptr, WRITE_LOCK_1,$030);
SetAdfunc(cptr, WRITE_LOCK_2,$030); // apply function, address
end;
3: begin
SetAdfunc(cptr, WRITE_LOCK_1,$030);
SetAdfunc(cptr, WRITE_LOCK_2,$030); // apply function, address
SetAdfunc(cptr, WRITE_LOCK_3,$030); // apply function, address
end;
End;
EnableAddress(cptr); // enable func, PSEN*, PROG*
Fastdelay(10); // delay 10 uS
if (MCID[2] = $0ff) then // Vpp=12v
begin
EnableVpp(cptr);
FastDelay(15000); // delay 15 mS Vpp rise->PROG*
end;
Pulse(cptr,100); // apply 100 uS PROG* pulse
Fastdelay(10); // delay PROG*->adr/data
MCreset(cptr); // float signals, Vpp=5v
if (MCID[2] = $0ff) then
FastDelay(15000); // delay 15 mS for Vpp fall
end;
procedure TForm1.HighResTimer;
begin
QueryPerformancefrequency(Frequency^);
end;
procedure Tform1.FastDelay(Fdly:Integer);
Var
Step:Extended; //7FFFFFFFFFFFFFFF
FrezzedCount:Int64;
Label FastTimerOvfl ;
begin
Step:=((Fdly*0.000001)/(1/Frequency^));
// Step:=((Fdly*0.000003)/(1/Frequency^));
Step:=(round(Step));
FastTimerOvfl :
QueryPerformanceCounter(FastCounter^);
FrezzedCount:=FastCounter^;
If (FrezzedCount >= ($7FFFFFFFFFFFFFFF - step)) then // Avoid Timer consuming Loop caused by timer overflow
goto FastTimerOvfl;
While FastCounter^ < FrezzedCount + Step do
begin
QueryPerformanceCounter(FastCounter^);
end;
// Form1.Caption:=Floattostr(CurrentCount)+ '----'+ Floattostr(FastCounter^);
end;
procedure TForm1.MC_LockBitsClick(Sender: TObject);
begin
if MCType then
LockBits(Cptr,Lock);
beep;
end;
procedure TForm1.NOLOCKClick(Sender: TObject);
begin
Lock:=0;
MC_LockBits.Enabled:=False;
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
Lock:=1;
MC_LockBits.Enabled:=True;
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
begin
Lock:=2;
MC_LockBits.Enabled:=True;
end;
procedure TForm1.RadioButton4Click(Sender: TObject);
begin
Lock:=3;
MC_LockBits.Enabled:=True;
end;
procedure TForm1.ProtectionClick(Sender: TObject);
begin
Case Protection.ItemIndex of
0: MC_LockBits.Enabled:=false;
1: begin
LOCK :=1;
MC_LockBits.Enabled:=True;
end;
2: begin
LOCK :=2;
MC_LockBits.Enabled:=True;
end;
3: begin
LOCK :=3;
MC_LockBits.Enabled:=True;
end;
end;
end;
procedure TForm1.SendSerial(Func_Byte:Byte);
Var
Loop : Integer ;
begin
Loop := 0;
Repeat
Fastdelay(35);
Data_Bit_Out:= $1 and (ord(Func_Byte) shr (7 - Loop));
Out32( PData,ord(Data_Bit_out) shl (1));
Fastdelay(65);
Out32( PData,$1 or ord(Data_Bit_out) shl (1));
Fastdelay(50);
Out32( PData, $1);
Fastdelay(50);
Out32( PData, $0);
Inc(Loop);
Until Loop > 7;
end;
function Tform1.ReceiveSerial:Byte;
Var
Loop : Integer ;
begin
Loop := 7;
Data := $0;
Repeat
// Fastdelay(15);
Data_Bit_out:=Inp32(PStatus);
Data_Bit_out:= $8 and Data_Bit_out;
Data_Bit_out:= (ord(Data_Bit_out) shr (3));
Data:=Data xor (ord(Data_Bit_out) shl (Loop));
Fastdelay(120);
Out32 (PData,$1);
Fastdelay(120);
Out32 (PData,$0);
Dec(Loop);
Until Loop < 0;
ReceiveSerial:=Data;
end;
function TFOrm1.MCProg_Enable:boolean;
begin
SetAdfunc( cptr, PROG_ENABLE_AT90S2313, $00);
if Prog_enable = $53 then
MCProg_Enable:=true
else
MCProg_Enable:=false;
end;
procedure TForm1.E2P_ReadClick(Sender: TObject);
begin
if MCType then
begin
// MCReset( cptr );
// Out32(PData,AT90S2313_SET_RST);
if SaveDialog2.Execute then
begin
FilenameSave:=SaveDialog2.Filename;
EEPRead(cptr,EEPRomSize,0);
CreateImgFile(EEPRomSize);
beep;
End;
end;
end;
procedure TForm1.E2P_BurnClick(Sender: TObject);
begin
if Mctype then
begin
// ResetBuffer;
if OpenDialog2.Execute then
begin
FilenameOpen:=OpenDialog2.Filename;
if (OpenImgFile(EEpromSize)) then
begin
// if Notblank(cptr) then // Apaga mem髍ia se necess醨io antes de gravar
// MCErase;
EEPromProgram(Cptr,NumRead);
if (Burn_Compare.Checked = true) then
begin
EEPRead(cptr,EEPRomSize,1);
Show_dif.ShowModal;
end;
beep;
end
end
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -