Вы находитесь на странице: 1из 5

How to use a pc parallel port for monitoring and control purposes Part 1.

Just about all IBM compatible personal computers have a parallel port that you can access via a rear panel connector. The ports original purposes was to provide a printer interface, which is still its most common use. But users and product developers have also learned that the ports eight outputs five inputs and four bi-directional lines are enough for many basic monitoring, control, data transfer and other applications. The result is that the parallel port becomes a popular location into which to plug all kinds of things besides printers. For circuit design and testing, there are parallel-port programmers, voltmeters, oscilloscopes and logic analysers. For portable computers, or any computer that doesnt have an empty expansion slot or drive bay, you can buy parallel-port versions of standard add-ons like tape backup drives, network adapters, joystick interfaces, and even sound systems. Other products include car-engine diagnostic tools and controller and data loggers of all types. Because a parallel-port device plugs into the computers rear panel, you dont have to open the cover of your system unit for installation, and you can easily move whatever device you connect to a different computer when needed. Original parallel port The standard parallel port offers just one of many ways to add user-accessible inputs and outputs to a personal computer. There are dozens of expansion cards with rear-panel connectors that permit access to various combinations of inputs and outputs but the focus here is on the standard parallel port that just about every MS-DOS computer has. The circuitry and connector for the parallel port are usually on an expansion card. Although sometimes, especially in portable computers, the circuits arent complex the expansion card almost always includes additional functions. Some parallel ports are on multifunction cards that include serial and game port. While others are added to disk controllers or display adapters MS-DOS refers to the parallel port as (line printer1), or lpt2 and lpt3 for additional ports. Another name for the parallel Port is printer port. Reflecting its most common use the rear- panel connector (not to be confused With the male 25-pin D-shell connectors used on many serial ports) each parallel port has one of three Possible base addresses in memory 3BCh, 368h, or 278h. You change address bi moving a jumper or running a set up utility some ports permit just one or two of the three addresses and a few let you To choose any uncommitted address, including non-standard ones, look on the card for labelled jumpers, when the computer boots, a BIOS routine look for a port at each of the three addresses in the order listed above. The BIOS determines whether or not a port exists by writing to it and then reading back what it wrote. If the read is successful, the port exists. The first port found is called LPT1, the second LPT2. So LPT1 may be ay any of the base addresses. If exists, LPT2 may be at 378h or 278h, and LPT3 can only be at 278h. The bios routine stores the port addresses in a table 40:8 to 40:F, beginning with LPT1. The top two bytes (for LPT4) are rare used. You can swap printer designations by swapping the values in the table. Therefore, its possible to vary from the original configuration. You might want to do this if a program supports only LPT1 and you printer is on port LPT2. Two hardware interrupts, 5 and 7, are commonly associated with the parallel ports. Some cards allow you to selected an interrupt with a jumper or set up utility, while others are hardwired to a specific interrupt. Conventionally, LPT1 uses interrupt 7 and LPT interrupt 5. However, since on XT-type computers, the hard disk uses interrupt 5, its not available for the parallel port. Although interrupt-driven software is fast, most parallel-port printer drivers dont use interrupts. This is partly due to a problem on the original parallel port and many of its imitators. On these ports, the interrupt-requested line isnt latched. So if the pulse is short, the computer many not see it at all. Table 1 summarizes the signals more or less follow the printer interface popularised by the centronics data computer corporation, although the 25-pin connector doesnt use all of the 36 lines in the original interface. Centronics was an early manufacturer of low-cost

