/
project1.lpr
42 lines (37 loc) · 1.03 KB
/
project1.lpr
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
program project1;
{$mode objfpc}{$H+}
uses
sysutils,
pascalio, fpi2c,
{ you can add units after this };
var
idev: TI2CLinuxDevice;
bval: Byte;
begin
idev := nil;
try
idev := TI2CLinuxDevice.Create($20, 1);
writeln('Device file handle: ', idev.Handle);
bval := idev.ReadRegByte($12);
Writeln('Register $12 (GPIOA): ', binstr(bval,8));
idev.WriteRegByte($01, $00); // GPIOB = Output
for bval := 0 to 5 do
begin
idev.WriteRegByte($13, $FF);
Sleep(1000);
idev.WriteRegByte($13, $00);
Sleep(1000);
end;
except
// this exception handling should be a try/finally block
// but FPC 2.7.1 doesn't do the default exception handling
// so this is workaround to avoid memory leaking the exception object
on e: exception do
begin
writeln(ErrOutput, 'E Class : ', e.ClassName);
writeln(ErrOutput, 'E Message: ', e.Message);
writeln(ErrOutput, 'E Address: ', hexStr(ExceptAddr));
end;
end;
idev.Free;
end.