上传者: jklr11
|
上传时间: 2021-11-20 21:00:27
|
文件大小: 288KB
|
文件类型: -
用C语言做的DOS界面的串口通信程序
void setPort(int size, char check, int stop){
unsigned char b = 0x00;
disable();
switch(size){
case 6:b |= 0x01; break;
case 7:b |= 0x02;break;
case 8:b |= 0x03; break;
}
switch(check){
case 'N':
case 'n':b &= ~0x08;break;
case 'J':
case 'j':b |= 0x08; break;
case 'O':
case 'o':b |= 0x18;break;
}
switch(stop){
case 1: b &= ~0x04;break;
case 2: b |= 0x04;break;
}
outportb(PORT[PORTNUM] + 3, b);
/*register interrupt*/
outportb(PORT[PORTNUM] + 1, 0x01);/*接收中断*/
outportb(PORT[PORTNUM] + 4, 0x0b);/*零MODEM,恒有效状态*/
oldhandle = getvect(INTR[PORTNUM]);/*取得硬中断向量表的中断处理程序*/
setvect(INTR[PORTNUM],newhandle);
/*开启IRQx*/
outportb(0x21, inportb(0x21) & INTRENTER[PORTNUM]);
enable();
}
/*
baund:波特率
*/
void initCom(int baund){
unsigned char b;
disable();
outportb(PORT[PORTNUM] + 3, 0x80);/*设DLAB=1*/
outportb(PORT[PORTNUM] + 1, 0X00);/*高八位设0*/
switch(baund){
case 2400:b = 0x30;break;
case 3600:b = 0x20;break;
case 4800:b = 0x18;break;
case 7200:b = 0x10;break;
case 9600:b = 0x0c;break;
}
outportb(PORT[PORTNUM], b);
enable();
}
void closeCom(){
disable();
setvect(INTR[PORTNUM],oldhandle);
enable();
}
void setDefineOpion(){
}
void readOpion(){
}
int AcceptOrRefuse(){
int index=0;
int key = 0;
int ret;
char str[2][7]={"accpet","refuse"};
while(key!=13)
{
gotoxy(12,5+index);
textcolor(15);
printf("%s",str[index]);
index=1-index;
gotoxy(12,5+index);
textcolor(13);
printf("%s",str[index]);
key=bioskey(0);
key=key&0xff;
}
if (index == 0){
ret = 0;
strcpy(sendmsg, "_accept");
strcat(sendmsg, "\0");
sendMessage();
}
else {
ret = 1;
strcpy(sendmsg, "_refuse");
strcat(sendmsg, "\0");
sendMessage();