Rev Author Line No. Line
204 miho 1 unit PP_PGMHW;
2  
3 {== Ovladani programatoru ==}
4  
5 {========================================================}
6 { (c)DECROS 2000 miho, pefi }
7 { 1.0 - ovladani programatoru pres LPT a ALL03 }
8 { 1.1 - zmena vystupu cisla portu z DEC na HEX }
9 { - doplneni xDelayMicro(1) u vazby na ALL03 }
10 {========================================================}
11  
12  
13 interface
14  
15 uses DELAY,
16 PP_ALL03;
17  
18 type Logical=(zero,one,tristate); { typ pro definovani stavu vystupu }
19  
20 type PGM = object
21 {-- Rodicovsky objekt pro ovladani programatoru --}
22  
23 _PortAdr : word; { adresa portu }
24 _Error : string; { retezec posledni chyby }
25  
26 constructor Init(Port:word);
27 {== inicializuje a zapamatuje adresu ==}
28  
29 procedure Error(S:string);
30 virtual;
31 {== vypise chybu ==}
32  
33 procedure Info(S:string);
34 virtual;
35 {== vypise info ==}
36  
37 procedure SetVcc(Voltage:real);
38 virtual;
39 {== nastav napajeni ==}
40  
41 procedure SetVpp(Voltage:real);
42 virtual;
43 {== nastav programovaci napeti ==}
44  
45 procedure SetReset(Stat:Logical);
46 virtual;
47 {== nastav signal RESET dle Stat ==}
48  
49 procedure SetData(Stat:Logical);
50 virtual;
51 {== nastav signal DATA dle Stat ==}
52  
53 procedure SetClock(Stat:Logical);
54 virtual;
55 {== nastav signal CLOCK dle Stat ==}
56  
57 function GetData:boolean;
58 virtual;
59 {== precte stav datoveho vstupu ==}
60  
61 end; {object}
62  
63 type PGM_p=^PGM;
64  
65 type PGM_LPT = object(PGM)
66 {-- Objekt ovladani programatoru pres LPT --}
67  
68 _PortStat : byte;
69  
70 constructor Init(Port:word);
71 {== inicializuje, vstupem je cislo portu ==}
72  
73 procedure SetVcc(Voltage:real);
74 virtual;
75 {== nastav napajeni ==}
76  
77 procedure SetVpp(Voltage:real);
78 virtual;
79 {== nastav programovaci napeti ==}
80  
81 procedure SetReset(Stat:Logical);
82 virtual;
83 {== nastav signal RESET dle Stat ==}
84  
85 procedure SetData(Stat:Logical);
86 virtual;
87 {== nastav signal DATA dle Stat ==}
88  
89 procedure SetClock(Stat:Logical);
90 virtual;
91 {== nastav signal CLOCK dle Stat ==}
92  
93 function GetData:boolean;
94 virtual;
95 {== precte stav datoveho vstupu ==}
96  
97 end; {object}
98  
99 type PGM_LPT_p=^PGM_LPT;
100  
101 type PGM_ALL = object(PGM)
102 {-- Objekt ovladani programatoru ALL03 --}
103  
104 _ProgAdr : word;
105  
106 constructor Init(Port:word);
107 {== inicializuje, vstupem je cislo portu ==}
108  
109 procedure SetVcc(Voltage:real);
110 virtual;
111 {== nastav napajeni ==}
112  
113 procedure SetVpp(Voltage:real);
114 virtual;
115 {== nastav programovaci napeti ==}
116  
117 procedure SetReset(Stat:Logical);
118 virtual;
119 {== nastav signal RESET dle Stat ==}
120  
121 procedure SetData(Stat:Logical);
122 virtual;
123 {== nastav signal DATA dle Stat ==}
124  
125 procedure SetClock(Stat:Logical);
126 virtual;
127 {== nastav signal CLOCK dle Stat ==}
128  
129 function GetData:boolean;
130 virtual;
131 {== precte stav datoveho vstupu ==}
132  
133 end; {object}
134  
135 type PGM_ALL_p=^PGM_ALL;
136  
137 implementation
138  
139 function num2str(w:word):string;
140 {== Prevede cislo na retezec ( jako HEX cislo ) ===}
141 const prevod:array[0..15]of char=('0','1','2','3','4','5','6','7',
142 '8','9','A','B','C','D','E','F');
143 var s:string;
144 begin s[0]:=#4;
145 s[1]:=prevod[(w shr 12) and $F];
146 s[2]:=prevod[(w shr 8) and $F];
147 s[3]:=prevod[(w shr 4) and $F];
148 s[4]:=prevod[(w shr 0) and $F];
149 if s[1]='0' then s:=copy(s,2,255);
150 if s[1]='0' then s:=copy(s,2,255);
151 if s[1]='0' then s:=copy(s,2,255);
152 num2str:=s;
153 end; {num2str}
154  
155 {========================================================}
156 { }
157 { Programator prazdny prototyp }
158 { miho }
159 {========================================================}
160  
161 constructor PGM.Init(Port:word);
162 {== inicializuje a zapamatuje adresu ==}
163 begin _PortAdr:=0;
164 end; {Init}
165  
166 procedure PGM.Error(S:string);
167 {== vypise chybu ==}
168 begin _Error:=s;
169 end; {Error}
170  
171 procedure PGM.Info(S:string);
172 {== vypise info ==}
173 begin writeln('INFO: ',S);
174 end; {Error}
175  
176 procedure PGM.SetVcc(Voltage:real);
177 {== nastav napajeni ==}
178 begin
179 end; {SetVcc}
180  
181 procedure PGM.SetVpp(Voltage:real);
182 {== nastav programovaci napeti ==}
183 begin
184 end; {SetVpp}
185  
186 procedure PGM.SetReset(Stat:Logical);
187 {== nastav signal RESET dle Stat ==}
188 begin
189 end; {SetReset}
190  
191 procedure PGM.SetData(Stat:Logical);
192 {== nastav signal DATA dle Stat ==}
193 begin
194 end; {SetData}
195  
196 procedure PGM.SetClock(Stat:Logical);
197 {== nastav signal CLOCK dle Stat ==}
198 begin
199 end; {SetClock}
200  
201 function PGM.GetData:boolean;
202 {== precte stav datoveho vstupu ==}
203 begin
204 end; {GetData}
205  
206 {========================================================}
207 { }
208 { Programator via printer port }
209 { miho }
210 {========================================================}
211  
212 const LPT_DATA = $01; { Datovy vystup - RB7 }
213 LPT_DATAOE = $02; { Povoleni vystupu }
214 LPT_CLOCK = $04; { Hodiny - RB6 }
215 LPT_CLOCKOE = $08; { Povoleni vystupu }
216 LPT_VCC = $10; { Zapnuti +5V }
217 LPT_VPP = $20; { Zapnuti +12V na MCLR }
218 LPT_RES = $40; { Pripojeni 0V na MCLR }
219  
220 LPT_DATAIN = $40; { Maska bitu pro cteni dat }
221  
222  
223 constructor PGM_LPT.Init(Port:word);
224 var AdrTab:array[1..3]of word absolute 0:$408;{ tabulka LPT1..LPT3 z BIOSu }
225 {== inicializuje a zapamatuje adresu ==}
226 var w:word;
227 begin _PortAdr:=0;
228 _Error:='';
229 _PortStat:=0;
230 if (port<1) or (port>3) then Error('Invalid Port Number')
231 else _PortAdr:=AdrTab[Port];
232 if _PortAdr=0 then Error('Port not Registered in BIOS');
233 Info('Port Address '+num2str(_PortAdr)+'H');
234 if _Error<>'' then fail;
235 if _PortAdr<>0 then system.port[_PortAdr]:=_PortStat;
236 end; {Init}
237  
238 procedure PGM_LPT.SetVcc(Voltage:real);
239 {== nastav napajeni ==}
240 begin if Voltage = 5.0 then _PortStat:=_PortStat or LPT_VCC
241 else _PortStat:=_PortStat and not LPT_VCC;
242 if _PortAdr<>0 then port[_PortAdr]:=_PortStat;
243 xDelayMicro(1);
244 end; {SetVcc}
245  
246 procedure PGM_LPT.SetVpp(Voltage:real);
247 {== nastav programovaci napeti ==}
248 begin if Voltage=13.0
249 then _PortStat:= LPT_VPP or ( _PortStat and not LPT_RES )
250 else _PortStat:= _PortStat and not LPT_VPP;
251 if _PortAdr<>0 then port[_PortAdr]:=_PortStat;
252 xDelayMicro(1);
253 end; {SetVpp}
254  
255 procedure PGM_LPT.SetReset(Stat:Logical);
256 {== nastav signal RESET dle Stat ==}
257 begin case Stat of
258 zero : begin SetVpp(0);
259 _PortStat:=_PortStat or LPT_RES;
260 end;
261 one : _PortStat:=_PortStat and not LPT_RES;
262 end; {case}
263 if _PortAdr<>0 then port[_PortAdr]:=_PortStat;
264 xDelayMicro(1);
265 end; {SetReset}
266  
267 procedure PGM_LPT.SetData(Stat:Logical);
268 {== nastav signal DATA dle Stat ==}
269 begin case Stat of
270 zero : _PortStat := ( _PortStat and not LPT_DATA ) or LPT_DATAOE;
271 one : _PortStat := _PortStat or LPT_DATA or LPT_DATAOE;
272 tristate : _PortStat := ( _PortStat and not LPT_DATAOE and not LPT_DATA )
273 end; {case}
274 if _PortAdr<>0 then port[_PortAdr]:=_PortStat;
275 xDelayMicro(1);
276 end; {SetData}
277  
278 procedure PGM_LPT.SetClock(Stat:Logical);
279 {== nastav signal CLOCK dle Stat ==}
280 begin case Stat of
281 zero : _PortStat := ( _PortStat and not LPT_CLOCK ) or LPT_CLOCKOE;
282 one : _PortStat := _PortStat or LPT_CLOCK or LPT_CLOCKOE;
283 tristate : _PortStat := ( _PortStat and not LPT_CLOCKOE and not LPT_CLOCK )
284 end; {case}
285 if _PortAdr<>0 then port[_PortAdr]:=_PortStat;
286 xDelayMicro(1);
287 end; {SetClock}
288  
289 function PGM_LPT.GetData:boolean;
290 {== precte stav datoveho vstupu ==}
291 begin GetData:=(port[_PortAdr+1] and LPT_DATAIN) = LPT_DATAIN;
292 xDelayMicro(1);
293 end; {GetData}
294  
295  
296 {========================================================}
297 { }
298 { Programator ALL03 }
299 { pefi }
300 {========================================================}
301  
302 { Tato cast v podstate jen vola funkce jednotky ProgAll }
303  
304 const ALL_VCC = 30;
305 ALL_GND = 11;
306 ALL_VPP = 10;
307 ALL_CLOCK = 28;
308 ALL_DATA = 29;
309  
310 Constructor PGM_All.Init(Port:Word);
311 {== provede inicializaci programatoru ==}
312 begin
313 Initialize(Port);
314 Gnd11(true); { pripoji zem na vyvodu 11 }
315 end;{End Init}
316  
317 procedure PGM_All.SetVcc(Voltage:real);
318 {== zapina a vypina napajeni ==}
319 begin
320 SetVoltageV1(Voltage);
321 if Voltage=0 then ConnectV1(ALL_VCC,false)
322 else ConnectV1(ALL_VCC,true);
323 xDelayMicro(1);
324 end;{End SetVcc}
325  
326 procedure PGM_All.SetVpp(Voltage:real);
327 {== zapina a vypina programovaci napeti ==}
328 begin
329 SetVoltageV2(Voltage);
330 if Voltage=0 then ConnectV2(ALL_VPP,false)
331 else ConnectV2(ALL_VPP,true);
332 xDelayMicro(1);
333 end;{EndSetVpp}
334  
335 procedure PGM_All.SetReset(Stat:Logical);
336 {== nastavi nebo shodi signal Reset-VPP ==}
337 begin
338 ConnectV2(ALL_VPP,false);{nejdrive nutno Vpp odpojit}
339 if Stat = zero then SetBit(ALL_VPP,0)
340 else SetBit(ALL_VPP,1);
341 xDelayMicro(1);
342 end;{EndSetReset}
343  
344 procedure PGM_All.SetData(Stat:Logical);
345 {== nastavi nebo shodi signal DATA ==}
346 begin
347 if Stat = zero then SetBit(ALL_DATA,0)
348 else SetBit(ALL_DATA,1);
349 xDelayMicro(1);
350 end;{End SetData}
351  
352 procedure PGM_All.SetClock(Stat:Logical);
353 {== nastavi nebo shodi signal CLK ==}
354 begin
355 if Stat = zero then SetBit(ALL_CLOCK,0)
356 else SetBit(ALL_CLOCK,1);
357 xDelayMicro(1);
358 end;{End SetClock}
359  
360 function PGM_All.GetData:boolean;
361 var
362 stav:byte;
363 begin
364 Stav:=GetBit(ALL_DATA);
365 if Stav=1 then GetData:=true
366 else GetData:=false;
367 xDelayMicro(1);
368 end;{End GetData}
369  
370 end.