Parallelport programming in DOS

Parallelport programming in DOS

The following examples are short code examples how to write to I/O ports using different languages. In the examples I have used I/O address 378h which is one of the addresses where parallel port can be.

The typical parallel port I/O addess configurations seen on PCs with ISA bus:

  • LPT1: 3BCh, LPT2: 378h, LPT3: 278h
  • LPT1: 378h, LPT2: 278h
  • LPT1: 378h

Those are the typical I/O addresses used in ISA bus based systems. In PCI bus based systems the LPT1 port on motherboard is typically at I/O-address 378h or 3BCh. If the systems has extra LPT ports on multi-IO card in PCI bus, those extra LPT ports work differently than the “normal parallel port” described in this document, and the same control methods can’t be applied to them (they are on different I/O addresses and could use different control register system that could be card specific, the driver software that comes with the card makes them to look like LPT ports for the applications using standard operating system printing routines).

The following examples are for DOS system (they might or might not work on other systems). The code examples are designed to be used with LPT1 port that resides in I/O address 378h.

Assembler

MOV DX,0378H
MOV AL,n
OUT DX,AL

Where n is the data you want to output.

BASIC

OUT &H378, N

Where N is the number you want to output.

C

 
outp(0x378,n);

or

outportb(0x378,n);

Where N is the data you want to output. The actual I/O port controlling command varies from compiler to compiler because it is not part of standardized C libraries.

Here is an example source code for Borland C++ 3.1 compiler:

#include <stdio.h>
#include <dos.h>
#include <conio.h>

/********************************************/
/*This program set the parallel port outputs*/
/********************************************/

void main (void)
{
clrscr();             /* clear screen */
outportb(0x378,0xff); /* output the data to parallel port */
getch();              /* wait for keypress before exiting */
}

Using DOS debug to access parallel port

DOS program Debug is a simple 8088 assembler that comes with DOS operating system (comes with DOS utilities on most modern WIndowssystems as well). Debug allows debugging of simple 16-bit DOS applications (not useful to modern 32-bit Windows programs). Debug program has several built-in debugging tool commands, including commands to read and write I/O ports.
o- writes one byte of dat to the specified I/O port
SYNTAX o port value
port - specifies the port address. The port address can be an 8 or a 16 bit value.
value - specified the value to write to this I/O-port. This value is 8 bit value.

i- reads one byte of data from the specified I/O port
SYNTAX i port
port - specifies the port address. The port address can be an 8 or a 16 bit value.

Examples:

If you type 

o 3bc ff

debug will output value ff (hex) to port 3bc (hex).

If you type

i 3bc

debug will display 1 byte of data from the parallel port.
Programming I/O

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: