---
title: "DOS下串口通信程序来传送文件的源代码。"
author: "mmdev"
date: "2005-08-01T16:41:00Z"
tags: []
slug: "dos"
draft: false
lastmod: "2005-08-01T16:41:00Z"
id: 990322
url: "https://mmdev.iteye.com/blog/990322"
---

我们PC/104系统只能装DOS，并且只有串口。平时调试很不方便，需要将电脑里的程序写到软盘，然后  
再通过软盘复制到开发装置。可怜软驱还不争气，到现在已经坏了好多软盘了。而且调试间和办公室离得比较远。到了调试间软盘读不出来，很郁闷。

这些天任务不是很重，就利用现有资源把串口程序整理了一下。做了一个DOS下的文件传送程序。在短距离下调试通过，不过长距离或者现场干扰较大的话，就不能保证传送的正确了。毕竟程序里没有校验文件功能，等以后再加吧。以后还要加一个传送整个文件夹的功能。  
抛砖引玉。

接收程序：

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;dos.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;fstream.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;conio.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;stdio.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;stdlib.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;math.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineRXD0//接收  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineTXD0//发送  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineLSB0//波特率调节低8位  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineMSB1//波特率调节高8位  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineIER1//中断起用寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineIIR2//中断标识寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineLCR3//线路控制寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineMCR4//调制解调器控制寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineLSR5//线路状态寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineMSR6//调制解调器状态寄存器  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineIERV1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineOUT20x08  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineERTS2  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineEDTR1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineEMPTY0X20  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineREADY0X30  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineICREG0X20  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineIMASKREG0X21  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineEOI0X20  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineWAITCOUNT5000  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineBUFFLEN2048//用于存储字符的数组的界  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineALTE0X12  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineALTQ0X10  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_120096  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_240048  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_96000x0C  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_192006  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_STOP\_10/\*/1stopbitpercharacter\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_STOP\_24/\*/2stopbitspercharacter\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BITS\_50/\*/send5bitcharacters\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BITS\_61/\*/send6bitcharacters\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BITS\_72/\*/send7bitcharacters\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BITS\_83/\*/send8bitcharacters\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_PARITY\_NONE0/\*/noparity\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_PARITY\_ODD8/\*/oddparity\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_PARITY\_EVEN24/\*/evenparity\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intport;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intComNum;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)unsignedportaddr;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)unsignedportf;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)unsignedintbaudtable\[]=...{0x180,0xc0,0x60,0x30,0x18,0x0c,0x06};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)unsignedcharparitytable\[]=...{0x08,0x18,0x00,0x28,0x38};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)unsignedcharbuffer\[BUFFLEN];//recvbuf  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intbuffin=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intbuffout=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intincount=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)intoutcount=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidinterrupt(\*vect\_com)(...);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidputb(unsignedcharch)//writeachartotherecvbuf将中断得到的数据写到缓冲区  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inttemp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp=buffin;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(++buffin==BUFFLEN)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)buffin=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(buffin!=buffout)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{buffer\[buffin]=ch;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//printf("bufferin\[%d]=%c",buffer\[buffin]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//getch();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)buffin=temp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)unsignedchargetb()//readacharfromtherecvbuf  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(buffout!=buffin)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(++buffout==BUFFLEN)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)buffout=0;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//printf("bufferout\[%d]=%c",buffout,buffer\[buffout]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return(buffer\[buffout]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return(0xff);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//\*unsignedcharsender(unsignedcharch)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif){  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr2+TXD,ch);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf(" senderoutportdata=%c ",ch);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outcount++;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return(1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidinterruptreceiver(...)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharch;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ch=inportb(portaddr+RXD);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)putb(ch);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)incount++;//记录接收了多少个数据。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(ICREG,EOI);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidSerInit(intbaud,intconfiguration)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)disable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+LCR,0x80);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+LSB,baud);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+MSB,0x00);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+LCR,configuration);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)enable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidSerOpen(void)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)vect\_com=getvect(portf+8);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)disable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inportb(portaddr+RXD);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inportb(portaddr+MSR);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inportb(portaddr+LSR);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)inportb(portaddr+IIR);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+IER,IERV);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+MCR,OUT2|ERTS|EDTR);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(IMASKREG,inportb(IMASKREG)&(~(1&lt;&lt;portf)));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)setvect(portf+8,receiver);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)enable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidSerClose(void)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)disable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+IER,0);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(portaddr+MCR,0);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)outportb(IMASKREG,inportb(IMASKREG)|(1&lt;&lt;portf));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)enable();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)setvect(portf+8,vect\_com);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidGetportaddr(intport)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)switch(port)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case0:portaddr=0x3F8;break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case1:portaddr=0x2F8;break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case2:portaddr=0x3E8;break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case3:portaddr=0x2E8;break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)portf=(port==0)?4:3;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidInt()  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)unsignedcharkey,key2;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)port=ComNum-1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(peek(0x40,port\*2)==0)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf("havenospecialcom. ");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)exit(1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf("Theusedportis:COM%d ",ComNum);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Getportaddr(port);//得到串口地址  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SerInit(SER\_BAUD\_9600,SER\_PARITY\_EVEN|SER\_BITS\_8|SER\_STOP\_1);//初始化串口，设置波特率等  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SerOpen();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)do  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(kbhit())  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)key2=getch();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(key2==27)...{break;}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)key=getb();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(key!=0xff)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf("%x ",key);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)FILE\*fp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fp=fopen("C:\\Receivedata.dat","ab");//可选择接收数据的存放文件路径和文件名  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(fp==NULL)printf("Fileopenerror!");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//fputc(key,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fwrite(&key,sizeof(unsignedchar),1,fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)fclose(fp);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}while(key2!=27);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)SerClose();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//printf("%dcharhasbeenreceived ",incount);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//printf("%dcharhasbeensended ",outcount);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//printf(" sum=%d ",sum);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)voidmain()//com1receive  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf("PleaseinputthereceiveCOMnum:(1~4) ");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cin&gt;&gt;ComNum;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf("thecurrentcomsetis:9600,even,databits8,stop1,");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Int();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)printf(" OVER ");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)exit(0);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

－－－－－－－－－－－－－－－  
发送文件程序

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;dos.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;bios.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;stdio.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;math.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;conio.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#include&lt;graphics.h&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#ifdef\_\_cplusplus  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#define\_\_CPPARGS...  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#define\_\_CPPARGS  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#endif  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_RBF0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_THR0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_IER1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_IIR2  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_LCR3  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_MCR4  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_LSR5  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_MSR6  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_DLL0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_DLH1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_120096  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_240048  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_960012  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_BAUD\_192006  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineSER\_GP028  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#defineCOM\_10x3F8