(*PROIECT MICROPROCESOARE II --FLORIAN ANTAL ARPAD 2241/1 UTC-N (C)1999*) (*Teoretic functioneaza cu 27C64,27C128 inscrie fisier binar*) program ProgramatorEPROM; uses TpTimer; {UNIT ce contine functii pentru temporizare} const WhichPort : word = $378; {portul de imprimanta} var a : LongInt; b, counter : byte; m, i : word; c : char; F : file; timp :integer; data : array[0..32768] of byte; {buffer pentru date} function ReadPort:byte; {Intoarce datele din EPROM} var b:byte; begin port[WhichPort]:=255; {PULL-UP} port[WhichPort+2]:=3+32; {PORT setat pentru intrare} b:=port[WhichPort]; port[WhichPort+2]:=11; ReadPort:=b; end; procedure SetAddress(Addr: word); {seteaza adresa pentru EPROM} var lo,hi:byte; begin asm mov ax,ADDR mov lo,al mov hi,ah end; port[WhichPort+2]:=13; {Init - pentru LATCH LO} port[WhichPort]:=lo; port[WhichPort+2]:=9; port[WhichPort+2]:=8; {Strobe - pentru LATCH HI()} port[WhichPort]:=hi; port[WhichPort+2]:=9; {AUTOFD - e A14 la alte EPROMuri} end; procedure TestError(a:byte); begin case a of 0: writeln('La revedere....'); 1: writeln('EPROM stricat - dupa 10 incercari adresa ',m,' s-a dovedit stricat'); 2: writeln('EPROM lipseste sau dispozitiv neconectet, nealimentat etc.'); 3: begin WriteLn('Programul se porneste: ',paramstr(0),' nume_fisier <$378|$278|$3BC>'); WriteLn('unde nume_fisier este fisierul binar ce trebuie programat in EPROM'); WriteLn('si putem selecta si portul paralel'); end; 4: writeln('Nu pot citi fisierul ', paramstr(1)); 5: writeln('Parametrul al doilea nu este precizat corect.'); 6: writeln('Port paralel inexistent. Valori acceptate: $378,$3BC,$278'); else writeln('UNKNOWN ERROR CODE ',a); end; halt(a); end; function FileExists(FileName: String): Boolean; begin {$I-} Assign(F, FileName); FileMode := 0; { Set file access to read only } Reset(F,1); {$I+} FileExists := (IOResult = 0) and (FileName <> ''); end; { FileExists } begin writeln('Programator EPROM. (C) 1999 Proiect la MICROPROCESOARE II'); writeln('FLORIAN ANTAL ARPAD grupa 2241/1 UNIVERSITATEA TECHNICA CLUJ'); writeln; writeln('Tasteaza 1 pentru 2716 sau orice altceva pentru alte tipuri de EPROM'); readln(timp); if timp=1 then timp:=45 else timp:=90; if paramcount>1 then val(paramstr(2),WhichPort,i); if (i<>0) then TestError(5); if (WhichPort<>$378) and (WhichPort<>$278) and (WhichPort<>$3BC) then TestError(6); port[WhichPort+2]:=9; {Initializare programator. Numai -PGM e Hi} if not(FileExists(ParamStr(1))) then TestError(3); {$I-} blockread(F,data,FileSize(F)); {citesc fisierul in buffer} {$I+} if IOResult <> 0 then TestError(4); for i:=0 to filesize(f)-1 do begin WriteLn('Scriere la adresa ',i,' valoarea ',data[i]); SetAddress(i); port[WhichPort]:=data[i]; repeat a:=Readtimer; repeat until abs(readtimer-a)>timp; {astept aprox 50/100 ms} inc(counter); a:=Readtimer; asm mov dx,37ah {Program pulse on} mov al,3 out dx,al end; repeat until abs(readtimer-a)>timp; {astept aprox 50/100 ms} asm mov dx,37ah {Program pulse off} mov al,9 out dx,al end; until (counter>10); if ReadPort=data[i] then if i=0 then TestError(2) else TestError(1); counter:=0; end; close(F); restoretimer; TestError(0); end.