Monday 19 July 2010

Accessing your PC’s parallel port using Inpout32.dll in Delphi

(Dancing Lamp # 1)

Before we create a dancing lamp using our PC’s parallel port, we have to know the parallel port female pin-out (see the picture below).

D0 is the LSB (Least Significant Bit) and D7 is the Most Significant Bit (MSB). You can send an integer type data to the D0..D7 pin-outs. And the output will be the binary form of the integer we send. For example : If we send an integer data 15 the output will be :

D7D6D5D4D3D2D1D0
LOWLOWLOWLOWHIGHHIGHHIGHHIGH

15 (byte) = 00001111 (binary)

How To Send Data To The Parallel Port ?

To send data to the parallel port I use a DLL file (Inpout32.dll) that can be downloaded at logix4u.net, and it’s free for non-commercial manner. Place this file in C:\WINDOWS\system or in the same folder with you project you’re going to create.

To use this file you can see my previous tutorial about using a DLL file. This DLL file contains a function called Out32(). The syntax of this function :

                                                    Out32(portaddress,data);

Usually, the port address is $378 (you can check the BIOS setting of your PC) 

Example program :

unit Unit1;

interface

uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   StdCtrls;

type
   TForm1 = class(TForm)
   Edit1: TEdit;
   Label1: TLabel;
   Button1: TButton;
   procedure FormActivate(Sender: TObject);
   procedure Button1Click(Sender: TObject);
private
  { Private declarations }
public
  { Public declarations }
end;

var
   Form1: TForm1;

implementation

{$R *.DFM}
function Out32(wAddr:word;bOut:byte):byte; stdcall; external 'inpout32.dll';

procedure TForm1.FormActivate(Sender: TObject);
begin
  Edit1.Text := '';
  Edit1.SetFocus; 
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Out32($378,StrToInt(Edit1.Text));
end;

end.

You can download the complete code here.

Go to next tutorial (LED Circuit)

2 comments:

  1. berkunjung untuk memungut ilmu he he he...

    salam sukses selalu

    ReplyDelete
  2. Peace..:).. I tried to follow the steps you have written, but I still have a problem.. the leds does not light up..:(.. Can you please help me.. the delphi program runs perfectly..:| but the leds does not light up sending it any integer number..:( I bought a pci to parallel expansion slot and the base address of my lpt1 is 3BC/3BCh.. I/O range is D880-D887.. need help.. I have an email address, please do help for God's sake..:( b69i.vio8@gmail.com

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.