⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sercomm.h

📁 自己编的用于工业触摸屏通讯的MODBUS RTU SLAVE 协议源代码
💻 H
字号:
#ifndef _SERCOMM_H_
#define _SERCOMM_H_

#define COM1            1
#define COM2            2
//#define COM3            3
//#define COM4            4

#define COM1BASE        0x3F8   /*  Base port address for COM1  */
#define COM2BASE        0x2F8   /*  Base port address for COM2  */
//#define COM3BASE        0x3E8   /*  Base port address for COM3  */
//#define COM4BASE        0x2E8   /*  Base port address for COM4  */

/*-------------------------------------------------------------------*
  Bit values held in the Line Control Register (LCR).
	bit		meaning
	---		-------
	0-1		00=5 bits, 01=6 bits, 10=7 bits, 11=8 bits.	/word length select bit
	2		Stop bits.									/	
	3		0=parity off, 1=parity on.					/Parity Enable=1
	4		0=parity odd, 1=parity even.				/Odd or Even select
	5		Sticky parity.								/
	6		Set break.
	7		Toggle port addresses.						/1:access 
 *-------------------------------------------------------------------*/
#define LCR_NO_PARITY       0x00
#define LCR_EVEN_PARITY     0x18
#define LCR_ODD_PARITY      0x08

#define LCR_BITS8           0x03
#define LCR_BITS7           0x02
#define LCR_BITS6           0x01
#define LCR_BITS5           0x00

#define LCR_STOP_BITS1      0x00
#define LCR_STOP_BITS2      0x04

#define FALSE				0
#define TRUE				1
#define false				0
#define true				1

#define NO_ERROR			0       /* No error               */
#define BUF_OVFL			1       /* Buffer overflowed      */

//打开串口设置
//串口号comport:1或2
int SerComOn(int comport);
//设置串口参数波特率
//baud:9600或19200 
//para:LCR_BITS8|LCR_STOP_BITS1|LCR_NO_PARITY(8位数据,停止1位,无校验)
int SetSerCom(int comport, int baud, int para);
//关闭串口
void SerComOff(int comport);
//关闭全部串口
int OffAllSerial(void);
//发送字符
void SendChar(int comport,int cc);
//发送字符串
void SendChars(int comport,unsigned int strlen,unsigned char *buf, unsigned int *sendlen);
//接收字符,非阻塞式,没有数据返回FALSE
int ReceiveChar(int comport, char *ch);

#endif //_SERCOMM_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -