📄 giaotiep lpt.htm
字号:
7 D5 8 D6 9 D7</PRE>Pins 18,19,20,21,22,23,24 and 25 are all ground pins.<P>Those datapins are TTL level output pins. This means that theyput out ideally 0V when they are in low logic level (0) and +5V when theyare in high logic level (1). In real world the voltages can be somethingdifferent from ideal when the circuit is loaded.The output current capacity of the parallel port is limited to onlyfew milliamperes.<P>Here is a simple idea how you can connect load to a PC parallel port data pins. <P><PRE> Dn Out ------+ |+ Sourcing Load (up to 2.6 mA @ 2.4 v) |- Ground ------+</PRE><P>This is not the only way to connect things to a parallel port.<P>The parallel port data pins are TTL outputs, that can both sink and source current. In ordinary parallel port implementations the data outputs are 74LS374 IC totem-pole TTL outputs which can source 2.6 mA and sink 24 mA. <P>Regular TTL outputs basically consist of a two "stacked" transistor in series between +5 volts and ground, with the output coming from the connection between them. This is called a "totem pole output". At any given time one of these transistors is conducting and the other is not. To pull the output "high", the transistor from +5 to the output conducts (H), which "sources" positive current from the output to ground (that is, an external device between the output and ground will get power). To pull the output low, only the lower transistor (L) conducts, "sinking" current to ground; an external device between +5 volts and the output can be energized. <P><PRE> +5 / | ---H on V \ --> |________ TTL output on = 1 = high, "sourcing" current | out \ / / | ---L off \ V \_________/ Gnd +5_________ / \ ---H off / | \ \ V |________/ TTL output off = 0 = low, "sinking" current | <-- out / ---L on | \ V Gnd </PRE><P>The outputs are designed so that they give at least 2.4V at 2.6 mA load. This 2.6 mA figure is for ordinary LS-TLL circuits used, the LSI implementations used in many computers can give more or less. For example quite popular (few years ago) UM82C11-C parallel port chip can only source 2 mA. <P>Simple current sinking load connection:<P><PRE> Dn Out ------+ |+ Sourcing Load (up to 2.6 mA @ 2.4 v) |- Ground ------+</PRE><P>When taking current from PC parallel port, keep the load low, only up to few milliamperes. Trying to toke too much current (for example shorting pins to ground) can fry the parallel port. I have not killed any parallel port (yet) in this method, but I have had in cases where too much load has made the parallel port IC very hot. Be careful.<P>If you have an external +5 volt supply, you have another option for connection: use the Data Out pins to sink up to 24 mA from your +5 volt supply. This can be made with a circuit like this: <P><PRE> +------------------------------- (+5 v) |+ Sinking Load (up to 24 mA @ 4.2v) |- Power Supply Dn Out ------+ Ground -------------------------------------- ( Gnd)</PRE><P>The load gets power then you have external +5V on and the printer port data pin set to 0. This circuit gives you capability of of driving more current than the "sinking" approach. You need to be careful with this circuit, because with this circuit you can easily fry the parallel port if you do things wrong. My advice is to be very careful with this type of circuit and make sure that the external +5V power supply gets turned off when computer gets turned off (all printer ports might not like getting +5V though the load to printer port when they are not powere). The most convient source "external +5V" might be from same other port on your PC (USB, joystick, keyboard/mouse etc. port). <P>I have used mostly "sinking" type circuits and this article is concentrated on using them. <P><H3>Simple LED driving circuits</H3><P>You can make simple circuit for driving a small led through PCparallel port. The only components needed are one LED and one470 ohm resistors. You simply connect the diode and resistorin series. The resistors is needed to limit the current takenfrom parallel port to a value which light up acceptablynormal LEDs and is still safe value (not overloading the parallel portchip). In practical case the output current will be fewmilliampres for the LED, which will cause a typical LEDto somewhat light up visibly, but not get the full brigtness.<P><IMG SRC="led_r.gif" ALT="LED and resistor"><P>Then you connect the circuit to the parallel portso that one end of the circuit goes to one data pin (that one you with to usefor controlling that LED) and another one goes to any of the ground pins.Be sure to fit the circuit so that the LED positive lead (the longerone) goes to the datapin. If you put the led in the wrong way, it willnot light in any condition.You can connect one circuit to each of the parallel port data pins.In this way you get eight software controllable LEDs.<P><IMG SRC="lptleds.gif" ALT="LEDs wired to parallel port"><P><P>The softwarecontrolling is easy. When you send out 1 to the datapin where theLED is connected, that LED will light. When you send 0 to that same pin,the LED will no longer light.<P>Here are two photos of circuit above I have built:<P><IMG SRC="lptcircuit1.jpg" ALT="LEDs wired to parallel port circuit photo 1"><br><IMG SRC="lptcircuit2.jpg" ALT="LEDs wired to parallel port circuit photo 2"><P>Pn those circuits I have wired the ground wire only to one ground pin (it works also well, you can use any of the ground pins). <P><H3>Technical specifications of parallel port pins</H3><P>The IBM specifications says accoding <A HREF="http://www.epanorama.net/counter.php?url=http://www.linux.com/howtos/IO-Port-Programming-6.shtml">http://www.epanorama.net/counter.php?url=http://www.linux.com/howtos/IO-Port-Programming-6.shtml</A> the following: The data output pins (pins 2-9) sink 24 mA, source 15 mA, and their high-level output is min. 2.4 V. The low state for both is max. 0.5 V. Pins 1, 14, 16, and 17 (the control outputs) have open collector drivers pulled to 5 V through 4.7 kiloohm resistors (sink 20 mA, source 0.55 mA, high-level output 5.0 V minus pullup). Non-IBM parallel ports probably deviate from this standard. <P>Warning: Be careful with grounding. You can break parallel ports by connecting devices to them when PC is powered on. It is not a good idea to short the pins to ground or +5V, this can damage the port. It might be a good thing to use a parallel port not integrated on the motherboard for things like this. (You can usually get a second parallel port for your machine with a cheap standard `multi-I/O' card)<P><H2><A NAME="doscontrol">Control program for DOS (and Win9x)</A></H2><P>The following program is an example how to control parallel port LPT1data pins from your software. This example directly controls theparallel port registers, so it does not work under some multitaskingoperating system which does not allow that. It works nicely underMSDOS. You can look the Borland Pascal 7.0 code (should compilealso with earlier versions also) and then download the compiledprogram <A HREF="lptout.exe">LPTOUT.EXE</A>. This has worked nicely for me in DOS systems and Windows 95/98 systems. On recent testings this program has worked unreliably on some Windoes 2000 systems.<P><PRE>Program lpt1_output;Uses Dos;Var addr:word; data:byte; e:integer;Begin addr:=MemW[$0040:$0008]; Val(ParamStr(1),data,e); Port[addr]:=data;End.</PRE><H3>How to use the program</H3><P>LPTOUT.EXE is very easy to use program. The program takes oneparameter, which is the data value to send to the parallel port.That value must be integer in decimal format (for example 255).Hexadecimal numbers can also be used, but they must be preceded by $mark (for example $FF). The program hoes not have any type of errorchecking to keep it simple. If your number is not in correct format,the program will send some strange value to the port. <P>NOTE: I have found out that this program does not work reliably on some Windows 2000 systems I have tested on this. I don't know what is causing this specific problem (other than you should not try to access hardware directly on Windows NT based system..). I have not tested this program with Windows XP.<P><H3>Example how to use the program</H3><P>LPTOUT 0<BR>Set all datapins to low level.<BR><BR>LPTOUT 255<BR>Set all datapins to high level.<BR><BR>LPTOUT 1<BR>Set datapin D0 to high level and all other datapins to low level.<BR><BR><H4>How to calculate your own values to send to program</H4><P>You have to think the value you give to the program as a binarynumber. Every bit of the binary number control one output bit.The following table describes the relation of the bits, parallel port outputpins and the value of those bits.<PRE>Pin 2 3 4 5 6 7 8 9Bit D0 D1 D2 D3 D4 D5 D6 D7Value 1 2 4 8 16 32 64 128</PRE>For example if you want to set pins 2 and 3 to logic 1 (led on) then youhave to output value 1+2=3. If you want to set on pins 3,5 and 6 thenyou need to output value 2+8+16=26. In this way you can calculate the valuefor any bit combination you want to output.<P><H3>Making changes to source code</H3><P>You can easily change te parallel port number int the source codeby just changing the memory address where the program read theparallel port address. For more information, check the followingtable.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -