c语言串口通信中字符串结束符发,c语言串口通信范例-20210322202011.docx-原创力文档...

Last updated on the afternoon of January 3, 2021

Last updated on the afternoon of January 3, 2021

c语言串口通信范例

一个c语言的串口通信程序范例

标签:

分类:

最近接触一个项目,用HL-C1C激光位移传感器+易控组态软件完成生产线高度跳变检测,好久没有接触cc#,一些资料,找来做个记录,也许大家用的着

#include<>#include<>#include<>#include<>

#defineCOM232?0x2f8#defineCOMINT?0x0b

#defineMaxBufLen500#definePort82590x20#defineEofInt0x20

staticintcomportaddr;staticcharintvectnum;staticunsignedcharmaskb;staticunsignedcharBuffer[MaxBufLen];staticintCharsInBuf,CircIn,CircOut;

staticvoid(interruptfar*OldAsyncInt)();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(ComPortAddr+1,High);

Data=(Data-5)|((Stop-1)*4);if(Parity==2)Data=Data|0x18;elseif(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);elseoutp(Port8259+1,maskb&0xf7);}

staticvoidinterruptfarAsyncInt(void){disable();

if(CharsInBuf

voidRestore(void){setvect(intvectnum,OldAsyncInt);outp(Port8259+1,maskb);}intGetCharInBuf(unsignedchar*Char){intFlag;

Flag=-1;

if(CharsInBuf>0){(*Char)=Buffer[CircOut];if(CircOut

intSendChar(unsignedcharChar){if((inp(comportaddr+5)&0x20)==0)return-1;outp(comportaddr,Char);return0;}

main(){inti,c;unsignedcharInChar;

Init_COM(COM232,COMINT,1200,8,1,0);while(1){if(kbhit()){

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值