I present you about programming by C, version that runs on DOS because there is easier explanation than program as visual that runs on Window that you can notice the article about MS VC++ 6 communicating with Parallel Port and also you can write and try to do by yourself. You can use TurboC because just 1 Mb compiler.

From the part 1, I mentioned about communication as interrupt. In this part, I will present you about communication as polling. The working like this, the flow of data will not be smooth. CPU cannot anticipate that when the new data arrive. It will verify the time with getting and sending data by speed rate that is higher than speed rate that send through keyboard.

So, you may understand about polling, let’ see programming. I will mention about code program of C, in the section of setting so that com port can communicate, that has the details like the following,

1. Code for setting Literal to variable for position value of each com port by choosing that value according to com port we use in communication only.

#define COMP1 0×3F8 // set value of com port position by having Hexadenary like the following,
// COM1 = 0×3F8
// COM2 = 0×2F8
// COM3 = 0×3E8
// COM4 = 0×2E8

2. This code will be setting of communication via com port. You will see that many parts of the article I mentioned already will have this part also. You can use this code to use as the same figure to communicate with Com Port (RS-232) only.

outp(COMP1 + 1 , 0); // close interrupt com port1
outp(COMP1 + 3 , 0×80); // open com port for communication
outp(COMP1 + 0 , 0×03); // set Baud rate, the speed in getting and sending data in the side of Low Byte
// 0×03 = 38,400 BPS
// 0×01 = 115,200 BPS
// 0×02 = 57,600 BPS
// 0×06 = 19,200 BPS
// 0×0C = 9,600 BPS
// 0×18 = 4,800 BPS
// 0×30 = 2,400 BPS
outp(1 + 1 , 0×00); // set Baud rate in the side of High Byte
outp(COMP1 + 3 , 0×03);
// the number of getting and sending 8 บิต, no parity, bit stop 1.
outp(COMP1 + 2 , 0xC7);
// control register value FIFO.
outp(COMP1 + 4 , 0×0B);
// open getting and sending DTR, RTS and OUT2.

Codes I mentioned above, you can write in main of communicative program as polling by having the code details and working’s explanation of command like this,

#include <dos.h> // set include file for function communicating port.
#include <stdio.h>
//set include file for the main function.
#include <conio.h>
//set include file for function communicating with I/O hardware.

#define COMP1 0×3F8 // set value of com port’s position by having ค่าของเลขฐาน16 like the following,
// COM1 = 0×3F8
// COM2 = 0×2F8
// COM3 = 0×3E8
// COM4 = 0×2E8

void main(void)
// the main routine of program
{
int valA;
// set variable for using in routine as polling.
int strg;
// set variable as string to keep alphabet of getting and sending data at com port
outp(COMP1 + 1 , 0); /
/ close interrupt com port1.

//set so that com port can get and send data.

outp(COMP1 + 3 , 0×80); // open com port for communication
outp(COMP1 + 0 , 0×03);
// set Baud rate, the speed in getting and sending data in the side of Low Byte
// 0×03 = 38,400 BPS
// 0×01 = 115,200 BPS
// 0×02 = 57,600 BPS
// 0×06 = 19,200 BPS
// 0×0C = 9,600 BPS
// 0×18 = 4,800 BPS
// 0×30 = 2,400 BPS
outp(1 + 1 , 0×00); // set Baud rate in the side of High Byte
outp(COMP1 + 3 , 0×03);
// the number of getting and sending 8 บิต, no parity , bit stop 1
outp(COMP1 + 2 , 0xC7);
// control register value FIFO
outp(COMP1 + 4 , 0×0B);
// open getting and sending data DTR, RTS และ OUT2

printf(”\nCommunicate’s Polling. Press ESC to Exit \n”);

do { valA = inp(COMP1 + 5); //verify that there is sending data already.
//getting data already.
if (valA &amp; 1) {strg = inp(COMP1); // so, then keep value of data.
printf(”%valA”,strg); }
//show alphabet on screen.

if (kbhit()){strg = getch(); // If there is printing, then keep value to variable strg
outp(COMP1,strg);}
// after that, sending those alphabet in variable strg to Serial port

} while (strg !=27); // If there is pressing button ESC, then end the program and exit program
}

Are you Ok with this article? It’s about code main () only, no other procedure. Maybe, some of them doubt that can Parallel Port program as interrupt and polling. In the next part, I will present.