C语言实现串行通信接口程序
setvect(com[comnum].intbit,coml); //com1
else
setvect(com[comnum].intbit,com2); //com2
//set hard int
Hardinterrupt = inportb(0x21);
if(comnum)
outportb(0x21,Hardinterrupt&0xf7); //com2 ,0
else
outportb(0x21,Hardinterrupt&0xef); //com1 0,
}
void clear interrupt(int comnum)
{
if(comnum)
outportb(0x21,Hardinterrupt | 0x08); //COM2
else
outportb(0x21,Hardinterrupt|0x10); //COM1
setvect(com[comnum].intbit,old_com[comnum]);
for( i=0;i<maxsize;i++) com[comnum].buf[i]='\0';
com[comnum].sendcount=com[comnum].recount=com[comnum].bufh=0;
outportb(com[comnum].portadd+1,0);
outportb(com[comnum].por tadd+4,0x0);
}
void fax2(int i)//i=o,com1; i=1, com2
{ unsigned char mark;
mark=inport(com[i].portadd+2);
do
{
if(mark&0x4)// receive data
{ if (com[i].bufh==maxsize)
com[i].bufh=0; com[i].buf[com[i].bufh++]=inportb(com[i].portadd); com[
i].recount++;}
else if(mark&0x2)// send command
{ if(*com[i].comm)
outportb(com[i].p
ortadd,*com[
com[i],sendcount++;}
else
outportb(com[i].portadd+1,1);
}
}while ((mark=inport([1]. portadd+2))!=1);
outportb(ox20,0x20); //hard int return
}
// interruptmark 1= reoeive, 2=send, 3=rec&send
void comint(int com, char para, int interruptmark)
{
bioscom(0, par, com);
//open com interrupt
outportbv (com[comnum]. portadd+4,0x8;
outportb (com[comnum].portadd+1,interruptmark);
}
void sendcomdata(int comnum,char * command)
{ unsigned char interruptmark;
com[comnum],comm=command;
com[comnum],sendcount=0;
//set send interrupt
interruptmark=inportb (com[comnum].portadd_1);
outportb (com[comnum].portadd+1.(interruptmark|2));
}
//get com_receivedate and clear com_receivebuf,
int getcomdata (int comnum, char * buf)
{ int result=com[comnum]. recount,i:
if(buf)
strncpy(buf,com[comnum].buf,com
[comnum].bufh);
buf[com[comnum].bufh]='\0';
com[comnum].recount=com [comnum].bufh=0;
retun(result);
}
本文链接地址:http://www.oyaya.net/fanwen/view/171881.html
else
setvect(com[comnum].intbit,com2); //com2
//set hard int
Hardinterrupt = inportb(0x21);
if(comnum)
outportb(0x21,Hardinterrupt&0xf7); //com2 ,0
else
outportb(0x21,Hardinterrupt&0xef); //com1 0,
}
void clear interrupt(int comnum)
{
if(comnum)
outportb(0x21,Hardinterrupt | 0x08); //COM2
else
outportb(0x21,Hardinterrupt|0x10); //COM1
setvect(com[comnum].intbit,old_com[comnum]);
for( i=0;i<maxsize;i++) com[comnum].buf[i]='\0';
com[comnum].sendcount=com[comnum].recount=com[comnum].bufh=0;
outportb(com[comnum].portadd+1,0);
outportb(com[comnum].por tadd+4,0x0);
}
void fax2(int i)//i=o,com1; i=1, com2
{ unsigned char mark;
mark=inport(com[i].portadd+2);
do
{
if(mark&0x4)// receive data
{ if (com[i].bufh==maxsize)
com[i].bufh=0; com[i].buf[com[i].bufh++]=inportb(com[i].portadd); com[
i].recount++;}
else if(mark&0x2)// send command
{ if(*com[i].comm)
outportb(com[i].p
ortadd,*com[
i].comm++);
com[i],sendcount++;}
else
outportb(com[i].portadd+1,1);
}
}while ((mark=inport([1]. portadd+2))!=1);
outportb(ox20,0x20); //hard int return
}
// interruptmark 1= reoeive, 2=send, 3=rec&send
void comint(int com, char para, int interruptmark)
{
bioscom(0, par, com);
//open com interrupt
outportbv (com[comnum]. portadd+4,0x8;
outportb (com[comnum].portadd+1,interruptmark);
}
void sendcomdata(int comnum,char * command)
{ unsigned char interruptmark;
com[comnum],comm=command;
com[comnum],sendcount=0;
//set send interrupt
interruptmark=inportb (com[comnum].portadd_1);
outportb (com[comnum].portadd+1.(interruptmark|2));
}
//get com_receivedate and clear com_receivebuf,
int getcomdata (int comnum, char * buf)
{ int result=com[comnum]. recount,i:
if(buf)
strncpy(buf,com[comnum].buf,com
[comnum].bufh);
buf[com[comnum].bufh]='\0';
com[comnum].recount=com [comnum].bufh=0;
retun(result);
}
《C语言实现串行通信接口程序(第3页)》