size : 3139
uploaded_on : Thu Nov 5 00:00:00 1998
modified_on : Wed Dec 8 14:03:26 1999
title : Sending data to the parallel port
org_filename : DataToPort.txt
author : Carl
authoremail : carlolsen@omax.com
description : How to open the parallel port in Delphi and send data to it?
keywords :
tested : not tested yet
submitted_by : The CKB Crew
submitted_by_email : ckb@netalive.org
uploaded_by : nobody
modified_by : nobody
owner : nobody
lang : plain
file-type : text/plain
category : delphi-system32bit
__END_OF_HEADER__
> How do I open the parallel port in Delphi and send data to it?
I have done this using the assembly language "Out" command, although I think
there might also be a "Port" command that will work as well. Attached is
some example code that I used to controll stepper motors. Basically all you
have to do is a little in-line assembly language like this (untested code):
Procedure SendByteToPort(SendByte:Byte):
begin
asm
{Move the byte to send into the AL register.
(AL is like a variable, so we are really saying
AL:=SendByte)}
Mov Al,SendByte
{Move the address of the parallel port into the DX register.}
Mov DX,3BCH
{Send the contents of AL out the DX parallel port}
Out DX,AL // Send it!
end; // end of assembly language stuff
end; // end of procedure
Note that the address of the parallel port is either 278, 378, or 3BC (all
hexidecimal), depending if you are writing to LPT1, LPT2, or LPT3.
Below is the full code I used to send the pulse to the stepper motor, if you
are interested. I did not test the above code, but I know that the below
code works.
Note: None of this will work under NT, however, because NT will not let you
access the hardware directly. If you are writing for NT, then you will
probably have to write a device driver, which I have no idea how to do.
Note: If you are trying to read the parallel port, then you should probably
be able to use the INP assembly language command. (I think.) Also, I think
that NT will allow you to read the parallel port, just not write to it.
I hope this is helpful, and Good Luck!
- Carl.
Procedure ASMSendByte (SendByte:Byte);
{Sends a byte to the parallel port for the purpose of controlling step &
direction motors}
begin
asm
Mov AL,SendByte {Send Sendbyte into this routine}
AND AL,250 {MASK OFF STEP BITS}
{*** GET READY TO SEND BYTE WITHOUT STEP BITS ***}
MOV DX,3BCH {LOCATION OF LPT3:DATA BYTE}
OUT DX,AL {PUT VALUE PASSED READY TO SEND}
INC DX {LOCATION OF LPTx:STATUS REGISTER}
INC DX {LOCATION OF LPTx:CONTROL REGISTER}
{*** SEND THE BYTE ***}
MOV AL,0DH {CONTROL VALUE FOR STROBE HIGH}
OUT DX,AL {STROBE ON}
MOV AL,0CH {CONTROL VALUE FOR STROBE LOW}
OUT DX,AL {STROBE OFF}
MOV AL,SendByte {RESTORE STEP BITS}
{*** GET READY TO SEND BYTE WITH STEP BITS ***}
MOV DX,3BCH {LOCATION OF LPT3:DATA BYTE}
OUT DX,AL {PUT VALUE PASSED READY TO SEND}
INC DX {LOCATION OF LPTx:STATUS REGISTER}
INC DX {LOCATION OF LPTx:CONTROL REGISTER}
{*** SEND THE BYTE ***}
MOV AL,0DH {CONTROL VALUE FOR STROBE HIGH}
OUT DX,AL {STROBE ON}
MOV AL,0CH {CONTROL VALUE FOR STROBE LOW}
OUT DX,AL {STROBE OFF}
end; {End of Assembly language stuff}
end; {end Procedure ASMSendByte}