Parallel port: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Added how to detect the IO base addresses
m Bot: Replace deprecated source tag with syntaxhighlight
 
(6 intermediate revisions by 4 users not shown)
Line 1:
{{NoteBox|<b>NOTE:</b> Before doing anything, make sure to set the parallel ports mode to Standard or Normal in the BIOS instead of ECP/EPP if anything fails from your programming efforts, preferably before exhausting your options}}
 
 
The parallel port uses a sub-d 25 connector to provide a 8-bit data bus. It is commonly used by printers. There are 3 kinds of parallel ports: Standard Parallel Port (SPP), Enhanced Parallel Port (EPP) and Extended Capabilities Parallel Port (ECP). iirc they are all part of IEEE Standard 1284, or is it just the second two?
==Pin types==
Line 65 ⟶ 68:
In Standard (or Compatibility) mode, data is sent to the connected device by writing the byte to the data port, then pulsing the STROBE signal. This pulse informs the device that data is ready to be read. The device will respond by raising its BUSY signal and then reading the data and performing some processing on it. Once this processing is complete, the device will lower the Busy signal and may raise a brief ACK signal to indicate that it has finished.
 
<sourcesyntaxhighlight lang="c">
// Sends a byte to the printer
void Parallel_SendByte( unsigned char pData )
Line 72 ⟶ 75:
// Wait for the printer to be receptive
while ( ! Ports_In8inb( 0x379 ) & 0x80 )
{
Timer_Delay( 10 );
Line 78 ⟶ 81:
// Now put the data onto the data lines
Ports_Out8outb( 0x378, pData );
// Now pulse the strobe line to tell the printer to read the data
lControl = Ports_In8( 0x37A);
Ports_Out8outb( 0x37A, lControl | 1 );
Timer_Delay( 10 );
Ports_Out8outb( 0x37A, lControl );
// Now wait for the printer to finish processing
while ( ! Ports_In8inb( 0x379 ) & 0x80 )
{
Timer_Delay( 10 );
}
}
</syntaxhighlight>
</source>
 
<tt>Timer_Delay()</tt> pauses processing for the specified number of milliseconds. <tt>Ports_In8inb()</tt> and <tt>Ports_Out8outb()</tt> read and write a byte of data to/from the IO port. You can find the IO functions in the [[Inline_Assembly/Examples#OUTx|Inline Assembly Examples page]].
 
 
 
[http://devel.archefire.org/TextRecordings/lpthandler.tar <b><code>lpthandler.tar:</code></b> Code and binary for "LPT Handler for Windows"]
 
[http://www.youtube.com/watch?v=sJRbGohmA3M <b>YouTube video:</b> Basics of Parallel Port Programming Under Windows, Part 1 of 2]
 
[http://www.youtube.com/watch?v=zAxeCLuWZCk <b>YouTube video:</b> Basics of Parallel Port Programming Under Windows, Part 2 of 2]
 
[[File:Win32_lpthandler_exe_0000.jpg]]
 
<syntaxhighlight lang="c">
/*
In short we only need:
 
outl(LPT_Base_Address+2, 0); //Reset Control port with 0
outl(LPT_Base_Address, 0xFF-0x00); //Write Data Port with any byte value
*/
 
 
 
//Here the LPT_Base_Address can be:
//
// 0x3BC -- LPT1
// 0x378 -- LPT1
// 0x278 -- LPT2
// 0x3BC -- LPT3
///
 
//We need to reset the Control Port writing a 0
//to configure their options, controlled for each of
//their bits:
///
outl(LPT_Base_Address+2, 0);
 
//Now send an value betwewen 0 and 255 to the data port:
///
outl(LPT_Base_Address, 0xFF-0x00);
 
</syntaxhighlight>
 
== See Also ==
=== Threads ===
* [[Topic:30279|Easy Parallel Port Programming Tests (Under Windows)]]
 
 
<tt>Timer_Delay()</tt> pauses processing for the specified number of milliseconds. <tt>Ports_In8()</tt> and <tt>Ports_Out8()</tt> read and write a byte of data to/from the IO port.
 
[[Category:Common Devices]]
[[Category:Hardware Interfaces]]