基于C語(yǔ)言的RS232串行接口通信實(shí)現(xiàn)
void Init-COM(int ComPortAddr,unsigned char IntVectNum,im Baud,unsigned char Data,unsigned char Stop,unsigned char Parity)
{
unsigned char High,Low;
int f.
comportaddr=ComPortAddr;
intvectnum=IntVectNum;
CharslnBuf=0;Circln=0;CircOut=0;
/*set baud rate設(shè)置波特率*/
f=(Baud/100):
f=1152/t;High=f/256;
Low=f-High*256;
outportb(ComPortAddr+3,0x80);
outportb(ComPortAddr,LOW);
outportb(ComPortAddr+l,High);
/*set data bits,stop bits,and parity設(shè)置數(shù)據(jù)位。停止位。校驗(yàn)*/
Data=(Data-5)|((Stop-1)*4);
if(Parity=2)Data=Data|0x18;
else if(Parity==1)Data=Data|0x8;
outportb(ComPortAddr+3,Data);
/*set MCR(DTR,RTS=0,OUTl,OUT2=1)設(shè)置MODEM控制位*/
outportb(ComPortAddr+4,0xob);
/*set input data ready interrupt mode設(shè)置輸入數(shù)據(jù)中斷模式*/
outportb(ComPortAddr+1,Ox01);
/*set OC interrupt vector設(shè)置中斷源*/
disable ();
OldAsyncInt=getvect(IntVectNum);
setvect(ImVectNum,AsyncInt);
enable ();
/*open interrupt打開(kāi)中斷*/
maskb=inp(Port8259+1);
if(IntVectNum一0x0c)outport(Port8259+1,maskbOxef);/*INT4*/
else outport(Port8259+1,maskb0xf7);/*INT3*/
}
c語(yǔ)言相關(guān)文章:c語(yǔ)言教程
數(shù)字通信相關(guān)文章:數(shù)字通信原理
通信相關(guān)文章:通信原理
交換機(jī)相關(guān)文章:交換機(jī)工作原理
評(píng)論