Want to control the external equipment by using the computer? Of great fun, especially with only a few lines of program Delphi, we can set the lights, turn on the motor, set the robot arm or to access other electronic equipment.
Perhaps this article can be a nutritious cemilan enough for Delphiers like ngoprek practical electronics, this is because we do not have to make a card I / 0 of its own, but simply using the parallel printer port only.
Parallel Printer Port
Port this one, is always available on every computer. Reflected in its name, this time more parallel port used for printing business data. In fact, the very day port can be used for anything else, because it has input / output (I / O) data.
Layout of the twenty-five-pin (DB 25) parallel printer port, shown in Figure 1.
Perhaps this article can be a nutritious cemilan enough for Delphiers like ngoprek practical electronics, this is because we do not have to make a card I / 0 of its own, but simply using the parallel printer port only.
Parallel Printer Port
Port this one, is always available on every computer. Reflected in its name, this time more parallel port used for printing business data. In fact, the very day port can be used for anything else, because it has input / output (I / O) data.
Layout of the twenty-five-pin (DB 25) parallel printer port, shown in Figure 1.
The table and the signal function of each pin on the parallel printer port, shown in Figure 2. From there the pin 2 s / d 9 (signal D0-D7) as a function of output, then we can take advantage of to control the external equipment. |
Series
For testing purposes, try shortly, we can connect the LED (Light Emitting diode) through the resistor, the output pin directly to the printer's parallel port. Can also only measure the voltage with a 5 volt arise, when the data port in a state of high.
For testing purposes, try shortly, we can connect the LED (Light Emitting diode) through the resistor, the output pin directly to the printer's parallel port. Can also only measure the voltage with a 5 volt arise, when the data port in a state of high.
To be able to access a large burden and to prevent the occurrence of excessive loading on the parallel printer port, should we use a series of buffer.
Of the scheme in Figure 4, visible pins 3,5,7,9,12,16 and 18 of the 74LS224 is connected to each relay. Next switch on each of these relays, we can use to control equipment that has a big burden. Delphi Code Program Unlike Turbo Pascal or Delphi 1 in which the port is available, on 32-bit Delphi (version 2 s / d 6) function is not supported anymore. Instead we use in-line assembler code. Listing 1. Turn the LED 5 of a series in Figure 3. procedure KirimDataKePort(AlamatPort: Word; DataBit: Byte);
|
In principle, to set the LED, we send binary data
8-bit to the port. Customize this binary data transmission, with LED
who want to start.
For example, to set the data is the first LED 1 hex
(binary; 0000001), while the binary data 10000000
(80 hex / dec 128) is used to set the LED eighth.
The list below, can be used as a reference.
DataPort Bit 0 = LED1 = 00000001 bin = 1 hex = dec 1
DataPort Bit 1 = LED2 = 00000010 bin = 2 = hex 2 dec
DataPort Bit 2 = LED3 = 00000100 bin = 4 = 4 dec hex
DataPort Bit 3 = LED4 = 00001000 bin = 8 = 8 dec hex
DataPort Bit 4 = LED5 = 00010000 bin = 10 hex = 16 dec
DataPort Bit 5 = LED6 = 00100000 bin = 20 hex = 32 dec
DataPort Bit 6 = LED7 = 01000000 bin = 40 hex = 64 dec
DataPort Bit 7 = LED8 = 10000000 bin = 80 hex = 128 dec
For those who want to experiment, Listing 2 is the program code
Control of Applications example, as seen in Figure 5.
Listing 2. Code control application program.
(* = Controlling external equipment via the Parallel Printer Port = *)
8-bit to the port. Customize this binary data transmission, with LED
who want to start.
For example, to set the data is the first LED 1 hex
(binary; 0000001), while the binary data 10000000
(80 hex / dec 128) is used to set the LED eighth.
The list below, can be used as a reference.
DataPort Bit 0 = LED1 = 00000001 bin = 1 hex = dec 1
DataPort Bit 1 = LED2 = 00000010 bin = 2 = hex 2 dec
DataPort Bit 2 = LED3 = 00000100 bin = 4 = 4 dec hex
DataPort Bit 3 = LED4 = 00001000 bin = 8 = 8 dec hex
DataPort Bit 4 = LED5 = 00010000 bin = 10 hex = 16 dec
DataPort Bit 5 = LED6 = 00100000 bin = 20 hex = 32 dec
DataPort Bit 6 = LED7 = 01000000 bin = 40 hex = 64 dec
DataPort Bit 7 = LED8 = 10000000 bin = 80 hex = 128 dec
For those who want to experiment, Listing 2 is the program code
Control of Applications example, as seen in Figure 5.
Listing 2. Code control application program.
(* = Controlling external equipment via the Parallel Printer Port = *)
unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, Buttons, ExtCtrls, StdCtrls;
- type
- TForm1 = class(TForm)
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- SpeedButton3: TSpeedButton;
- SpeedButton4: TSpeedButton;
- SpeedButton5: TSpeedButton;
- SpeedButton6: TSpeedButton;
- SpeedButton7: TSpeedButton;
- SpeedButton8: TSpeedButton;
- Bevel1: TBevel;
- Bevel2: TBevel;
- lblDataPortBit: TLabel;
- lblNoLED: TLabel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- procedure SpeedButton1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- procedure KirimDataKePort(DataPortBit: Byte);
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- uses
- Math;
- const
- AlamatPort = $378;
- procedure TForm1.KirimDataKePort(DataPortBit: Byte);
- var
- Nilai: Byte;
- begin
- lblDataPortBit.Caption := IntToStr(DataPortBit);
- lblNoLED.Caption := 'LED No. ' + IntToStr(DataPortBit + 1) +
- ' Nyala';
- Nilai := Trunc(Power(2, DataPortBit));
- asm
- MOV DX, AlamatPort
- MOV AL, Nilai
- OUT DX, AL
- end;
- end;
- procedure TForm1.SpeedButton1Click(Sender: TObject);
- begin
- (* Letakan 8 buah TSpeedButton, atur propeti Tag
- dari 8 TSpeedButton tersebut dengan nilai
- 0 sampai dengan 7. Dari Object Inspector,
- arahkan event Clik dari semua TSpeedButton
- ke SpeedButon1Click. *)
- KirimDataKePort((Sender as TSpeedButton).Tag);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- KirimDataKePort(0);
- end;
- end.