📄 com.h
字号:
#ifndef COM_H
#define COM_H
#include <dos.h>//#include "nvgt.h"
#if !defined(_WIN32)
#define COM1 0
#define COM2 1
#define COM1_INT_NO 0x0C
#define COM2_INT_NO 0x0B
#define COM1_INT_MASK 0x10
#define COM2_INT_MASK 0x08
#define COM1_BASE_ADRR 0x3f0
#define COM2_BASE_ADRR 0x2f0
#define COM_THR 0x08
#define COM_RHR 0x08
#define COM_LSB 0x08
#define COM_MSB 0x09
#define COM_IER 0x09
#define COM_IIR 0x0A
#define COM_LCR 0x0B
#define COM_MCR 0x0C
#define COM_LSR 0x0D
#define COM_MSR 0x0E
#define BAUD_300 0x0180
#define BAUD_600 0x00C0
#define BAUD_1200 0x0060
#define BAUD_2400 0x0030
#define BAUD_3600 0x0020
#define BAUD_4800 0x0018
#define BAUD_7200 0x0010
#define BAUD_9600 0x000C
#define BAUD_14400 0x0008
#define BAUD_19200 0x0006
#define BAUD_28800 0x0004
#define BAUD_38400 0x0003
#define BAUD_57600 0x0002
#define BAUD_115200 0x0001
/* ///////////////////////////// LCR */
#define DLAB 0x80
#define BREAK 0x40
#define PARITY_NO 0x00
#define PARITY_ODD 0x08
#define PARITY_EVEN 0x18
#define PARITY_1 0x28
#define PARITY_0 0x38
#define STOP_BIT1 0x00
#define STOP_BIT2 0x04
#define DATA_BIT5 0x00
#define DATA_BIT6 0x01
#define DATA_BIT7 0x02
#define DATA_BIT8 0x03
/* ///////////////////////////// IER */
#define INT_MSK_MODEM 0x08
#define INT_MSK_ERR 0x04
#define INT_MSK_TX 0x02
#define INT_MSK_RX 0x01
/* ///////////////////////////// IIR */
#define INT_SCR_NO 0x01
#define INT_SCR_ERR 0x06
#define INT_SCR_RX 0x04
#define INT_SCR_TX 0x02
#define INT_SCR_MODEM 0x00
extern int com1TX, com2TX, com1RX, com2RX, com1TXBusy, com2TXBusy;
/* the folloing function is not alwayse needed to user */
#define WriteCOM1(c) outportb(COM1_BASE_ADRR+COM_THR, (c))
#define ReadCOM1() inportb(COM1_BASE_ADRR+COM_RHR)
#define WriteCOM2(c) outportb(COM2_BASE_ADRR+COM_THR, (c))
#define ReadCOM2() inportb(COM2_BASE_ADRR+COM_RHR)
void BaudRate(int comPort, int baud); /* comPort=0 for COM1, comPort=1 for COM2, */
void DataFormat(int comPort, unsigned char format);
void InterruptType(int comPort, unsigned char intType);
void interrupt ( *MountISR(int comPort, void interrupt (*pNew)(void)) );
void interrupt COM1ISR(void);
void interrupt COM2ISR(void);
/* user call the following two functions to initialize COM or close COM */
void OpenCOM(int comPort, int baud, unsigned char format, unsigned char intType);
void CloseCOM(int comPort);
void StartSend(int comPort, unsigned char comTransBuf[], int lenBuf);
/* user must program the following two functions in file 'COMUser.C' */
void COM1RX(unsigned char c);
void COM2RX(unsigned char c);
#endif /* _WIN32 */
#define EX_INV 0
char* i2s(short int i, char s[]);
char* l2s(long l, char s[]);
char* f2s(float f, char s[]);
char* d2s(double d, char s[]);
short int s2i(char s[]);
long s2l(char s[]);
float s2f(char s[]);
double s2d(char s[]);
unsigned char CheckSum(unsigned char data[], int length);
unsigned int CheckSum1 (unsigned char data[], int length, unsigned char sum);
unsigned short CRC16(unsigned char *frame, int frameLen);
char* str2frm(char *str, char *frm, int len);
char* frm2str(char *frm, char *str, int len);
#endif /* COM_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -