Saturday, November 13, 2010

Parallel Port Programming In Turbo C++ Part 1

Initial preparations: Before getting your hands dirty with coding, you have to do some thing to make these parallel port programs work well. Windows XP users will have to copy the file " MSWINSCK.OCX " into the folder c:/windows/system32.

In Turbo C++ functions for handling parallel port communication are held in the header file " dos.h" . Various functions required for parallel port are listed below.

 inport         reads a word from a hardware port.
 inportb       reads a byte from a hardware port.
 outport      outputs a word to a hardware port.
 outportb    outputs a byte to a hardware port.

INPORT  is used for word by word reception. The syntax is as follows: 

inport (portid); 

here portid is the address of the port. For parallel port the address is 0x378. For example 

int result;
result=inport( 0x378 ); 

this will read the word of data from the parallel port and will be stored in the variable result. 

INPORTB  is used for byte by byte reception. The syntax is as follows: 

inportb (portid) 

For example 

unsigned char result;
result = inportb(0x378); 

this will read a byte from the port and will be saved in the variable result. 

OUTPORT is used to output a word to the port. The syntax is as follows: 

outport (portid,value); 

here value is the data for output. For example 

int value =450;

this will output the data 450 to the parallel port. 

OUTPORTB is used to output a single byte to a port. The sysntax is as follows: 

outportb (portid, value); 

For example 

outportb (0x378,255); 

this will output the data 255 to the parallel port. 

Download Sample Programs


shrinivas said...

please post an article about controlling parallel port using Turbo C++ on windows-7 platform.

himesh M said...

i dnt think this programming technique will work on xp because microsoft doesn't support directio programming from winxp is only available for win98/95

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes