bios.h and conio.h are the header files you need to include.
#include
#include
#define COM1 0
#define DATA_READY 0x100
#define SETTINGS ( 0x80 0x02 0x00 0x00)
// 1200 baud, 7 data bits,
int main(void)
{
int in, out, status;
bioscom(0, SETTINGS, COM1); /*initialize the port*/
cprintf("Data sent to you: ");
while (1)
{
status = bioscom(3, 0, COM1); /*wait until get a data*/
if (status & DATA_READY)
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) /*input a data*/
putch(out);
if (kbhit())
{
if ((in = getch()) == 27) /* ASCII of Esc*/
break;
bioscom(1, in, COM1); /*output a data*/
}
}
return 0;
}
Turbo C Function used here is bioscom(). The syntax of function is :
bioscom(int cmd, char abyte, int port);
_bios_serialcom(int cmd ,int port, char abyte);
bioscom() and _bios_serialcom() uses the bios interrupt 0x14 to perform various communicate the serial communication over the I/O ports given in port.
1) cmd: The I/O operation to be performed.
0
_COM_INIT
Initialise the parameters to the port
1
_COM_SEND
Send the character to the port
2
_COM_RECEIVE
Receive character from the port
3
_COM_STATUS
Returns rhe current status of the communication port
2)portid: port to which data is to be sent or from which data is to be read.
0: COM1
1: COM2
2: COM3
3)abyte:
When cmd =2 or 3 (_COM_SEND or _COM_RECEIVE) parameter abyte is ignored.
When you compile and run the above program in both the computers, The characters typed in one computer should appear on the other computer screen and vice versa. Initially, we set the port to desired settings as defined in macro settings. Then we waited in an idle loop until a key is pressed or a data is available on the port. If any key is pressed, then kbhit() function returns non zero value. So will go to getch function where we are finding out which key is pressed. Then we are sending it to the com port. Similarly, if any data is available on the port, we are receiving it from the port and displaying it on the screen.
Communication
The program is the same in help of turbo C++
ReplyDeleteYeah.. but a lil more described than in the Turbo.. especially this one is for those who didnt know to look the Turbo Help properly, and googles for a sample. :)
ReplyDeleteThanks for comments.