Parallel Port Programming: QBasic

Getting Started

QBasic is perhaps the easiest language to program the parallel port with. Almost everyone with a PC should have access to QBasic. If you don't have it on your computer, it can be found on the Windows 98 CD in x:\tools\oldmsdos\. There are two files that need to be copied: qbasic.exe and qbasic.hlp.

The Code

The command for sending data to the parallel port in QBasic is OUT. The format is

OUT port, value

Since the parallel port is often at 378 hex, that is the value that I use in my code. The following program allows a user to enter a value in decimal that is sent out the parallel port.

DIM outval
outval = 0

WHILE outval < 256

  INPUT "Enter a value (256 to quit) >", outval

  OUT &H378, outval
 
WEND


Explanation

The program defines a variable, outval. outval is assigned the value of 0. A loop is defined that runs as long as outval is less than 256. I chose 256 because the parallel port is an 8-bit output, and with 8 bits only 0 to 255 can be represented. The next statement takes an input from the user and stores it in outval. Next the OUT statement writes outval to the parallel port. Very simple.