一个 c 语言的串口通信程序范例标签:分类:技术笔记c 语言串口通信通信程序it最近接触一个项目,用 HL-C1C 激光位移传感器+易控组态软件完成生产线高度跳变检测,好久没有接触 cc#,一些资料,找来做个记录,也许大家用的着#include#include#include#include#defineCOM2320x2f8#defineCOMINT0x0b#defineMaxBufLen500#definePort82590x20#defineEofInt0x20staticintcomportaddr;staticcharintvectnum;staticunsignedcharmaskb;staticunsignedcharBuffer[MaxBufLen];staticintCharsInBuf,CircIn,CircOut;staticvoid(interruptfar*OldAsyncInt)();outp(ComPortAddr+4,0x0a);staticvoidinterruptfarAsyncInt(void);voidInit_COM(intComPortAddr,unsignedcharIntVectNum,intBaud,unsignedcharData,unsignedcharStop,unsignedcharParity){unsignedcharHigh,Low;intf;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(ComPortAd