📄 pcuart.h
字号:
#define True 1
#define False 0
void iniccom(int portadd,unsigned int speed,int parity,int data,int stop,int intrmode);
void computc(int,char);
char comgetc(int);
char Send_ready(int portadd);
char Rece_ready(int portadd);
/*
portadd(int) ------ 端口地址: 0x00--0xffff
speed(unsigned int) ------ 波特率: 600 -- 57600
parity(int) ------ 奇偶校验: 0-(无)
1-(奇)
2-(偶)
3-(奇偶位保持传号)
4-(奇偶位保持空号)
data(int) ------ 数据位数: 5-8
stop(int) ------ 停止位长度: 1
2
intrmode(int) ------ 接收中断允许: 0-不允许
1-允许。
------ 初始化串行口函数
*/
void iniccom(int portadd,unsigned int speed,int parity,int data,int stop,int intrmode)
{
unsigned char msb,lsb,com_mode,intrmode1;
portadd = portadd/8*8;
switch(speed) /* 转换波特率 */
{
case 50:
msb = 0x09;
lsb = 0x00;
break;
case 75:
msb = 0x06;
lsb = 0x00;
break;
case 110:
msb = 0x04;
lsb = 0x17;
break;
case 150:
msb = 0x03;
lsb = 0x00;
break;
case 300:
msb = 0x01;
lsb = 0x80;
break;
case 600:
msb = 0x00;
lsb = 0xc0;
break;
case 1200:
msb = 0x00;
lsb = 0x60;
break;
case 1800:
msb = 0x00;
lsb = 0x40;
break;
case 2000:
msb = 0x00;
lsb = 0x3a;
break;
case 2400:
msb = 0x00;
lsb = 0x30;
break;
case 3600:
msb = 0x00;
lsb = 0x20;
break;
case 4800:
msb = 0x00;
lsb = 0x18;
break;
case 7200:
msb = 0x00;
lsb = 0x10;
break;
case 9600:
msb = 0x00;
lsb = 0x0c;
break;
case 19200:
msb = 0x00;
lsb = 0x06;
break;
case 38400:
msb = 0x00;
lsb = 0x03;
break;
case 57600:
msb = 0x00;
lsb = 0x02;
break;
case 0:
msb = 0x00;
lsb = 0x00;
break;
default:
msb = 0x00;
lsb = 0x0c;
break;
}
com_mode = 0x06;
com_mode = com_mode|0x38; /* 以下为设置奇偶较验 */
switch(parity)
{
case 0: /* 无较验 */
com_mode = com_mode&0xc7;
break;
case 1: /* 奇较验 */
com_mode = com_mode&0xc8;
break;
case 2: /* 偶较验 */
com_mode = com_mode&0xd8;
break;
case 3: /* 奇较验保持传号 */
com_mode = com_mode&0xe8;
break;
case 4: /* 偶较验保持空号 */
com_mode = com_mode&0xf8;
break;
default:
com_mode = com_mode&0xc7;
}
switch(stop) /* 设置停止位 */
{
case 1:
com_mode = com_mode&0xfb;
break;
case 2:
com_mode = com_mode|0x04;
break;
default:
com_mode = com_mode&0xfb;
}
com_mode = com_mode&0xfc; /* 设置数据位数 */
switch(data)
{
case 5:
com_mode = com_mode|0x00;
break;
case 6:
com_mode = com_mode|0x01;
break;
case 7:
com_mode = com_mode|0x02;
break;
case 8:
com_mode = com_mode|0x03;
break;
default:
com_mode = com_mode|0x03;
}
com_mode = com_mode&0x7f;
/* com_mode 转换完毕 */
switch(intrmode)
{
case 0:
intrmode1 = 0x07;
break;
default:
intrmode1 = 0x0F;
}
/* 以下为初始化命令部分 */
outportb(portadd+3,0x80); /* 初始化命令 */
outportb(portadd ,lsb); /* 设置波特率因子低字节 */
outportb(portadd+1,msb); /* 设置波特率因子高字节 */
outportb(portadd+3,com_mode); /* 设置串行口状态 */
/*outportb(portadd+4,intrmode1|0x10); /* 输出MODEM控制寄存器 ?remove */
outportb(portadd+1,(char)intrmode); /* 输出中断控制字节 */
outportb(portadd+4,intrmode1); /* 输出MODEM控制寄存器 */
inportb(portadd+5);
inportb(portadd);
delay(10);
}
/*字符发送函数:查询端口状态,直至空闲后将字符送出.*/
void computc(int portadd,char c)
{
int temp;
while(((inportb(portadd+5))&0x20)==0);
outportb(portadd,c); /* 将字符送端口 */
}
char comgetc(int portadd)
{
int temp;
unsigned char status;
status = inportb(portadd+5);
if(status&0x01)
{
return(inportb(portadd));
}
else
{
return(0x13);
}
}
char Send_ready(int portadd)
{
if((inportb(portadd+5)&0x20)==1)
return (True);
else
return(False) ;
}
char Rece_ready(int portadd)
{
if((inportb(portadd+5)&0x01)==1)
return(True); /* is ready */
else
return(False); /* not ready */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -