1 | unit PinsIO;
|
---|
2 |
|
---|
3 | {$MODE Delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | procedure RstOn;
|
---|
8 | procedure RstOff;
|
---|
9 | procedure StrobeOn;
|
---|
10 | procedure StrobeOff;
|
---|
11 | procedure ChipselectOn;
|
---|
12 | procedure ChipselectOff;
|
---|
13 | function ReadRst:boolean;
|
---|
14 | procedure ClkLo;
|
---|
15 | procedure ClkHi;
|
---|
16 | procedure Send0;
|
---|
17 | procedure Send1;
|
---|
18 | procedure LedOn;
|
---|
19 | procedure LedOff;
|
---|
20 | function ReadBit:boolean;
|
---|
21 | procedure PinoutChanged;
|
---|
22 |
|
---|
23 | implementation
|
---|
24 |
|
---|
25 | uses Globals, PortsIO;
|
---|
26 |
|
---|
27 | var
|
---|
28 | last_data, last_control:byte;
|
---|
29 |
|
---|
30 | procedure SetDataBit(nr:byte);
|
---|
31 | begin
|
---|
32 | last_data:=last_data or (1 shl nr);
|
---|
33 | OutPort(BASE + DataPort, last_data);
|
---|
34 | end;
|
---|
35 |
|
---|
36 | procedure ClearDataBit(nr:byte);
|
---|
37 | begin
|
---|
38 | last_data:=last_data and (255-(1 shl nr));
|
---|
39 | OutPort(BASE + DataPort, last_data);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | function GetDataBit(nr:byte):boolean;
|
---|
43 | begin
|
---|
44 | Result:=((last_data and (1 shl nr)) <> 0);
|
---|
45 | end;
|
---|
46 |
|
---|
47 | procedure SetControlBit(nr:byte);
|
---|
48 | begin
|
---|
49 | last_control:=last_control or (1 shl nr);
|
---|
50 | OutPort(BASE + ControlPort, last_control);
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure ClearControlBit(nr:byte);
|
---|
54 | begin
|
---|
55 | last_control:=last_control and (255-(1 shl nr));
|
---|
56 | OutPort(BASE + ControlPort, last_control);
|
---|
57 | end;
|
---|
58 |
|
---|
59 | function GetControlBit(nr:byte):boolean;
|
---|
60 | begin
|
---|
61 | Result:=((last_control and (1 shl nr)) <> 0);
|
---|
62 | end;
|
---|
63 |
|
---|
64 | function GetStatusBit(nr:byte):boolean;
|
---|
65 | begin
|
---|
66 | Result:=((InPort(BASE + StatusPort) and (1 shl nr)) <> 0);
|
---|
67 | end;
|
---|
68 |
|
---|
69 | procedure SetLPTBit(nr:byte);
|
---|
70 | begin
|
---|
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;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure ClearLPTBit(nr:byte);
|
---|
88 | begin
|
---|
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;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | function GetLPTBit(nr:byte):boolean;
|
---|
106 | begin
|
---|
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;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure RstOn;
|
---|
118 | var v:boolean;
|
---|
119 | begin
|
---|
120 | v:=(proctype = PROC_TYPE_AVR) xor (not pinout.resetinv);
|
---|
121 | if v then
|
---|
122 | SetLPTBit(pinout.reset)
|
---|
123 | else
|
---|
124 | ClearLPTBit(pinout.reset);
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure RstOff;
|
---|
128 | var v:boolean;
|
---|
129 | begin
|
---|
130 | v:=(proctype = PROC_TYPE_AVR) xor pinout.resetinv;
|
---|
131 | if v then
|
---|
132 | SetLPTBit(pinout.reset)
|
---|
133 | else
|
---|
134 | ClearLPTBit(pinout.reset);
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure StrobeOn;
|
---|
138 | begin
|
---|
139 | ClearLPTBit(pinout.strobe1);
|
---|
140 | ClearLPTBit(pinout.strobe2);
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure StrobeOff;
|
---|
144 | begin
|
---|
145 | SetLPTBit(pinout.strobe1);
|
---|
146 | SetLPTBit(pinout.strobe2);
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure ChipselectOn;
|
---|
150 | begin
|
---|
151 | ClearLPTBit(pinout.reset);
|
---|
152 | end;
|
---|
153 |
|
---|
154 | procedure ChipselectOff;
|
---|
155 | begin
|
---|
156 | SetLPTBit(pinout.reset);
|
---|
157 | end;
|
---|
158 |
|
---|
159 | function ReadRst:boolean;
|
---|
160 | begin
|
---|
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;
|
---|
176 | end;
|
---|
177 |
|
---|
178 | procedure ClkLo;
|
---|
179 | begin
|
---|
180 | ClearLPTBit(pinout.sck);
|
---|
181 | end;
|
---|
182 |
|
---|
183 | procedure ClkHi;
|
---|
184 | begin
|
---|
185 | SetLPTBit(pinout.sck);
|
---|
186 | end;
|
---|
187 |
|
---|
188 | procedure Send0;
|
---|
189 | begin
|
---|
190 | ClearLPTBit(pinout.mosi);
|
---|
191 | end;
|
---|
192 |
|
---|
193 | procedure Send1;
|
---|
194 | begin
|
---|
195 | SetLPTBit(pinout.mosi);
|
---|
196 | end;
|
---|
197 |
|
---|
198 | procedure LedOn;
|
---|
199 | begin
|
---|
200 | ClearLPTBit(pinout.led);
|
---|
201 | end;
|
---|
202 |
|
---|
203 | procedure LedOff;
|
---|
204 | begin
|
---|
205 | SetLPTBit(pinout.led);
|
---|
206 | end;
|
---|
207 |
|
---|
208 | function ReadBit:boolean;
|
---|
209 | begin
|
---|
210 | Result:=GetLPTBit(pinout.miso);
|
---|
211 | end;
|
---|
212 |
|
---|
213 | procedure PinoutChanged;
|
---|
214 | begin
|
---|
215 | last_data:=InPort(BASE + DataPort);
|
---|
216 | last_control:=InPort(BASE + ControlPort);
|
---|
217 | end;
|
---|
218 |
|
---|
219 | end.
|
---|