Delphi control parallel Port bit operation

Source: Internet
Author: User

Parallel port for short, it has 3 ports: Data port, State port, control port, commonly used and port is LPT1, its 3 ports address are: 378H, 379H and 37AH respectively.

First, the same mouth read and write

In assembly language, you can use in and out instructions to operate with the mouth, and there is no corresponding function in Delphi, the method can be read and written to the parallel port, fortunately Delphi can be embedded assembler program, through the direct embedding assembly instructions in and out can easily read and write to the parallel port. We can also access the port by invoking Windows API functions or third-party-supplied DLLs and VxD, but it is more convenient and quicker to read and write to the same port by using the embedded assembly method.

Use the following Readport function and the Writeport procedure to read and write the interface, and the parameter port is the port address to be manipulated.

function ReadPort(Port:WORD):BYTE;
var
B:BYTE;
begin
ASM
MOV DX, Port;
IN AL, DX;
MOV B, AL;
END;
Result:=B;
end;
procedure WritePort(Port:WORD;ConByte:BYTE);
begin
ASM
MOV DX, Port;
MOV AL, ConByte;
OUT DX, AL;
END;
end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.