Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parallel Ports of PC Methods of interfacing Examples.

Similar presentations


Presentation on theme: "Parallel Ports of PC Methods of interfacing Examples."— Presentation transcript:

1 Parallel Ports of PC Methods of interfacing Examples

2 The parallel port consist of 25 pins:  8 data input/outputs  4 control outputs  5 status inputs  8 pins are grounded

3 25 pin female (DB25) connector The registers found in standard parallel port are: Data register Status register Control register

4 Parallel Port Details

5 Parallel Port Details (Cont.)

6  Data registers are connected to data lines.  Control registers are connected to control lines.  Status register is connected to Status lines.  What you write to these registers, will appear in corresponding lines as voltages. You can measure it with a Multimeter.  Whatever you give to parallel port as voltages can be read from these registers ◦ For example, if we write '1' to Data register, the line Data 0 will be driven to +5v (actually 3.5 V). This way we can programmatically turn on and off any of the data lines and control lines.

7  In an IBM PC, these registers are IO mapped and will have unique address. We have to find these addresses to work with parallel port.  For a typical PC, ◦ the base address of LPT1 is 0x378 ◦ the base address of LPT2 is 0x278.  The data register resides at this base address  The status register at base address + 1  The control register is at base address + 2.  So once we have the base address, we can calculate the address of each registers in this manner. The table in the next slide shows the register addresses of LPT1 and LPT2.

8 The parallel port consists of three bytes in the PC I/O address space, starting at address 0x378. The first byte at 0x378 is for 8 bits of output The second byte at 0x379 is for 5 bits of input, 3 bits unused The third byte at 0x37A is for 4 bits of output, 4 bits of setup 0x378 is the address of the parallel port data register

9  Base port numbers: 0x378, 0x278  The normal method ◦ Call linux.ioperm() to get permission to access the ports ◦ Use in() to read from the port (check x86 Instructions) ◦ Use out() to write to the port (check x86 Instructions) ◦ The command #include(“linux.hhf”) provides the library for the functions of linux.ioperm()

10  The function ioperm (...) is Linux specific. ◦ It allows an application program to access to the 80x86 I/O- addresses within the range 0x000 to 0x3ff.  Call ioperm() to get permission to access the ports  Use in() to read data from the port. ◦ These instructions read a byte, word, and double word from an input port and place the input data into the accumulator register.  Must use DX register to hold the 16-bit port number  Example: in($379, AL) to read data from port $379 (line 10-line13) and place the information into the register AL

11  out( ) provides a HLA language interface to the machine instruction that outputs the accumulator to the specified port (i.e., I/O port) using the I/O address space instead of the memory address space.  Must use DX register to hold the 16-bit port number Example: mov($FF, AL); mov($378, DX); out(AL, DX) // this will send binary data 1111_1111 stored in AL to data port $378 (line2 - line9)

12  Give your program permission to access the port. This is done by calling the ioperm() function  The syntax is ioperm(from, num, turn_on), where: ◦ from is the first port number to give access to ◦ num the number of consecutive ports to give access to ◦ turn_on is a boolean value.  Example: ioperm(0x300, 5, 1) would give access to ports 0x300 through 0x304 (a total of 5 ports). The last argument is a Boolean value specifying whether to give access to the program to the ports (true (1)) or to remove access (false (0)). You can call ioperm() multiple times to enable multiple non-consecutive ports.  ioperm() can only give access to ports 0x000 through 0x3ff;  The ioperm() call requires your program to have root privileges; thus you need to run it as the root user

13  LEDS are connected to pins D 0 to D 7 and to the ground pins, respectively  Light the LED or output data (value) by out(AL, DX)  Value of AL is associated with the pins of the parallel port  Example: To light D 0 to D 3 you should call mov(15, AL); mov($378, DX); out(AL,DX); 1 + 2 + 4 + 8 = 15.

14  You have to think the value you give to the program as a binary number.  Every bit of the binary number control one output bit. The following describes the relation of the bits, parallel port output pins and the value of those bits. Pin 2 3 4 5 6 7 8 9 Bit D 0 D 1 D 2 D 3 D 4 D 5 D 6 D 7 Value 1 2 4 8 16 32 64 128 Note: The value above is the numeric value to send to printer port

15 How does it look In HLA under Linux? program Interface; #include(“stdlib.hhf”); #include(“linux.hhf”); begin Interface; stdout.put ("You must be root to run this program“, nl); linux.ioperm($378,3,1): //open port //Get a data from keyboard by stdin.get(AL); //Similar get a port number from key board mov($AA, AL); mov($378,DX); out(AL,DX);//send 1010 1010 to port $378 linux ioperm($378,3,0); //close port End Interface;


Download ppt "Parallel Ports of PC Methods of interfacing Examples."

Similar presentations


Ads by Google