📄 main.pas
字号:
SendSerial(Addr);
MCID[ADDR]:=ReceiveSerial;
End;
PROG_ENABLE_AT90S2313 :
begin
FastDelay(2000);
SendSerial(PROG_ENABLE_AT90S2313);
SendSerial($FF xor PROG_ENABLE_AT90S2313);
Prog_Enable:=ReceiveSerial;
// SendSerial(PROG_ENABLE_AT90S2313);
// SendSerial(PROG_ENABLE_AT90S2313);
End;
READ_DATA_AT90S2313 :
begin
SendSerial(READ_DATA_AT90S2313);
Data := $ff00 and Addr;
Data := Swap(Data);
SendSerial(Data);
Data := $ff and Addr ;
SendSerial(Data);
// SendSerial(PROG_ENABLE_AT90S2313);
// SendSerial(PROG_ENABLE_AT90S2313);
End;
READ_DATA_AT90S2313 + 8 :
begin
SendSerial(READ_DATA_AT90S2313 + 8);
Data := $ff00 and Addr;
Data := Swap(Data);
SendSerial(Data);
Data := $ff and Addr ;
SendSerial(Data);
// SendSerial(PROG_ENABLE_AT90S2313);
// SendSerial(PROG_ENABLE_AT90S2313);
End;
CHIP_ERASE_AT90S2313 :
begin
SendSerial($FF xor CHIP_ERASE_AT90S2313);
SendSerial($80);
SendSerial($80);
SendSerial($80);
end;
WRITE_DATA_AT90S2313 :
begin
SendSerial(WRITE_DATA_AT90S2313);
Data := $ff00 and Addr;
Data := Swap(Data);
SendSerial(Data);
Data := $ff and Addr ;
SendSerial(Data);
end;
WRITE_DATA_AT90S2313 + 8 :
begin
SendSerial(WRITE_DATA_AT90S2313 + 8);
Data := $ff00 and Addr;
Data := Swap(Data);
SendSerial(Data);
Data := $ff and Addr ;
SendSerial(Data);
end;
READ_E2PDATA_AT90S2313 :
begin
SendSerial(READ_E2PDATA_AT90S2313); // Comando $A0 -> Leitura EEPROM
SendSerial(Addr); // Manda qualquer lixo
SendSerial(Addr); // Manda o endere鏾 a ser lido
// SendSerial(PROG_ENABLE_AT90S2313);
// SendSerial(PROG_ENABLE_AT90S2313);
End;
WRITE_E2PDATA_AT90S2313 :
begin
SendSerial(WRITE_E2PDATA_AT90S2313);
SendSerial(Addr); // Manda qualquer lixo
SendSerial(Addr);
end;
End;
end;
{
& Logical AND, if both bits are 1, the result is 1.
| Logical OR, if either bit is one, the result is 1.
^ Logical XOR, (exclusive OR), if one and only one
bit is 1, the result is 1.
~ Logical invert, if bit is 1, the result is 0, and
if bit is 0, the result is 1
<< n Left shift n places.
>> n Right shift n places.
}
procedure Tform1.EnableAddress(Apointer:pointer);
begin
cptr^ := cptr^ or $10;
Out32( pdata,(cptr^)); // set up data
Out32( pctrl, $08 ); // select control latch
Out32( pctrl, $09 ); // latch data
Out32( pctrl, $08 );
Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
end;
function Tform1.Getdata : Word;
var
tmp:word;
begin
// Out32( pdata, $0ff ); // set LPTx port data high
Out32( pdata, $0f ); // set LPTx port data high
Out32( pctrl, $24 ); // disable LPTx port data driver
Out32( pctrl, $26 ); // enable read data buffer
delay(2);// delay 10 uS
tmp:= Inp32( pdata ); // get data
Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
Getdata:= tmp;
end;
procedure Tform1.Setdata(Data : Word);
begin
Out32( pdata, Data ); // set up output data
Out32( pctrl, $04 ); // select data latch
Out32( pctrl, $05 ); // latch data
Out32( pctrl, $04 );
// Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
end;
procedure TForm1.EnableVpp(Apointer:pointer);
begin
// Enable 12 volts on Vpp.
// Note that Vpp will not immediately reach the specified value.
cptr^:=(cptr^ or $80);
Out32( pdata, (cptr^)); // set up data
Out32( pctrl, $08 ); // select control latch
Out32( pctrl, $09 ); // latch data
Out32( pctrl, $08 );
Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
end;
Procedure TForm1.Pulse(Apointer:pointer;Pls_Dly : Word);
begin
cptr^:=cptr^ or $04;
Out32( pdata, (cptr^)); // set up data
Out32( pctrl, $08 ); // select control latch
Out32( pctrl, $09 ); // latch data
Out32( pctrl, $08 );
//Form1.Delay(Pls_Dly);
FastDelay(Pls_dly);
// wait specified count
cptr^:=(cptr^ and (not $04));
Out32( pdata,(cptr^)); // set up data
Out32( pctrl, $08 ); // select control latch
Out32( pctrl, $09 ); // latch data
Out32( pctrl, $08 );
Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
end;
Procedure Tform1.EnableData(Apointer:Pointer);
Begin
Cptr^:=(Cptr^ or $20);
Out32( pdata, (Cptr^)); // set up data
Out32( pctrl, $08 ); // select control latch
Out32( pctrl, $09 ); // latch data
Out32( pctrl, $08 );
Out32( pctrl, $04 ); // control signals inactive
Out32( pdata, $0 ); // clear data
End;
function TForm1.NotBlank(Apointer:Pointer):boolean;
var
Address : Word;
rslt : Boolean;
begin
address:=$0;
rslt:=false;
Status.Caption:='Verificando - Blanck Check ! ';
MCreset( cptr ); // float signals, Vpp=5v
SetAdFunc( cptr, READ_DATA, $0fff ); // select function
EnableAddress(cptr); // enable func, PSEN*, PROG*
While (Address < Chipsize) do
begin
SetAdfunc(cptr, READ_DATA, Address); // apply address
Fastdelay(10); // delay address->data
Application.ProcessMessages;
if (Getdata <> $0ff) then // compare to erased value
rslt:= true; // not blank
Inc(Address);
end;
MCReset( cptr ); // float signals, Vpp=5v
NotBlank:=rslt;
end;
Procedure TForm1.MCRead(Apointer:pointer;Size:word;Compare:byte);
var
address:word;
temp:word;
order_byte : Boolean;
pos : integer;
begin
address:=$0;
pos:=0;
order_byte :=false;
Status.Caption:=' Lendo microcontrolador !';
// MCReset(Cptr); // float signals, Vpp=5v
// SetAdfunc(Cptr,READ_DATA,$0fff); // select function
// EnableAddress(Cptr); // enable func, PSEN*, PROG*
//delay(2);
// FastDelay(10);
while Address < Size do
begin
if order_byte = false then
SetAdfunc(Cptr, READ_DATA_AT90S2313,address ) // apply address
else
SetAdfunc(Cptr, $8 xor READ_DATA_AT90S2313,address ); // apply address
//delay(2); // delay address->data
// FastDelay(10);
case Compare of
0: if order_byte =false then
begin
ImageBuffer[pos] :=ReceiveSerial;
end
else
begin
ImageBuffer[pos + 1] :=ReceiveSerial;
end;
1:if order_byte =false then
begin
CompareBuffer[pos]:=ReceiveSerial;
end
else
begin
CompareBuffer[pos + 1 ]:=ReceiveSerial;
end
end;
Application.ProcessMessages;
Status.Font.Color:=clBlue;
case compare of
0: Status.Caption:=' Endere鏾 : '+(inttohex(address,4))+#13+' Dado : '+(inttohex(ImageBuffer[address],2));
1: Status.Caption:=' Endere鏾 : '+(inttohex(address,4))+#13+' Dado : '+(inttohex(CompareBuffer[address],2));
end;
if order_byte = false then
order_byte := true
else
begin
pos := pos + 2;
inc(address);
order_byte := false;
end;
end;
// MCReset(cptr); // float signals, Vpp=5v
Status.Caption:=' Fim !';
end;
Procedure TForm1.EEPRead(Apointer:pointer;Size:word;Compare:byte);
var
address:word;
temp:word;
order_byte : Boolean;
pos : integer;
begin
address:=$0;
pos:=0;
Status.Caption:=' Lendo EEPROM do microcontrolador !';
// MCReset(Cptr); // float signals, Vpp=5v
// SetAdfunc(Cptr,READ_DATA,$0fff); // select function
// EnableAddress(Cptr); // enable func, PSEN*, PROG*
//delay(2);
// FastDelay(10);
while Address < Size do
begin
SetAdfunc(Cptr, READ_E2PDATA_AT90S2313,address ); // apply address
// FastDelay(10);
case Compare of
0: ImageBuffer[pos] :=ReceiveSerial;
1: CompareBuffer[pos]:=ReceiveSerial;
end;
Application.ProcessMessages;
Status.Caption:=' Endere鏾 : '+(inttohex(address,4))+#13+' Dado : '+(inttohex(ImageBuffer[address],2));
inc(pos);
inc(address);
end;
// MCReset(cptr); // float signals, Vpp=5v
Status.Caption:=' Fim !';
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Dispose(Cptr);
Dispose(Frequency);
Dispose(FastCounter);
end;
procedure TForm1.MC_ERASEClick(Sender: TObject);
begin
MCerase;
beep;
end;
Procedure Tform1.MCErase;
begin
if MCType then
begin
Status.Caption:='Apagando !';
Application.ProcessMessages;
Setadfunc( cptr,CHIP_ERASE_AT90S2313, $0 ); // select function
FastDelay(8000);
MCReset( cptr );
Status.Caption:=' Fim !';
end;
end;
procedure TForm1.MC_READClick(Sender: TObject);
begin
if MCType then
begin
ResetBuffer;
// MCReset( cptr );
// Out32(PData,AT90S2313_SET_RST);
if SaveDialog1.Execute then
begin
// if Notblank(cptr) then
// begin
FilenameSave:=SaveDialog1.Filename;
MCRead(cptr,ChipSize,0);
CreateImgFile(ChipSize);
// end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -