Pc interface

Status
Not open for further replies.

leekok002

New Member
Hi, all. I am just new join this forum and i would like to ask that how can i connect 2 PC through serial port? i need the source code of the software used, and i have got one that using C++, but i do not have the header file "bios.h" and my advisor ask me to change the software. For my knowledge, its not easy to do that because i do not familiar with programming. that's my pro... i will attach the coding i got and hopefully you all can help. Meanwhile, i would like to look for the information of PC connect to microcontroller(PIC).

//Program to communicate two PC s via serial port
//00H bios function (AL register)

//bits 7 6 5 Baud rate
// 0 0 0 110
// 0 0 1 150
// 0 1 0 300
// 0 1 1 600
// 1 0 0 1200
// 1 0 1 2400
// 1 1 0 4800
// 1 1 1 9600

//bits 4 3 Parity bits
// 0 0 no parity
// 0 1 odd parity
// 1 1 even

//bits 2 stop bits
// 0 1 stop bit
// 1 2 stop bit

//bits 1 0 Number of bits per data
// 1 0 7 data bits
// 1 1 8 data bits

//Register Dx 0->com1, 1->com2, 2->com3, 3->com4

//Configuration: 9600 bd,no parity,2 stop bits and 8 data bits
//AL register value is 1 1 1 0 0 1 1 1 -> 0xE7

#include <stdio.h>
#include <process.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>

#define TRUE 1
#define PARAM 0xA7
#define COM1 0
#define COM2 1

void init_port(void);
char state_port(void);
void send_byte(unsigned char);
unsigned char read_byte(void);
void keyb(void);


int tecla = 1;

void main ( void )
{
unsigned char read_com;
unsigned char read_kb;
clrscr();
init_port();

while(read_kb != 'c')
{
read_kb=getch();
send_byte(read_kb);
read_com=read_byte();
if(read_com!=0){printf("%c",read_com);}
}
}

void init_port()
{
union REGS regs;
regs.h.ah = 0x00;
regs.x.dx = COM2;
regs.h.al = PARAM;
int86( 0x14, &regs, &regs);
}

//return the state of the port

char state_port()
{
union REGS regs;
regs.h.ah = 0x03;
regs.x.dx = COM2;
int86( 0x14, &regs, &regs);
if(regs.h.ah & 0x80) printf("\t EXCEED TIME\n");
if(regs.h.ah & 0x40) printf("\t TSR EMPTY\n");
if(regs.h.ah & 0x20) printf("\t THR EMPTY\n");
if(regs.h.ah & 0x10) printf("\t INTERRUPTION\n");
if(regs.h.ah & 0x08) printf("\t THREAT ERROR\n");
if(regs.h.ah & 0x04) printf("\t PARITY ERROR\n");
if(regs.h.ah & 0x02) printf("\t OVERLOAD ERROR\n");
return (regs.h.ah);
}

//Keyboard handle

void keyb()
{
union u_type{int a;char b[3];}keystroke;char inkey=0;

if(bioskey(1)==0) return;
keystroke.a=bioskey(0);
inkey=keystroke.b[1];
switch (inkey)
{
case 1: keyb=0;
return; /*ESC*/
default: keyb=15;
return;
}
}



//Send a character to the serial port

void send_byte(unsigned char byte)
{
union REGS regs;
regs.h.ah = 0x01;
regs.x.dx = COM2;
regs.h.al = byte;
int86( 0x14, &regs, &regs);
if( regs.h.ah & 0x80)
{
printf("\t SENDING ERROR ");
exit(1);
}
}

//read a character from serial port

unsigned char read_byte()
{
int x,a;
union REGS regs;
if((estate_port() & 0x01))
{
regs.h.ah = 0x02;
regs.x.dx = COM2;
int86(0x14,&regs,&regs);
if(regs.h.ah & 0x80)
{
printf("\t RECEIVING ERROR");
exit(1);
}
return(regs.h.al);}
else
{
return(0);
}
}
[/b]
 

Hi there,

U need a connect PC1 COM port's pin2 to PC2 COM port pin 3 to make it as null modem to establish communication between 2 PCs. And you must consider what PC operating system are you using now ? If you are using WIN95/98, it will allow you to read/write I/O directly, but whenever you are under Windows XP, Windows 2000 or NT, then you will got problem to read/write I/O directly. And I/O driver needed.

Other alternative, you may consider to use Visual basic for programming, please visit website below,

http://www.geocities.com/bagtool/vb/vb_program.html
http://www.geocities.com/bagtool/serial_basic.htm
http://www.geocities.com/bagtool/parallel_basic.html

free 8)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…