c语言串口通信 地址,《c语言串口通信范例》.doc
发布日期:2021-10-27 11:20:53 浏览次数:9 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:自学c语言看视频怎么好晕呀,C语言指针学多了,你为什么会觉得晕?
下一篇:linux eclipse cuda,CUDA与Linux系统

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月02日 18时14分46秒