Professional Documents
Culture Documents
(Ref: http://www.codeproject.com/Articles/4981/I-O-Ports-Uncensored-Controlling-LEDs-Light-Emit)
S0: This bit becomes higher (1) if a timeout operation occurs in EPP mode.
S1: Not used (Maybe for decoration
S2: Mostly not used but sometime this bit shows the cut condition (PIRQ) of the port
S3: If the printer determines an error it becomes lower (0). Which is called nError or nFault
S4: It is high (1) when the data inputs are active. Which is called Select
S5: It is high(1) when there is no paper in printer. Which is called PaperEnd, PaperEmpty or PError
S6: It sends low impact signaling when the printer gets a one byte data. Which is called nAck or nAcknowledge
S7: This is the only reversed pin on the connector (see my table in the article) . If the printer is busy and it cannot get any additional data this pin
becomes lower. Which is called Busy
C0: This pin is reversed. It sends a command to read D0-D7 on the port. When the computer starts it is high in the connector. Which is called nStrobe
C2: This pin is for reset the printer and clear the buffer. Which is called nInit, nInitialize
C1: This pin is reversed. It sends a command to the printer to feed the next line. It is high in the connector after the machine starts. Which is called Auto
LF
C3: This pin is reversed. Sends a high(1) for opening data inputs. It is low after the machine starts. Which is called nSelectIn
C4: Opens the cut operation for the printer. Not visible in the connector...
C5: Sets the direction control in multidirectional ports. Not visible in the connector...
C6: Not used and also Not visible in the connector...
C7: Mostly not used but it is used as a C5 in some ports. Not visible in the connector...
PART 2 - Electricity
I made an electrical circuit to show you how our circuit work. It is shown in the picture...
1 or 2 meter parallel port cable (3 mt is acceptable but the voltage drops from 5 V to 4.7 V)
9 assembling cables (8 go to resistance and 1 go to ground)
A Breadboard (white one in the picture) or you can solder the cables but with a breadboard you don't have to...
8 Leds (2,5 V)
8 Resistances (470 ohm) (For not to make the leds garbage because of +5V)
A Multimeter (Not needed but if something happens you can check the wiring with this...)
using System;
using System.Runtime.InteropServices;
public class PortAccess
{
[DllImport("inpout32.dll", EntryPoint="Out32")]
public static extern void Output(int adress, int value);
}
So you have to import inpout32.dll to your debug or release directory. By the way, the main thing in
my Form1.csis PortAccess.Output. It takes two variables which are address and value. If your data ports are set in "0x378" (see Part 1)
you will have to write "888" because "378" Hexadecimal is equal to "888" in decimal. (Default LPT1 is set to "378") If you are using LPT2 which is "0x278"
you have to write for the address "632" For ex: for full signaling to pins we have to call the Output method of PortAccess like:
Hide Copy Code
PortAccess.Output(888, 255);
And for null data we have to send "0" to the Output method like:
Hide Copy Code
PortAccess.Output(888, 0);
I wrote a func for reseting the LEDs which is:
Hide Copy Code
#include <conio.h>
#include <dos.h> // For _out
#define port 0x378 // Port Address
#define data port+0 // Data Port of the parallel cable
void main (void)
{
_out(data, 255); // For all lights on
_out(data, 0); // For all lights off
}
or
The ground of the external power supply must also be connected to the ground of the parallel port.
With this configuration, the LED will only light if 0V or low logic is present in theoutput port. This is so
because there will be a potential difference between the external supply and computer port. This will
eventually cause an electric current to flow, a current enough to lit up the LED.
One way to solve this interfaced programming problem is identify first the statement or statements that
will control the load. In our case, we will use the outportb function of Turbo C. Then we will solve the
number to be send.
To activate the LED, the following bits should be sent to the data port:
We should send 0 to D0 so that the LED will light. The other data pins are markedX since they can be any
bit (0 or 1), they can not affect the LED which is only connected to D0.
But it is still necessary to put specific bits to D7-D1. So well just fill them with all 0s so that it can easily
be converted to hexadecimal number.
The next step is to convert the binary digits into hexadecimal number. We can also convert it to decimal
number but binary to hexadecimal conversion is more simple.
We still send 0s to D7-D1 so that the whole byte can be easily converted.
Next we will convert the number.
Therefore, our Turbo C statements that will turn off the LED should be:
So we can now write our Turbo C program that will control the LED to blink 5 times.
#include <dos.h>
void main()
{
outportb(0x378, 0x01);
delay(200);
outportb(0x378, 0x00);
delay(200);
outportb(0x378, 0x01);
delay(200);
outportb(0x378, 0x00);
delay(200);
outportb(0x378, 0x01);
delay(200);
outportb(0x378, 0x00);
delay(200);
outportb(0x378, 0x01);
delay(200);
outportb(0x378, 0x00);
delay(200);
outportb(0x378, 0x01);
delay(200);
outportb(0x378, 0x00);
delay(200);
outportb(0x378, 0x01);