Pages

Thursday, September 5, 2013

PC to PC serial communication-PC1

/*Program : PC to PC serial communication-PC1*/
/*Programmed By : Lubin*/
#define COM_BASE 0x3f8
#define DFR COM_BASE+3
#define LDLR COM_BASE
#define HDLR COM_BASE+1
#define SSR COM_BASE+5
#include<asm/io.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
static inline unsigned char recv_char()
{
while(!(inb(SSR) & 1));
return inb(COM_BASE);
}
void uart_init()
{
iopl(3);
outb(0x83,DFR);
outb(0x18,LDLR);
outb(0,HDLR);
outb(0x03,DFR);
}
int main(int argc,char *argv[])
{
int count,fd,i=0;
unsigned char ch,fname[30];
uart_init();
if(argc>1)
fd=open(argv[1],O_CREAT | O_WRONLY);
else
{
printf("Enter the output file\n");
scanf("%s",fname);
fd=open(fname,O_CREAT | O_WRONLY);
}
printf("Receiving....\n");
do
{
ch=recv_char();
if((char)ch!=EOF)
{
count=write(fd,&ch,1);
i++;
}
}while((char)ch!=EOF);
close(fd);
printf("Received %d bytes\n",i);
return 0;
}

No comments:

Post a Comment