资源描述:
《C语言串口通信-源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#defineCOM232 0x2f8#defineCOMINT 0x0b#defineMaxBufLen 500#definePort8259 0x20#defineEofInt 0x20staticint comportaddr;staticcharintvectnum;staticunsignedcharmaskb;staticunsignedcharBuffer[MaxBufLen];staticint Char
2、sInBuf,CircIn,CircOut;staticvoid(interruptfar*OldAsyncInt)();staticvoidinterruptfarAsyncInt(void);voidInit_COM(intComPortAddr,unsignedcharIntVectNum,intBaud, unsignedcharData,unsignedcharStop,unsignedcharParity){ unsignedcharHigh,Low; intf; comportaddr=ComPortAddr; intvectnum=IntVectNum;
3、CharsInBuf=0;CircIn=0;CircOut=0; f=(Baud/100); f=1152/f;High=f/256; Low=f-High*256; outp(ComPortAddr+3,0x80); outp(ComPortAddr,Low); outp(ComPortAddr+1,High); Data=(Data-5)
4、((Stop-1)*4); if(Parity==2)Data=Data
5、0x18; elseif(Parity==1)Data=Data
6、0x8; outp(ComPortAddr+3,Data); outp(ComPortAddr+
7、4,0x0a); outp(ComPortAddr+1,0x01); disable(); OldAsyncInt=getvect(IntVectNum); setvect(IntVectNum,AsyncInt); enable(); maskb=inp(Port8259+1); if(IntVectNum==0x0c)outp(Port8259+1,maskb&0xef); elseoutp(Port8259+1,maskb&0xf7); }staticvoidinterruptfarAsyncInt(void){ disable(); if(C
8、harsInBuf9、intFlag; Flag=-1; if(CharsInBuf>0) { (*Char)=Buffer[CircOut]; if(CircOut10、 Init_COM(COM232,COMINT,1200,8,1,0); while(1) { if(kbhit()) {if((InChar=getch())==27)break; elsewhile(SendChar(InChar)); } if(GetCharInBuf(&InChar)==0) printf("%c",InChar); }Restore();} 接收程序: #include #include<