dot-matrix printers, and, although centronics printers are no longer made, the name lives on in the connector, signals and pin-out that the company made popular. Although each signal has names that suggest a particular function, you dont have to use the signals for their intended purposes. For example, you can use the paper-end signal for any type of input, not just to announce that a printer is out of paper. INPUTS AND OUTPUTS.- you can access the parallel port through both MSDOS and the ROM BIOS. Services 00,01 and 02 of bios interrupt 17h enable you send a byte to the printer, Initialise the printer and get printer status. DOS interrupt 21h, function 05, also writes a byte to the printer and function 40h can direct a block of data to a parallel port. But. For full access to all of the port s 17 signals, you need to read add write directly to the port, to do this, you ignore the DOS and bios functions and instead read from and write directly to the ports data, status and control registers. DATA LINES.- data lines D0 through D7 are eight outputs that carry the data to be printed to the printer. For other applications, you can use the data lines as general-purpose outputs. To control de states of pins 2 through 9 on the parallel connector, you just write the desired data to the data register, whose address is the base address of the port. For example, to bring high D$ through D7 and low D0 through D3, youd write F0h to the data register. In BASIC you use the out statement, as Follows: Listing1 is a QuickBasic program that brings each one at a time some parallel ports have bi-directional data lines. Which you can use as inputs as well as outputs later, I'll explain how to determine if you have a bi-directional data port for input. STATUS LINES.- the status lines are five inputs that you read at a status register, which has an address of base address + 1, or 3BCh. The status register is read-only; writing to it has no effect. The five status lines use bits 3 through 7 in register, corresponding to pins 10 through 13 and 15 at the connector. Bits 0, 1 and 2 arent used. To read the status inputs, you read the status port. However, the value you read doesnt exactly match the logic states at the connector , bits3 through 6 read normally the bits in the status register of their corresponding pins bit 7however, contains the complement Of the logic state at pin 11 ( BUSY) .so, to find the actual logic States at the connector you complement or invert bit 7. The Boolean exclusive- OR (XOR) operator is an easy way to invert one or more bits unchanged as the following truth table shows the result of an XOR OPERATION is l only when the inputs consist of one 1 and one 0. To invert selected bits in a bite first a mask byte in which the bits you want to invert are 1s and the bits to ignore are 0s . for example to invert bit 7, the mask bite would be 10000000, or 80h, if you XOR this bite read from the status register, you end up with the actual value at the connector the mask bite gets name because the 0s mask ,or hide the bits you don t want to change. Here s an example this BASIC statement will display the actual logic states at the status port pins, for a port with a base address of 3BCH Listing 2 is a BASIC program that reads the status port and displays the logic state at each of the status inputs CONTROL LINES in addition to the data and status port, the parallel port , you can use its four lines as inputs or outputs, in any combination the control register s address is base address+2, or 3Beh for a port with a base address of 3BCH the four control lines use bits 0 through 3 in the register which correspond to pins 1, 14, 16 and17 on the connector bit four enables the parallel ports HARDWARE interrupt when bit 4 is high a falling edge at status input ACK (PIN 10) generates an interrupt (A few ports interrupt on the rising edge of ACK) to use the interrupt, you must install an interrupt routine that responds to the port, s assigned interrupt. Lf you arent using the interrupt don. T bring high bit 4. 5, 6 and 7in the control ports are unused in most parallel ports. In ports with bi-directional data 5 or 7 may has inverted bits. At the connector bits 0, 1 and 3 are the complements, of their logic states In the control register only bit 2 reads normally . so if you write 0Fh to the control register. You actually write 04h to the connector to make the value you write match the result at the connector XOR the value with 0Bh (00001011), as this example shows: listing 3 is a BASIC program that brings high each of the control ports bits in turn, you

