DPRG
DPRG List  



[DPRG] Changing Printer Ports in C++

Subject: [DPRG] Changing Printer Ports in C++
From: Randy Carter rwcarter at foxinternet.net
Date: Mon Sep 1 15:44:01 CDT 2003

The answer you want is in the file LCD_DUAL.C provided on the JK 
Micro Systems CD.  First you load the proper TSR program at the 
DOS prompt then use the the example in the file.

Bill Boyer wrote:

> I'm messing with a 386ex single-board computer and a 4 x 40 LCD and I
> need to be able to write to LPT2 to get the second two rows of the
> display working. I know stdprn is LPT1, but what is the easiest way to
> access LPT2? This is using Borland C++ 4.52.
> 
> FYI -- they have a single 10-pin header set up to drive two LCD's in
> 4-bit mode by sending output to LPT1 or LPT2. They share all but the
> enable line, which is used to determine which LCD you want. 
> 
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at dprg.org
> http://nimon.ncc.com/mailman/listinfo/dprglist
> 
-------------- next part --------------
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <bios.h>
#include <dos.h>

#define LCD_CMD 160			/* command for LCD driver */
#define LCD_CMD1 40         /* i/o format setup command */
#define LCD_CMD2 6          /* cursor setup command */
#define LCD_CMD3 6          /* cursor setup command */

#define CLR_HOME 1          /* clear and home command */

#define LPT_INT		0x17    /* BIOS LCD Function */
#define LCD1		0       /* printer interface number */
#define LCD2		1

int lcd_out( char * lcd_string, int lcd) {
	union REGS regs;

	regs.h.ah = 0;  /* func 0, write to LPT */
	regs.h.dh = 0;
	regs.h.dl = lcd;

	while ( *lcd_string != NULL) {
		regs.h.al = *lcd_string++;		/* load register w/ character to output */
		int86(LPT_INT, &regs, &regs);	/* send it to the BIOS */
	}

	return regs.h.ah;		/* return status */
}


void main(void)
{
	time_t 			sec_now, sec_prev=0;	/* time in seconde, 2 copies */
	struct 	tm 		*tm_now;                /* time/date structure */
	unsigned char	lcd_pos=0xC5;       	/* demo position w/ variable */
	char 			c;
	char			lcd[30];					/* string to buffer lcd data */

	sprintf(lcd,"%c%c",LCD_CMD,40);         /* with decimal commands */
	lcd_out( lcd, LCD1 );
	lcd_out( lcd, LCD2 );

	sprintf(lcd,"%c%c",LCD_CMD,0xC);        /* with hex commands */
	lcd_out( lcd, LCD1 );
	lcd_out( lcd, LCD2 );

	sprintf(lcd,"%c%c",LCD_CMD,LCD_CMD2);	/* with defined commands */
	lcd_out( lcd, LCD1 );
	lcd_out( lcd, LCD2 );

	sprintf(lcd,"%c%c",LCD_CMD,CLR_HOME);
	lcd_out( lcd, LCD1 );
	lcd_out( lcd, LCD2 );

	sprintf(lcd,"LCD1" );
	lcd_out( lcd, LCD1 );
	sprintf(lcd,"LCD2");
	lcd_out( lcd, LCD2 );

	while ( 1 ) {              						/* loop until key hit */
		if ( kbhit() ) {
			if ( (c=getch()) == ' ' ) break;
			sprintf(lcd,"%c%c" ,LCD_CMD,0xD4);		/* position cursor */
			lcd_out( lcd, LCD1 );
			sprintf(lcd,"%c",c);			        /* print character */
			lcd_out( lcd, LCD1 );
		}
		time(&sec_now);                 		/* get time in (sec since whenever) */
		if (sec_now != sec_prev) {      		/* see if new time */
			sec_prev=sec_now;
			tm_now=localtime(&sec_now);			/* convert seconds to string */

			sprintf(lcd,"%c%c", LCD_CMD, lcd_pos);	/* position cursor */
			lcd_out( lcd, LCD1 );
			lcd_out( lcd, LCD2 );
			sprintf(lcd,"%02d-%02d-%04d",        	/* print date */
				(tm_now->tm_mon+1), tm_now->tm_mday, tm_now->tm_year + 1900);
			lcd_out( lcd, LCD1 );
			lcd_out( lcd, LCD2 );
			sprintf(lcd,"%c%c", LCD_CMD,0x9A);   	/* position cursor */
			lcd_out( lcd, LCD1 );
			lcd_out( lcd, LCD2 );
			sprintf(lcd,"%02d:%02d:%02d",           /* print time */
				tm_now->tm_hour, tm_now->tm_min,	tm_now->tm_sec);
			lcd_out( lcd, LCD1 );
			lcd_out( lcd, LCD2 );
		}
	}


	/* done */
	return;
}

More information about the DPRG mailing list