本文共 1620 字,大约阅读时间需要 5 分钟。
一个c语言的串口通信程序范例
标签:
c语言
串口通信
通信程序
it
分类: 技术笔记
最近接触一个项目,用HL-C1C激光位移传感器+易控组态软件完成生产线高度跳变检测,好久没有接触c c#,一些资料,找来做个记录,也许大家用的着
#include #include #include #include
#define COM232? 0x2f8#define COMINT? 0x0b
#define MaxBufLen????? 500#define Port8259?????? 0x20#define EofInt??????? 0x20
static int? comportaddr;static char intvectnum;static unsigned char maskb;static unsigned char Buffer[MaxBufLen];static int? CharsInBuf,CircIn,CircOut;
static void (interrupt far *OldAsyncInt)();static void interrupt far AsyncInt(void);
void Init_COM(int ComPortAddr, unsigned char IntVectNum, int Baud,?????? unsigned char Data, unsigned char Stop, unsigned char Parity){?unsigned char High,Low;?int f;
?comportaddr=ComPortAddr;?intvectnum=IntVectNum;
?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)|((Stop-1)*4);?if(Parity==2) Data=Data|0x18;?else if(Parity==1) Data=Data|0x8;?outp(ComPortAddr+3,Data);
??outp(ComPortAddr+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);?else outp(Port8259+1,maskb&0xf7);??????????????}
static void interrupt far AsyncInt(void){?disable();
?if(CharsInBuf
void Restore(void){?setvect(intvectnum,OldAsyncInt);?outp(Port8259+1,maskb);?}int GetCharInBuf(unsigned char *Char){?int Flag;
?Flag=-1;
?if(CharsInBuf>0)? {?? (*Char)=Buffer[CircOut];?? if(CircOut
int SendChar(unsigned char Char){?if((inp(comportaddr+5)&0x20)==0) retur
转载地址:https://blog.csdn.net/weixin_34518190/article/details/117032201 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!