Basic information about parallel port programming
Please note: We use the conventional trailing h to indicate a hexadecimal number.
|Signal name||Register bit||SUB-D||Centronics|
|Data bit 0||D0||2||19||2||20|
|Data bit 1||D1||3||19||3||21|
|Data bit 2||D2||4||20||4||22|
|Data bit 3||D3||5||20||5||23|
|Data bit 4||D4||6||21||6||24|
|Data bit 5||D5||7||21||7||25|
|Data bit 6||D6||8||22||8||26|
|Data bit 7||D7||9||22||9||27|
The most parallel ports are located at a base address of 378h, 278h, or 3BCh. To find the base address of a parallel port in Windows 95, open the "Control panel", then click on "System", "Device manager", "Ports", select an LPT port, then click the "Resources" tab. The addresses of installed parallel ports are also displayed in the CMOS setup screens that you can access when you boot your computer.
In Visual BASIC you have to use a DLL to access the ports. Jan Axelson programmed two DLLs which allow you to use the QBASIC INP and OUT instructions. You can download the DLLs at http://www.lvr.com. Inpout16.dll is for use with 16-bit programs, and Inpout32.dll is for use with 32-bit programs. Although the program code to call the Inp and Out routines is identical for both types, each requires a different DLL and declarations.
Instructions to read and write to the port
Read instruction: xx=INP(address)
Write insruction: OUT(address),xx
You can write to the data port (D0-D7) at the base address. D0 is the least significant bit and D7 is the most significant bit. For example "OUT(889),85" writes 01010101(=85 decimal)to the port address 378h (= 889 decimal).
You can read the status port (S3-S7) at the base address+1. At Bit 7(S7) you will read the inverted signal of the connector. S0 - S2 are usually not in use and read as low signals. When all signals are high you will read 78h (01111000 = 120decimal = 78h).
You can write to the control port (C0-C3) at base address+2. The bits 0,1 and 3 are inverted so if you write 04h (00000100), all four bits will be going high and when you write 0Bh (00001011) all four bits will be going low.
Do you want to learn more about the parallel port?
Then take a look at Jan Axelson´s book: Parallel Port Complete. -Highly recommended!