source: ISPProgrammer/ISPprog/PinsIO.pas

Last change on this file was 363, checked in by chronos, 12 years ago
  • Added: Package ISPProgrammer for in-system programming of various chips. Supports Dallas ISP protocol, Presto, Rabbit RFU and some others Atmel devices.
File size: 4.7 KB
Line 
1unit PinsIO;
2
3{$MODE Delphi}
4
5interface
6
7procedure RstOn;
8procedure RstOff;
9procedure StrobeOn;
10procedure StrobeOff;
11procedure ChipselectOn;
12procedure ChipselectOff;
13function ReadRst:boolean;
14procedure ClkLo;
15procedure ClkHi;
16procedure Send0;
17procedure Send1;
18procedure LedOn;
19procedure LedOff;
20function ReadBit:boolean;
21procedure PinoutChanged;
22
23implementation
24
25uses Globals, PortsIO;
26
27var
28 last_data, last_control:byte;
29
30procedure SetDataBit(nr:byte);
31begin
32 last_data:=last_data or (1 shl nr);
33 OutPort(BASE + DataPort, last_data);
34end;
35
36procedure ClearDataBit(nr:byte);
37begin
38 last_data:=last_data and (255-(1 shl nr));
39 OutPort(BASE + DataPort, last_data);
40end;
41
42function GetDataBit(nr:byte):boolean;
43begin
44 Result:=((last_data and (1 shl nr)) <> 0);
45end;
46
47procedure SetControlBit(nr:byte);
48begin
49 last_control:=last_control or (1 shl nr);
50 OutPort(BASE + ControlPort, last_control);
51end;
52
53procedure ClearControlBit(nr:byte);
54begin
55 last_control:=last_control and (255-(1 shl nr));
56 OutPort(BASE + ControlPort, last_control);
57end;
58
59function GetControlBit(nr:byte):boolean;
60begin
61 Result:=((last_control and (1 shl nr)) <> 0);
62end;
63
64function GetStatusBit(nr:byte):boolean;
65begin
66 Result:=((InPort(BASE + StatusPort) and (1 shl nr)) <> 0);
67end;
68
69procedure SetLPTBit(nr:byte);
70begin
71 case nr of
72 LPT_OUT_STROBE: ClearControlBit(0); // inverted
73 LPT_OUT_D0: SetDataBit(0);
74 LPT_OUT_D1: SetDataBit(1);
75 LPT_OUT_D2: SetDataBit(2);
76 LPT_OUT_D3: SetDataBit(3);
77 LPT_OUT_D4: SetDataBit(4);
78 LPT_OUT_D5: SetDataBit(5);
79 LPT_OUT_D6: SetDataBit(6);
80 LPT_OUT_D7: SetDataBit(7);
81 LPT_OUT_AUTOLF: ClearControlBit(1); // inverted
82 LPT_OUT_INIT: SetControlBit(2);
83 LPT_OUT_SELECTIN: ClearControlBit(3); // inverted
84 end;
85end;
86
87procedure ClearLPTBit(nr:byte);
88begin
89 case nr of
90 LPT_OUT_STROBE: SetControlBit(0); // inverted
91 LPT_OUT_D0: ClearDataBit(0);
92 LPT_OUT_D1: ClearDataBit(1);
93 LPT_OUT_D2: ClearDataBit(2);
94 LPT_OUT_D3: ClearDataBit(3);
95 LPT_OUT_D4: ClearDataBit(4);
96 LPT_OUT_D5: ClearDataBit(5);
97 LPT_OUT_D6: ClearDataBit(6);
98 LPT_OUT_D7: ClearDataBit(7);
99 LPT_OUT_AUTOLF: SetControlBit(1); // inverted
100 LPT_OUT_INIT: ClearControlBit(2);
101 LPT_OUT_SELECTIN: SetControlBit(3); // inverted
102 end;
103end;
104
105function GetLPTBit(nr:byte):boolean;
106begin
107 case nr of
108 LPT_IN_ACK: Result:=GetStatusBit(6);
109 LPT_IN_BUSY: Result:=not GetStatusBit(7); // inverted
110 LPT_IN_PAPEREND: Result:=GetStatusBit(5);
111 LPT_IN_SELECT: Result:=GetStatusBit(4);
112 LPT_IN_ERROR: Result:=GetStatusBit(3);
113 else Result:=false;
114 end;
115end;
116
117procedure RstOn;
118var v:boolean;
119begin
120 v:=(proctype = PROC_TYPE_AVR) xor (not pinout.resetinv);
121 if v then
122 SetLPTBit(pinout.reset)
123 else
124 ClearLPTBit(pinout.reset);
125end;
126
127procedure RstOff;
128var v:boolean;
129begin
130 v:=(proctype = PROC_TYPE_AVR) xor pinout.resetinv;
131 if v then
132 SetLPTBit(pinout.reset)
133 else
134 ClearLPTBit(pinout.reset);
135end;
136
137procedure StrobeOn;
138begin
139 ClearLPTBit(pinout.strobe1);
140 ClearLPTBit(pinout.strobe2);
141end;
142
143procedure StrobeOff;
144begin
145 SetLPTBit(pinout.strobe1);
146 SetLPTBit(pinout.strobe2);
147end;
148
149procedure ChipselectOn;
150begin
151 ClearLPTBit(pinout.reset);
152end;
153
154procedure ChipselectOff;
155begin
156 SetLPTBit(pinout.reset);
157end;
158
159function ReadRst:boolean;
160begin
161 case pinout.reset of
162 LPT_OUT_STROBE: Result:=not GetControlBit(0); // inverted
163 LPT_OUT_D0: Result:=GetDataBit(0);
164 LPT_OUT_D1: Result:=GetDataBit(1);
165 LPT_OUT_D2: Result:=GetDataBit(2);
166 LPT_OUT_D3: Result:=GetDataBit(3);
167 LPT_OUT_D4: Result:=GetDataBit(4);
168 LPT_OUT_D5: Result:=GetDataBit(5);
169 LPT_OUT_D6: Result:=GetDataBit(6);
170 LPT_OUT_D7: Result:=GetDataBit(7);
171 LPT_OUT_AUTOLF: Result:=not GetControlBit(1); // inverted
172 LPT_OUT_INIT: Result:=GetControlBit(2);
173 LPT_OUT_SELECTIN: Result:=not GetControlBit(3); // inverted
174 else Result:=false;
175 end;
176end;
177
178procedure ClkLo;
179begin
180 ClearLPTBit(pinout.sck);
181end;
182
183procedure ClkHi;
184begin
185 SetLPTBit(pinout.sck);
186end;
187
188procedure Send0;
189begin
190 ClearLPTBit(pinout.mosi);
191end;
192
193procedure Send1;
194begin
195 SetLPTBit(pinout.mosi);
196end;
197
198procedure LedOn;
199begin
200 ClearLPTBit(pinout.led);
201end;
202
203procedure LedOff;
204begin
205 SetLPTBit(pinout.led);
206end;
207
208function ReadBit:boolean;
209begin
210 Result:=GetLPTBit(pinout.miso);
211end;
212
213procedure PinoutChanged;
214begin
215 last_data:=InPort(BASE + DataPort);
216 last_control:=InPort(BASE + ControlPort);
217end;
218
219end.
Note: See TracBrowser for help on using the repository browser.