Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Control LPT port under windows XP using Delphi

Another way of controlling LPT port under Windows 2000 and XP using Delphi language. In this case library inpout32.dll is used which allows controlling LPT port registers.

Ready project for Borland Delphi 7.0 you can download here: Project Files<187.5kB>

And now how to do this from beginning. Start Borland Delphi 7.0 and make simple form where you can enter Data to be sent to port, Port Address, buttons for writing to and reading from port.



If you are familiar with building forms this should be ease task.

OK now lets start programming. First of all wee need somehow to include inpout32.dll in to the project. For this Delphi has several ways, but lets stay to the easiest one when library is in same directory, where project is. Then in header in section uses we have to place function prototypes Out32 and Inp32 with special compiler directive external, saying where to find this finction.

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

 function Inp32(PortAdr: word): byte; stdcall; external 'inpout32.dll';
 function Out32(PortAdr: word; Data: byte): byte; stdcall; external 'inpout32.dll';


Then lets go to the button methods. For this double click on button in form and you will be directed to editor. Firs o all lets work with wiring to port function. Place data to the variables Port and Data from text fields convert them from text to numerical data and then call function Out32() with these parameters.


procedure TForm1.Button1Click(Sender: TObject);
    Port: word;
    Data: Byte;
    Data:= StrToInt(Edit1.Text);
    Port:= StrToInt(Edit2.Text);
    Out32(Port, Data);


Same way we have to deal with reading. Port Address is taken from Port Address text field. This is where data will be read from. Then call function Inp32() with port number and output received data to the window.


procedure TForm1.Button2Click(Sender: TObject);
    Port: word;
    Data: Byte;
    Port:= StrToInt(Edit3.Text);
    Data:= Inp32(Port);
    MessageDlg('Value: '+ IntToStr(Data), mtInformation, [mbOK], 0);


Compile program and start. Try to write to DATA register of LPT port number 0. For this port address will be 888(or hexadecimal $378). Press button and if you have some tester connected to LPT you will se the results. Same way you can work with reading.

Source: www.pcports.ru



  1. Thanks for this program too much
    and i have qusetion ?
    the qusetion is i want turn of the LED by LPT and and Turn on Again . ”Led is simple light”
    Please Help me.
    and thanks again for this program.

  2. Hello friend!

    well, it works but i have a question:
    i’m having problems with the interval between the bytes.
    I’m controlling a CNC driver and i’m trying to use my PC as a pulse generator.
    The minimum interval that i can get is 15.0 miliseconds. This have something to deal with the dll? (some delay)
    When i use MSDos (booted with command.com) i can reach to 0.2 miliseconds

  3. Richard!

    This not dll trouble,this is MSWin-sux!-(don’t let more than 10 millisec time(interrupt). U must use some external circuit with(PIC) or some other microcontroller.

    Sorry about my english


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.