DPRG List  

[DPRG] Changing Printer Ports in C++

Subject: [DPRG] Changing Printer Ports in C++
From: Bill Boyer daweasel at swbell.net
Date: Sun Aug 31 16:41:00 CDT 2003

Let me re-explain so you guys don't get all wound up with memory maps
and Visual C++.

This is on a JK Micro Flashlite 386ex single-board computer running XDOS
3.3c from an EPROM and Borland C++ 4.52 code compiled on a PC and
uploaded as a .exe to the 386ex board via a terminal program.

The board has a single 10-pin dual-row header for connecting one or two
HD44780-compatible LCD displays. A TSR program they furnish redirects
requests to LPT1 and LPT2 to this connector in a format usable by the

If you have two LCD's connected, they share all the data lines except
the E (enable) line. E1 is used if you want to write to the LCD as LPT1,
and E2 is used to write to the LCD as LPT2.

With a 4x40 LCD (Tanner's special, $10) you physically have one 4x40
display, but electrically it is two complete separate 2x40 displays /
chipsets that are written to individually. Hence the need to be able to
write to LPT1 and LPT2 with the same program.

So far, the LCD powers up, the TSR runs, and the code below will
initialize a 2x16 or half of a 4x4 LCD and display characters properly.

The problem is writing to LPT2 so I can use the other half of the


#include <stdio.h>

int main()
	printf("Hello, world\n");
	fprintf(stdprn,"\xA0\x28");		/* set display to 4-bit, 2 lines, 5x7 char
	fprintf(stdprn,"\xA0\x0C");	   /* display on, cursor off, blink
off       */
	fprintf(stdprn,"\xA0\x06");		/* increment cursor, no display shift     
	fprintf(stdprn,"\xA0\x01");		/* clear and home display                 


	return 0;


> You can't write directly to non memory mapped I/O ports in "normal" C or
> C++. You need a helper routine written in assembler.
> Most run time libraries provide routines named something like inport()
> and outport() which do the work for you. Sometimes they'll be called
> _inport _outport or _inp and _outp.
> In Visual C++ 6.0 they're called _inp and _outp and they can be found in
> conio.h

> > > You still haven't answered my question though -- how can I directly 
> > > write to LPT2 in C++? One reference book mentioned using a file 
> > > pointer and the FOPEN statement, but it did not seem to 
> > work properly 
> > > for either port, although an FPRINTF to STDPRN worked fine.
> > 
> > Sorry, I have no idea how you'd do that in C++.  Any 
> > low-level C++ gurus lurking out there?
> > 
> > The only possible thing I could think of would be to open 
> > another file for LPT2 and then overwrite stdprn with the new 
> > file handle.  I don't even know if that would work.

More information about the DPRG mailing list