Project Basics

Parallel Port

Computers parallel port is generally used to send or receive binary signals while interfacing with the external devices.

We can use switches, micro-controller pins or some IC pins to connect to parallel port.

Pin-out of Parallel port: The parallel port consists of 8 data pins and 4 status pins .We can use data pins as output ports and status as input port.

The data and status pins are normally high. Data pins are latched outputs while status pins are always high, except when a low input is applied and retained.

Pin No (DB25)Signal nameDirectionRegister – bit

Accessing parallel port in MATLAB:

Matlab provides port ID’s to the 3 registers of parallel port namely Data, Status and Control as shown in the following table:

Port IDPinsDescription
02-9Eight I/O lines
110-13 and 15Five inputs for status
21,14,16,17Four I/O lines used for control

The PC supports up to three parallel ports that are assigned the labels LPT1, LPT2, and LPT3. We can use any of these standard ports as long as they use the usual base addresses, which are (in hex) 378, 278, and 3BC, respectively. The port labels and addresses are typically configured through the PC s BIOS. Additional ports, or standard ports not assigned the usual base addresses, are not accessible by the toolbox.

Most PCs that support the MATLAB software will include a single parallel port with label LPT1 and base address 378. There are few steps to access parallel port using matlab:

  • Firstly we need to create a digital Input Output object.

To create a DIO (digital IO) object for parallel port following code is written,

   dio = digitalio('parallel','LPT1'); or dio = digitalio('parallel', 1)
  • Next we add pins which are to be used as output lines, in the above created object.

We add lines to a digital I/O object with the addline function. The function addline requires the device object, at least one hardware line ID, and the direction (input or output) of each added line as input arguments. . For example, to add eight output lines from port 0 to the device object dio created in the preceding section:

        hwlines = addline(dio,0:7,'out');

Sending data to the port:

  • Send the data at the output lines

We have already configured eight data lines as output pins and the data to be sent is stored in the variable named data. Now data can be written as follows



Receiving data from the port:

  • Receive the data from the pins If we configure the eight data lines as input lines                   hwlines = addline(dio,0:7,’in’); and we receive the data as                                       ram = getvalue(dio2.line(1:8));Now the data received gets stored in the variable named ram.
  • Creating a digital Input Output object.

dio2 = digitalio(‘parallel’,’LPT1′);

  • Add pins of status lines, in the above created object inreg = addline(dio2, 0:1, 1, ‘in’);
  • Reading values from status pins.ram=getvalue(dio2.line(1:2));

Leave a Reply

Your email address will not be published.