
Quelltextauszüge: Programmieren des Elektor-Flash-Boards zum 89S8252
procedure SPIout_MB ( Wert : Byte ); //Modul-Bus-Version
var Stelle, n : Integer;
begin
Stelle := 128; {MSB zuerst}
for n:=1 to 8 do begin
if ((Wert AND Stelle) > 0) then
TXD(0) { Daten an TXD/MOSI }
else TXD(1);
Delay (0.01); { Verzögerung }
RTS (0); { Clock an (RTS) }
Stelle := Stelle div 2;
Delay (0.01); { Verzögerung }
RTS (1); { Clock aus (RTS) }
Delay (0.01); { Verzögerung }
end;
Delay (0.01); { Verzögerung }
TXD (1);
end;
procedure SPIout ( Wert : Byte ); //Elektor-Version
var Stelle, n : Integer;
begin
Stelle := 128; {MSB zuerst}
for n:=1 to 8 do begin
if ((Wert AND Stelle) > 0) then
TXD(0) { Daten an TXD/MOSI }
else TXD(1);
Delay (0.01); { Verzögerung }
RTS (1); { Clock an }
Stelle := Stelle div 2;
Delay (0.01); { Verzögerung }
RTS (0); { Clock aus }
Delay (0.01); { Verzögerung }
end;
Delay (0.01); { Verzögerung }
TXD (1);
end;
procedure Prog (Adresse:Word; Daten: Byte);
begin
SPIout (hi(Adresse) * 8 + 2);
SPIout (lo (Adresse));
SPIout (Daten);
Delay (5); {5ms reicht}
end;
procedure TForm1.ButtonRunClick(Sender: TObject);
var f :File of Byte;
Zeile: String;
r,wert :Byte;
Anzahl: Byte;
Adresse, n, i : Word;
Code: Byte;
begin
if COM=2 then OpenCOM (pchar ('COM2:9600,N,8,1'));
if COM=1 then OpenCOM (pchar ('COM1:9600,N,8,1'));
AssignFile(f,'work.bin');
{$I-} Reset(f); {$I+}
r:=IOResult;
IF r = 0 then begin
RTS (1); //Sclk=0; // nur MB, weil RTS > Sclk invertiert
Delay (100);
DTR (1); //RESET=1;
Delay(100);
SPIout ($AC); //Prog Enable
SPIout ($53);
SPIout ($00);
Adresse :=0;
Memo2.clear;
Memo2.Lines.add ('');
n := Memo2.Lines.count-1;
Memo2.Lines[n] := '0000 ';
while not Eof (f) do begin
Read(f,Code);
Memo2.Lines[n] := memo2.Lines[n]+' '+ByteToHex(Code);
Prog (Adresse, Code);
Delay (5);
Adresse := Adresse + 1;
If (Adresse mod 16) = 0 then begin
if Memo2.Lines.Count > 260 then Memo2.Clear;
Memo2.Lines.add ('');
n := Memo1.Lines.Count -1;
Memo2.Lines[n] := ByteToHex(Adresse div 256)
+ByteToHex(Adresse and 255)+' ';
end;
end;
CloseFile(f);
TXD (0);
DTR (0);
RTS (0);
end;
CloseCOM;
end;