-
Notifications
You must be signed in to change notification settings - Fork 0
/
led7sd.pas
232 lines (194 loc) · 5.6 KB
/
led7sd.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{
/***************************************************************************
led7sd.pas
----------
***************************************************************************/
*****************************************************************************
This file is part of the Lazarus packages by Andreas Jakobsche
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit LED7SD;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, GPIO;
type
TBitIndex = 0..3;
TDigitIndex = 1..4;
TLatchGPIOList = array[TDigitIndex] of TGPIOPort;
TDataGPIOList = array[TBitIndex] of TGPIOPort;
{ TBCDOutput4Digits }
TBCDOutput4Digits = class(TComponent)
private
{ Private declarations }
FDataGPIOs: TDataGPIOList;
FLatchGPIOs: TLatchGPIOList;
FText: string;
function GetDataGPIOs(AnIndex: TBitIndex): TGPIOPort;
function GetLatchGPIOs(AnIndex: TDigitIndex): TGPIOPort;
function GetA: Boolean;
function GetB: Boolean;
function GetC: Boolean;
function GetD: Boolean;
function GetLE(AnIndex: TDigitIndex): Boolean;
procedure SetA(AValue: Boolean);
procedure SetB(AValue: Boolean);
procedure SetC(AValue: Boolean);
procedure SetD(AValue: Boolean);
procedure SetLE(AnIndex: TDigitIndex; AValue: Boolean);
property DataGPIOs[AnIndex: TBitIndex]: TGPIOPort read GetDataGPIOs;
property LatchGPIOs[AnIndex: TDigitIndex]: TGPIOPort read GetLatchGPIOs;
function GetPortA: Integer;
function GetPortB: Integer;
function GetPortC: Integer;
function GetPortD: Integer;
procedure SetPortA(AValue: Integer);
procedure SetPortB(AValue: Integer);
procedure SetPortC(AValue: Integer);
procedure SetPortD(AValue: Integer);
procedure SetText(AValue: string);
procedure UpdateDisplay;
property A: Boolean read GetA write SetA;
property B: Boolean read GetB write SetB;
property C: Boolean read GetC write SetC;
property D: Boolean read GetD write SetD;
property LE[AnIndex: TDigitIndex]: Boolean read GetLE write SetLE;
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property PortA: Integer read GetPortA write SetPortA;
property PortB: Integer read GetPortB write SetPortB;
property PortC: Integer read GetPortC write SetPortC;
property PortD: Integer read GetPortD write SetPortD;
property Text: string read FText write SetText;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Hardware',[TBCDOutput4Digits]);
end;
{ TBCDOutput4Digits }
function TBCDOutput4Digits.GetDataGPIOs(AnIndex: TBitIndex): TGPIOPort;
begin
if not Assigned(FDataGPIOs[AnIndex]) then begin
FDataGPIOs[AnIndex] := TGPIOPort.Create(Self);
with FDataGPIOs[AnIndex] do begin
Direction := pdOutput
end;
end;
Result := FDataGPIOs[AnIndex]
end;
function TBCDOutput4Digits.GetLatchGPIOs(AnIndex: TDigitIndex): TGPIOPort;
begin
if not Assigned(FLatchGPIOs[AnIndex]) then begin
FLatchGPIOs[AnIndex] := TGPIOPort.Create(Self);
with FLatchGPIOs[AnIndex] do begin
Direction := pdOutputHigh
end;
end;
Result := FLatchGPIOs[AnIndex]
end;
function TBCDOutput4Digits.GetLE(AnIndex: TDigitIndex): Boolean;
begin
Result := LatchGPIOs[AnIndex].Value;
end;
function TBCDOutput4Digits.GetA: Boolean;
begin
Result := DataGPIOs[0].Value
end;
function TBCDOutput4Digits.GetB: Boolean;
begin
Result := DataGPIOs[1].Value
end;
function TBCDOutput4Digits.GetC: Boolean;
begin
Result := DataGPIOs[2].Value
end;
function TBCDOutput4Digits.GetD: Boolean;
begin
Result := DataGPIOs[3].Value
end;
procedure TBCDOutput4Digits.SetA(AValue: Boolean);
begin
DataGPIOs[0].Value := AValue;
end;
procedure TBCDOutput4Digits.SetB(AValue: Boolean);
begin
DataGPIOs[1].Value := AValue;
end;
procedure TBCDOutput4Digits.SetC(AValue: Boolean);
begin
DataGPIOs[2].Value := AValue;
end;
procedure TBCDOutput4Digits.SetD(AValue: Boolean);
begin
DataGPIOs[3].Value := AValue;
end;
procedure TBCDOutput4Digits.SetLE(AnIndex: TDigitIndex; AValue: Boolean);
begin
LatchGPIOs[AnIndex].Value := AValue
end;
procedure TBCDOutput4Digits.SetText(AValue: string);
begin
if FText=AValue then Exit;
FText:=AValue;
UpdateDisplay
end;
function TBCDOutput4Digits.GetPortA: Integer;
begin
Result := DataGPIOs[0].Address;
end;
function TBCDOutput4Digits.GetPortB: Integer;
begin
Result := DataGPIOs[1].Address
end;
function TBCDOutput4Digits.GetPortC: Integer;
begin
Result := DataGPIOs[2].Address
end;
function TBCDOutput4Digits.GetPortD: Integer;
begin
Result := DataGPIOs[3].Address
end;
procedure TBCDOutput4Digits.SetPortA(AValue: Integer);
begin
DataGPIOs[0].Address:= AValue;
end;
procedure TBCDOutput4Digits.SetPortB(AValue: Integer);
begin
DataGPIOs[1].Address := AValue
end;
procedure TBCDOutput4Digits.SetPortC(AValue: Integer);
begin
DataGPIOs[2].Address := AValue
end;
procedure TBCDOutput4Digits.SetPortD(AValue: Integer);
begin
DataGPIOs[3].Address := AValue
end;
procedure TBCDOutput4Digits.UpdateDisplay;
var
x: Byte;
i: TDigitIndex;
begin
for i := Low(TDigitIndex) to High(TDigitIndex) do begin
x := Ord(Text[i]) - Ord('0');
if (x >= 0) and (x <= 9) then begin
A := x and 1 <> 0;
B := x and 2 <> 0;
C := x and 4 <> 0;
D := x and 8 <> 0;
{Sleep(1); eventuell einfügen}
LE[i] := False;
{Sleep(1); eventuell einfügen}
LE[i] := True;
end;
end;
end;
end.