Access Tools Foreign Through Parallel Printer Port

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.





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.




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);
  1. (* alamat LPT1, range 378-37F hex
  2. alamat LPT2, range 278-37F hex
  3. alamat LPT3, range 3BC-3BF hex
  4. lihat juga referensi teknis dari Intel dan Microsoft *)
  5. asm
  6. MOV   DX, AlamatPort
  7. MOV   AL, DataBit
  8. OUT   DX, AL
  9. end;
  10.  
  11. procedure TForm1.btnLED5Click(Sender: TObject);
  12. begin
  13. (* contoh pemanggilan prosedur KirimDataKePort,
  14. ini akan menyalakan LED 5 (data bit-4 / pin 6
  15. dari rangkaian yang terdapat pada Gambar 3.  *)
  16. KirimDataKePort($378, $8); //00010000 biner
  17. end;

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 = *)

unit Unit1;
  1.  
  2. interface
  3.  
  4. uses
  5. Windows, Messages, SysUtils, Classes, Graphics, Controls,
  6. Forms, Dialogs, Buttons, ExtCtrls, StdCtrls;
  7. type
  8. TForm1 = class(TForm)
  9. SpeedButton1: TSpeedButton;
  10. SpeedButton2: TSpeedButton;
  11. SpeedButton3: TSpeedButton;
  12. SpeedButton4: TSpeedButton;
  13. SpeedButton5: TSpeedButton;
  14. SpeedButton6: TSpeedButton;
  15. SpeedButton7: TSpeedButton;
  16. SpeedButton8: TSpeedButton;
  17. Bevel1: TBevel;
  18. Bevel2: TBevel;
  19. lblDataPortBit: TLabel;
  20. lblNoLED: TLabel;
  21. Label1: TLabel;
  22. Label2: TLabel;
  23. Label3: TLabel;
  24. procedure SpeedButton1Click(Sender: TObject);
  25. procedure FormCreate(Sender: TObject);
  26. private
  27. procedure KirimDataKePort(DataPortBit: Byte);
  28. public
  29. { Public declarations }
  30. end;
  31.  
  32. var
  33. Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.DFM}
  38.  
  39. uses
  40. Math;
  41.  
  42. const
  43. AlamatPort = $378;
  44.  
  45. procedure TForm1.KirimDataKePort(DataPortBit: Byte);
  46. var
  47. Nilai: Byte;
  48. begin
  49. lblDataPortBit.Caption := IntToStr(DataPortBit);
  50. lblNoLED.Caption := 'LED No. ' + IntToStr(DataPortBit + 1) +
  51. ' Nyala';
  52. Nilai := Trunc(Power(2, DataPortBit));
  53. asm
  54. MOV     DX, AlamatPort
  55. MOV     AL, Nilai
  56. OUT     DX, AL
  57. end;
  58. end;
  59.  
  60. procedure TForm1.SpeedButton1Click(Sender: TObject);
  61. begin
  62. (* Letakan 8 buah TSpeedButton, atur propeti Tag
  63. dari 8 TSpeedButton tersebut dengan nilai
  64. 0 sampai dengan 7. Dari Object Inspector,
  65. arahkan event Clik dari semua TSpeedButton
  66. ke SpeedButon1Click. *)
  67.  
  68. KirimDataKePort((Sender as TSpeedButton).Tag);
  69. end;
  70.  
  71. procedure TForm1.FormCreate(Sender: TObject);
  72. begin
  73. KirimDataKePort(0);
  74. end;
  75.  
  76. end.