I/O Port Access in Microsoft Visual C++
I/O Port Access in Microsoft Visual C++
I/O Port Access in Microsoft Visual C++
Microsoft Visual C/C++ provides access to the I/O ports on the 80x86 CPU via the predefined
functions _inp / _inpw and _outp / _outpw.
int _inp(unsigned portid); /* returns a byte read from the I/O port
portid */
unsigned _inpw(unsigned portid); /* returns a word read from the I/O port
portid */
int _outp(unsigned portid, /* writes the byte value to the I/O port
portid */
int value); /* returns the data actually written
*/
unsigned _outpw(unsigned portid, /* writes the word value to the I/O port
portid */
unsigned value); /* returns the data actually written
*/
---###---
IBM-PC Parallel Printer Port Female DB-25 Socket external Pin layout
______________________________________________________
/ \
\ 13 12 11 10 9 8 7 6 5 4 3 2 1 /
\ /
\ 25 24 23 22 21 20 19 18 17 16 15 14 /
\________________________________________________/
So it's also the Pin layout on the solder side of the Male DB-25 Cable Connector that plugs into it
---###---
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.
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.
Bit 7 6 5 4 ~3 2 ~1 ~0
Pin - - - IRQ 17 16 14 1
enable
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.
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.
If an external device should be driving data on these pins (in violation of usage groundrules) at
the time of an input, this data will be ORed with the latch contents.
This command presents realtime status to the processor from the pins as follows.
Bit 7 6 5 4 3 2 1 0
Pin 11 10 12 13 15 - - -
Input from address 27A/37A/3BE Hex
This instruction 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. If external drivers are dotted to these pins, that data will
be ORed with data applied to the pins by the output latch.
Bit 7 6 5 4 3 2 1 0
Pin - - - IRQ ~17 16 ~14 ~1
enable
---###---