It’s C/C++ in programming to communicate with Serial Port or comport (RS-232). The program I recommend here can communicate between two computers that can send message to each other as interrupt.

For here, we will use Borland C as complier, but you will see me use // that I make for programming explanation. There will be code for reference inter like the following,

Intervector –> use setvect()function for setting the value of IRQ

Intervector –> use getvect()function for the value of IRQ

Intervector –> use for setting of Programmable Interrrupt Controller

Intervector –> use for setting in order to cancel using intervector

Comm Setting –> will use the value in setting rate of Baud rate, the number of bit in transferring data, stop bit, control register FIFO, open DTR-RTS-OUT2.

I will take the values to show for explanation or in the content, Data Reference–> the value of IRQ,DMA,I/O,Memory Address that have explanation already. Let’s begin programming by setting include file that are used 3 files,

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

#define COMP1 0×3F8 // set the address value of Com Port Com1
// set the address value of Com Port from
Com1-4 like the followings,
// COM1 = 0×3F8
// COM2 = 0×2F8
// COM3 = 0×3E8
// COM4 = 0×2E8
#define valirq 0×0C //set the value of IRQ will be belong to the value of Com Port ;Com1=IRQ4 ,Com2= IRQ3 will have the value of interrupt vector like these,
// IRQ of com1 = 0×0C
// IRQ ” com2 = 0×0B
// IRQ ” com3 = 0×0C
// IRQ ” com4 = 0×0B

//
the next step is to set variable value for using in program
int storein = 0; // variable used in routine that get value from port
int storeout = 0;
// variable used in routine that send value from port
char strg;
char store[1025];
// variable that keep value that communicate port by using array.

void makeISR (*comported)(); // set for open and close interrupt by using as pointer
void ComportISR()
//this routineis is to make interservice routine
(ISR)forCOMP1
{
int valx;
//set variable named valx
do { valx = inp(COMP1 + 5);
//use function inp() for get value from port as byte
&amp;nbspif (valx &amp; 1) {strore[storein] = inp(COMP1);
//set condition for getting value to verify
&nbspstorein++;
if (storein == 1024) {storein = 0;}}
//If there are data =1024, give variable value as 0
}while (valx & 1);
outp(0×20,0×20);
// use function to send data to port using function outp()
}
//start main program

void main(void)
{
int valx;
outp(COMP1 + 1 , 0);
//close interrupt of comport
comported = getvect(valirq);
//keep interrupt value
setvect(valirq, ComportISR);
//set interrupt vector value IRQ
// COM1 = 0×0C
// COM2 = 0×0B
// COM3 = 0×0C
// COM4 = 0×0B

//set values using for communication of com port
outp(COMP1 + 3 , 0×80); //set value for opening port
outp(COMP1 + 0 , 0×0C);
// set Baud rate value at the side Low Byte at speed rate 9,600
// 0×03 = 38,400BPS */
// 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(COMP1 + 1 , 0×00); // set Baud rate at the side,
High Byte
outp(COMP1 + 3 , 0×03); // 8 bit per time, no parity, bit stop 1
outp(COMP1 + 2 , 0xC7); //control register value FIFO
outp(COMP1 + 4 , 0×0B); //open using DTR, RTS, and OUT2

outp(0×21,(inp(0×21) & 0xEF)); // set program mable controller program
// Com1 (IRQ4) = 0xEF
// Com2 (IRQ3) = 0xF7
// Com3 (IRQ4) = 0xEF
// Com4 (IRQ3) = 0xF7

outp(COMP1 + 1 , 0×01); //occure interrupt when get data

//show alphabet to wait pressing keyboard, if you will exit program, then press ESC
printf(”\nTest Comm Port By C . Keydown ESC to Exit \n”);

//in this side, will loop for getting data from keyboard in order to send data to comport
do {

if (storein != storeout){strg = store[storeout]; // keep value for sending to port
storeout++;
// set for not over 1024, if it is over, set variable storeout as 0
if (storeout == 1024) {storeout = 0;}
printf(”%valA”,strg);}
// show value to display monitor

if (kbhit()){valA = getch(); //function getting data keyboard
outp(COMP1, valA);}
//send value from port
} while (valA !=27);
// if press ESC, will exit from loop

outp(COMP1 + 1 , 0); //close interrupt of Com port
outp(0×21,(inp(0×21) | 0×10)); // close using IRQ
// COM1 (IRQ4) - 0×10
// COM2 (IRQ3) - 0×08
// COM3 (IRQ4) - 0×10

// COM4 (IRQ3) - 0×08
setvect(valirq, Comported); //restore IRQ

}

Are you alright with this section? If you want to program like this, you must know values of computer system that hardware has so that software will communicate. All this, you should have the good fundamental of C programming. For communication as polling is in the next section.