The following material was collected from several places, including some websites around, some text was changed, some still exactly the same as copied, with the only intention to spread knowledge about this subject.  I thank you Mr. Ian Harries from who I got great part of this material. The PC programs supplied here was produced by myself and it is free for distribution, as well it can be changed or updatet.  To use commercially any of those programs you need to contact me first.
prev update:  February 25 1999 (some files address for download, see the end of this text)
last update:  March 30, 2000
 
  PC PARALLEL PORT

The printer adapter responds to five I/O instructions: two output and three input.

The output instructions transfer data into two latches whose outputs are presented on the pins of a 25-pin D-type female connector.

Two of the three input instructions allow the processor to read back the contents of the two latches.
The third allows the processor to read the realtime status of a group of pins on the connector.

A description of each instruction follows
 
 

Output to address 278 / 378 / 3BC
Bit
7
6
5
4
3
2
1
0
Pin
9
8
7
6
5
4
3
2

The instruction captures data from the data bus and is present on the respective pins. These pins are each capable of sourcing 2.6 mA and sinking 24 mA. It is essential that the external device not try to pull these lines to ground.
 

 Output to address  27A / 37A / 3BE 
Bit
7
6
5
4
~3
2
~1
~0
Pin
-
-
-
IRQ
Enable
17
16
14
1

This instruction causes the latch to capture the least significant bits of the data bus. The four least significant bits present their outputs, or inverted versions of their outputs, to the respective pins shown above. If bit 4 is written as 1, the card will interrupt the processor on the condition that pin 10 transitions high to low.

These pins are driven by open collector drivers pulled to +5 Vdc through 4.7 k-ohm resistors. They can each sink approximately 7 mA and maintain 0.8 volts down-level.
 

  Input from address    278 / 378 / 3BC

This command presents the processor with data present on the pins associated with the corresponding output address. This should normally reflect the exact value that was last written.

The following command presents realtime status to the processor from the pins as follows.
 
 
 

 Input from address 279 / 379 / 3BD 
Bit 
7
6
5
4
3
2
1
0
 Pin 
~11
10
12
13
15
-
-
-

The following command causes the data present on pins 1, 14, 16, 17 and the IRQ bit to be read by the processor. In the absence of external drive applied to these pins, data read by the processor will exactly match data last written to the corresponding output address in the same bit positions. Note that data bits 0-2 are not included.
 

Input from address 27A/37A/3BE Hex
Bit
7
6
5
4
3
2
1
0
Pin
-
-
-
IRQ
Enable
~17
16
~14
~1
The state of those bits after processor reset
 -  -  -
0
1
0
1
1

The following table shows a typical I/O port, address 278, 378 or 3BC, which is the "base address" for the data transfered itself (Data Register), the next byte is the Status Register and the next is the Control Register.  So, the Control Register for the LPT1 (378) is the hexadecimal 37A.
 
 

  PC Parallel Port Registers - Addresses and Bits
Register
7
6
5
4
3
2
1
0
I/O Port
Data
~x
 x
 x
 x
x
 x
x
x
Base  278-378-3BC
Status
x
x
x
 x
x
-
-
-
Base + 1
Control
-
-
-
-
~x
x
~x
~x
Base + 2
Note:  ~ signal means inverted level




The following figure is the actual circuit descriptions and pin numbers for both sides of the cable, along with the data flow indicated by the arrow.  The - (minus) symbol in from of the circuit name means that circuit is "active" with low level.  The ~(tilt) symbol means the circuit works inverted, as a way to accomodate technical situations.
 
 



 

PC  Parallel  Port  LPTx  Pinout

Signal Name    Bit     Pin   Direction
===========    ========  =====   =========
-Strobe         ~C0        1      Output
+Data Bit 0      D0        2      Output
+Data Bit 1      D1        3      Output
+Data Bit 2      D2        4      Output
+Data Bit 3      D3        5      Output
+Data Bit 4      D4        6      Output
+Data Bit 5      D5        7      Output
+Data Bit 6      D6        8      Output
+Data Bit 7      D7        9      Output
-Acknowledge     S6       10       Input
+Busy           ~S7       11       Input
+Paper End       S5       12       Input
+Select In       S4       13       Input
-Auto Feed      ~C1       14      Output
-Error           S3       15       Input
-Initialize      C2       16      Output
-Select         ~C3       17      Output
Ground           -      18-25       -

 

So, any PC Program that can write or read to the physical hardware port addresses is able to communicate with the external world, thus a microcontroller, and this is exactly what we will do as the following in this chapter.

We will explore a little bit about PC DOS programs, since it was my arena from years ago.  There are several other ways to explore this communication programs via other languages as Basic, C, Pascal, Visual Basic, Windows, but we will go directly to assembler language so we can see exactly what it is doing.

I already developed a PC DOS program that "dumps" a disk file contents to the PC COM port.  You select the file, the speed and the COM port, and the program just "pour" it there.  Your microcontroller can capture the data and do whatever you want.  There is no handshake control in this situation, so the PC will never know if something is receiving the data.  Click here to download it: COPY2COM.EXE.

Another nice program I made was the COM2FILE.EXE , an utility for PC DOS, that can capture bytes arriving serially at the COM port and write them in a file.  By using it, your microcontroller can send bytes to the COM port, to be written at the PC hard disk.  You specify the filename, which COM port to use and its speed.  It finishes the reception and write the file, upon pressing any PC keyboard key or after receives 48kbytes of data.

Later in this chapter you will be able to download a PC DOS inteligent program, we can name it "The Dispatcher".  It will take actions based on commands received from the microcontroller, as well send commands to it.  The main idea is that you can control the microcontroller remotely, even by phone, or vice-versa, controlling the PC based on the microcontroller decisions.
 

to be continued...ttp://www.doc.ic.ac.uk/~ih/doc/par/doc/regpins.html [an error occurred while processing this directive]