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.

Delphi_LPT.gif

 

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.

uses
  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);
var
    Port: word;
    Data: Byte;
begin
    Data:= StrToInt(Edit1.Text);
    Port:= StrToInt(Edit2.Text);
    Out32(Port, Data);
end;

 

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);
var
    Port: word;
    Data: Byte;
begin
    Port:= StrToInt(Edit3.Text);
    Data:= Inp32(Port);
    MessageDlg('Value: '+ IntToStr(Data), mtInformation, [mbOK], 0);
end;

 

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

 

Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post
 |  TrackBack URI for this post

New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,
Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …
Programming AVR ADC module with WinAVR,
Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut …
New on WinARM Tutorial
What are differences between WinARM and WinAVR,
Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …
LPC2000 watchdog timer,
As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount …

One Response to “Control LPT port under windows XP using Delphi”

  1. souhill Says:

    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.
    Souhill

Leave a Reply