新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 115.2K串行通信C语言示例

115.2K串行通信C语言示例

作者:时间:2010-09-28来源:网络收藏

unsigned char time_out;

本文引用地址:http://www.eepw.com.cn/article/173198.htm

void init_com1(void) {
outportb(0x3fb,0x80);
outportb(0x3f8,1);
outportb(0x3f9,0x0);
outportb(0x3fb,0x3);
}
void sen_com1(unsigned char d) {
long i;
time_out=0;
while (!(inportb(0x3fd)0x20));
outportb(0x3fd,0x0);
outportb(0x3f8,d);
i=clock();
while (1) {
if (clock()>(i+8)) {time_out=1;return;}
if ((inp(0x3fd)0x1)==1) break;
}
if (inp(0x3f8)!=d) {time_out=2;return;}
}
unsigned char rec_com1(void) {
long i;
unsigned char d;
time_out=0;
i=clock();
while (1) {
if (clock()>(i+8)) {time_out=1;return(0);}
if ((inp(0x3fd)1)==1) break;
}
d=inp(0x3f8);
while (!(inportb(0x3fd)0x20));
outportb(0x3fd,0x0);
outportb(0x3f8,d);
return(d);
}
void main(void) {
int i;
long st;
init_com1();
st=clock();
sen_com1(0xaa);
if (time_out) {printf(CPU not ready!);exit(-1);}
sen_com1(0xaa);
if (time_out) {printf(CPU not ready!);exit(-1);}
for (i=0;i1000;i++) {
sen_com1(i);
if (time_out) {printf(CPU not ready!);exit(-1);}
}
printf(Total use %3.2f S.,(clock()-st)/18.2);
exit(1);
}


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