Tuesday, July 5, 2011

Basic Tips in parallel port interfacing

Parallel port is a uncomplicated and economical tool for building computer controlled devices and projects. The plainness and ease of programming makes parallel port popular in electronics leisure pursuit’s. The parallel port is often used in Computer manipulate robots, Zilog/PIC programmers, home power load automation, ...etc... Here a simple tutorial on parallel port interfacing and programming with some examples.
           each one knows what is parallel port, where it can be found, and for what it is being used. the primary use of parallel port is to attach printers to computer and is derictly designed for this purpose. Thus it is often called as printer Port or Centronics port (this name came from a well-liked printer manufacturing company 'Centronics' who devised some standards for parallel port). You can see the parallel port connector in the rear panel of your PC. It is a 25 pin female (DB25) connector (to which printer is connected). On almost all the PCs only one parallel port is present, but you can affix more by buying and inserting ISA/PCI parallel port cards.
           


Below is a table of the "Pin Outs" of the D-Type 25 Pin connector and the Centronics 34 Pin connector. The D-Type 25 pin connector is the most common connector found on the Parallel Port of the computer, while the Centronics Connector is commonly found on printers. The IEEE 1284 standard however specifies 3 different connectors for use with the Parallel Port. The first one, 1284 Type A is the D-Type 25 connector found on the back of most computers. The 2nd is the 1284 Type B which is the 36 pin Centronics Connector found on most printers.
IEEE 1284 Type C however, is a 36 conductor connector like the Centronics, but smaller. This connector is claimed to have a better clip latch, better electrical properties and is easier to assemble. It also contains two more pins for signals which can be used to see whether the other device connected, has power. 1284 Type C connectors are recommended for new designs, so we can look forward on seeing these new connectors in the near future.
Pin No (D-Type 25)
Pin No (Centronics)
SPP Signal
Direction In/out
Register
Hardware Inverted
1
1
nStrobe
In/Out
Control
Yes
2
2
Data 0
Out
Data

3
3
Data 1
Out
Data

4
4
Data 2
Out
Data

5
5
Data 3
Out
Data

6
6
Data 4
Out
Data

7
7
Data 5
Out
Data

8
8
Data 6
Out
Data

9
9
Data 7
Out
Data

10
10
nAck
In
Status

11
11
Busy
In
Status
Yes
12
12
Paper-Out / Paper-End
In
Status

13
13
Select
In
Status

14
14
nAuto-Linefeed
In/Out
Control
Yes
15
32
nError / nFault
In
Status

16
31
nInitialize
In/Out
Control

17
36
nSelect-Printer / nSelect-In
In/Out
Control
Yes
18 - 25
19-30
Ground
Gnd


Table 1. Pin Assignments of the D-Type 25 pin Parallel Port Connector.

Now that we have that finished with, let's get to the port. The parallel port is made up of three different sections. These are the data lines, control lines and status lines. There are 8 data lines, and they are the primary means of getting information out of the port. In simple projects, you will be concentrating mostly on the data lines. The control lines are another 4 outputs. They are meant to provide control signals to the printer (such as form feed or initialize). The status lines are a standard parallel port's only inputs. There are 5 of them. They were meant to allow the printer to communicate things such as error, paper out and busy to the PC.
Each section is accessed by it's own address and will act independently from the rest. This is almost as if they were different ports. The addresses are as follows:
Port
Address (Decimal)
Address (Hex)
Data Lines
888
378h
Control Lines
890
37Ah
Status Lines
889
379h
You need to know the address of the port you want to use. You will also need two other things; the command to access the port and the number you want to set it to. The command will be explained in a little while. The ports work with numbers. These can be expressed in hex, binary or decimal, but for this document all values will be expressed in decimal. It's just easier that way. Anyway, you operate the port by sending it a number that represents the binary pattern of the physical outputs on the port. For example, to set the 8 data lines to 11111111, you would send 255. To set them to 00000000 you would send 0. Note that these are all 8 bit binary numbers, and the port is also 8 outputs. Coincidence? I think not.
Before we can use any of the functions contained within either DLL, we must declare them. These declarations are to be placed in any module in your program in the General_Declarations section.
For 16bit VB (VBASM.DLL), use:
Declare Function vbInp Lib "VBASM.DLL" (ByVal nPort As Integer) As Integer
Declare Sub vbOut Lib "VBASM.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
For 32bit VB (WIN95IO.DLL), use:
Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)
Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
Once you declare the functions, you will have two new commands available. These are vbInp and vbOut. vbOut is a statement and is used to send a bit to a port, like the following:
You can download  the parmon application for you to monitor every single bit you send or get  while you practice programming in visual basic http://www.brothersoft.com/parallel-port-monitor-11878.html