can also use the control lines as inputs were 7405 open-collector inverters with 4,700ohm pull-up resistors. The outputs also connect to input buffers, when the open-collector outputs are high you can drive the input buffers with other digital out puts in newer port designs, the components vary but the port should retain the ability to use a control bit as input when the output is high, figure2 shows the difference between open collector outputs and the other common type of output, the totem-pole at an open-collector output, a low output causes the output transistor to conduct, creating a low resistance from the output pin to ground. A high output requires a pull-up resistor to bring the output to a valid logic-high level if you connect a high output to ground current flows through the pull-up resistor but with a 4,700-phm resistor its just a little over 14 mA. This is why you can tie together two or more open-collector outputs, and any low will bring low the combined output. This is often called a wired- OR gate, although in positive logic (high=1 and low =0), the outputs form an AND gate, with any low output bringing low the combined output the outputs of some NMOS and CMOS devices are similar to open- collector in this way. They have on-chip pull-up devices, and writing a 1 to an output allows you to use it as input. The ports on the 8051 and 80C51 micro controllers are examples of this type of output. In contrast to open-collector, most LSTTL devices have a different type of output, called totem pole, with two transistors stacked one above the other totem pole style. When the output is low, the lower output transistor conducts, similar to an open-collector output. But when the output is high, the upper transistor conducts, creating a low-resistance path to +5 volts. If you tie together two totem-pole outputs, when one is high and the other is low, you end up with a lot of current in the output transistors as they battle for control. The resulting logic level is unpredictable. More importantly, the currents may destroy the components. Outputs on most digital CMOS devises have complementary outputs that are similar to totem-pole if you tie a totem-pole output, to an open-collector output, stays high if it goes low and the totem-pole output is high, you end up with the same battle for control and excess currents. So to prevent problems, use open-collector outputs to drive the control inputs to bring high all four of the control ports outputs to use the bits for input, write 04 to the control register: because bits 0, 1 and 3 are inverted at the connector, you write 04, not of, to bring bits 0 through 3 high. To read the control inputs, you the read the control register with: the value read has bits 0, and 3 inverted from their logic states at the connector. To re-invert 0, 1 and 3 and display the actual value at the connector, use this statement: Listing 4 is BASIC programs that reads the control port and display the logic state at each of the control inputs. BIDIRECTIONAL DATA PORTS if you need eight bits of input, you can combine inputs from the status and control ports t achieve a byte of input data. For some applications, though, It would be convenient to use the data port as an eight-bit input and some-times you can do just this. In older PCs, and many newer ones, the data port is designed for only output. In the original design, the data outputs were driven bi a 74 ls 347 octal flip-flop. The data pins also connect to an input buffer, but reading the buffer tells you only the last value written to the outputs. (The input buffer is what enables you to test for the existence of the port bi writing to it and then reading back what you wrote.) But because theres no way to turn off the outputs, you can t read external signals at the data port. In fact, connecting outputs to the data port may destroy the port? S circuits. Beginning with its PS/2 model in 1987, IBM began to offer a bi-directional parallel port, the data lines of which can function as inputs as well as outputs. Other computer vendors have also added bi-directional ports. For example, computers that use Intels 386SL or 486SL superset have an l/0 subsystem chip that includes a bi-directional parallel port typically, to use a bi-directional port input, you must first run A set-up program or move a jumper to configure the port fur bi-directional operation. You then select input or output by setting or clearing a bit in the control register-usually bit 5, but some ports use bit 7. If your computer doesnt` t have a bi-directional port you can get one by adding an inexpensive expansion card. Essential data carries several, including STB`S DSP550 ($379), with one parallel port and two high-speed serial ports. Other suppliers have similar products, but many cards and computers, even newer ones, still dont have bi-directional data lines also, because all parallel ports have status and control inputs, any vendor can call its ports bi-directional even if the eight-bit data port is output-only so be sure you know what you` re buying, or that you can return the card if it

doesnt do what you need. For the adventurous, its possible to use some output-only data ports for input. On some ports you can bring high the data outputs and drive the input buffer with an external signal, much as you do on the control port. If you make a mistake, and maximum speed may be less than that 0f a true bi-directional port. This said, to under-stand how to use an output port for input, you need to examine the circuits involved. Although it` s convenient to think of digital logic as a collection of logic gates that respond perfectly to their inputs, sometimes it ` s necessary to see what is actually driving the circuits. On the original parallel port, a 74LS374 provided the data outputs. These days, there's no telling exactly what `s connected to the port pins. In researching this article, l examined several parallel ports of different vintages. One older card did, use a 74LS374 to drive the data port and other common DIP IC s for the status and control lines. On another card, a single 100-lead surface-mount chip contained almost all of the circuits needed to control the parallel port and a monochrome display adapter. MY guess is that the chip is an ASIC (application-specific IC) Designed for the expansion card. On a third card let the parallel port and other circuits were controlled by a 68-lead LCC (leaded chip carrier) with the designation HM83C452. A crystal to two the leads, which makes me suspect that the chip is a micro controller of some type. Since Philips 83C451 is a version of the 80C51microcontrollerin a 68-lead LCC, perhaps the 83C452 is a similar chip. At any rate, The actual components that control the parallel port vary widely to use. An output-only` data port input, you must have outputs that use open-collector or a similar design. You cant use totem-pole outputs like the 74LS374s. if you have a schematic diagram of your port, you can use it to find out whats driving your data outputs. If they use a 74LS374, you can t use the data port for input, unless you modify the circuits as described below. For other components, if the part number is recognizable, you can consult data book for details about the chip. Alternatively, you can perform the following tests: first write FFh to the voltages at pins 2 through 9. If you measure less than 4.5 volts, the are probably totem pole, and the isnt suitable for input. If you measure close to +5 volts, connect a 1,000-ohm pull-down resistor from output to ground. If the output voltage drops by 0.5 volt or more, the output is probably open-collector or similar. This means that you can use the data port for input by writing FF to the data port and then driving the input buffer with a 7406 or another strong open-collector driver, reading the data port should then tell you the logic states at the external drivers Outputs. See the December 1992 COMPUTERCRAFT for more details on this method, including how to connect two computers for bi-directional transfer. (Back issues of computer craft are available for $3.50 each from MICRO COMPUTER JOURNAL.) If you have a card that uses a 74LS374 for the data outputs, you can make the port bidirectional by modifying the circuits. Although buying a card with A true bi-directional port is easier, quicker and economical, the following are two options for the determined: (1) make and add a small daughter-board that replaces the 74LS374 with 7407s or another open-collector device with pull-up resistors. The July 1993 ISSUE of Computer Craft has details on this (2) control the 74LS374s outputs by cutting the ground connection at the 74LS374s OE (output-enable line) at pin 1 and tying pin 1 to one of the parallel ports control outputs. This control bit then determines the ports direction, where 0 enables the data outputs for an output and allows you to use the data port for input. SPEED How fast can? The answer depends on the speed of your computer and the speed of your software, which depends on both the programming language and the program you write using assembly language, you can read the parallel port and store the value from memory to the port, using just a few instructions. However, most real-world applications involve more than these basic operations, and any processing or calculations on the data will slow the transfer rate. Using BASIC, C or any compiled or interpreted programming language will also slow things. As a very general rule its possible to achieve transfer rates of 40K to 80K bites second on fast computers, and 10K to 15K bytes per second on an 8-MHz machine. Some newer port designs, including the enhanced parallel port in Intels SLSL chipset, and ports that follow the IEEE's new 1284 standard, can transfer data at IM byte per second. Some network adapters and other parallel-port devices use these faster methods When they detect a high-speed port PARALLEL-PORT CABLES

For experimenting with a parallel port, you need a cable that permits easy access to the signal lines. Standard printer cables typically have a male 25-contac D-shell connector on the computer end and a male 36- contact Centronics connector on the printer end (with 11 contacts that arent used). Therefore One solution is to use a standard printer cable and wire a 36-contact female centronics connector to Your circuits. If you want to use a different type of cable or connector, for best results, there are some things to be aware of. In an ideal cable, the signal at an input exactly matches the output that drives it. In reality, as signals travel along a cable, they degrade and pick up noise due to the conductors resistance, cross talk from adjacent conductors, reflected signal, poor grounding and other problems. Unlike the RS-232 serial interface, which can use cables of 100 feet and longer without problems, parallel- port circuits arent t designed for data transfers over long distances. This is why parallel cables are typically 15 feet or less in length. There are some things you can do to minimize problems in parallel links, however. Metal shielding blocks radio-frequency (rf) interference and also prevents capacitive coupling Between conductors on opposite sides of the shielded with toil or other metal covering around the conductor bundle for the length of the cable. On some moulded cables, shielding extends to the connectors shielding does nothing to prevent magnetic, or inductive, coupling between conductors in the cable, however and this can be a bigger problem a simple way to minimize magnetic coupling is to use twisted-pair cable in which each conductor is paired with another and the conductors in each pair wind around each other with a full twist every inch or two. Ideally, in a twisted-pair cable, each signal conductor is paired with a full twist every inch or two. Ideally, in a twisted- pair cable, each signal conductor is paired with a ground conductor that provides a return path. This minimizes the area of the current formed by the signal and return conductors, which, in turn, reduces the ability of signals to magnetically couple into adjacent conductors also, twisting causes noise that` s picked up in one twist to tend to cancel in the next. Unfortunately, the parallel-port connector doesn`t have sufficient pins to give each of the 17 signal, its own ground return. You do get eight groungd pins, though. So, as a last resort, oycould tie two conductors to a pin ordinary ribbon cable doesn`t have twisted pairs, but the groung conductors in the cable alternate with D3 through D7 and the four status lines. This helps to reduce noise. You can also buy twisted-pair ribbon cable, which has 18 sections of twisted pairs alternating with 2 flat untwisted sections to permit crimpring IDCs (insulation-displacement connectors) digi-kei is one source for these if you use a cable with D shell connectors On both ends, be sure that the cable contains 25 conductors. Many serial cables use 25pin D-shell connectors, but the cables themselves have 10 or fewer conductors. CONNECTORS If you want to use a solderless breadboard or perforated boar that has holes on 0.12 centers, the pin spacing on a Centronics or D-shell connector does` t match. A few perforated boards have pads intended for a D-shell connector. If oyu have one of these, you can use a pc-board-mount connector , or you can use a solder-cup D-shell connector and solder individual conductors to it. For use with boar, anther option is to use a 25-connductor ribbon cable with a male D-shell connector on one end and a DIP connector on the other the DIP IC connector has two rows of pins with the sama spacing as a DIP IC. The ribbon cable slides under the connectors` s cover and crimps onto the tops of the pins. The connector then plugs into a breadboard, perforated board or IC socket, permitting easy access to all of the port` s lines. Hand-held IDC tools are available for crimping onto ribbon cable. Or you can just use a vise to press the cable onto the contacts another option for use with perforated board is a ribbon cable that has a dual-row socket connector that plugs into a dual header. Digi-key is one of many sources for connectors.

Вам также может понравиться