再程序末的输出部分
有两个输出
一个是从串口直接读数输出
另一个是把串口的数存到字符串里,然后再一起输出
但是这两个输出的不一样
存到字符串的那组输出比原有的数多些其他的码
各位有时间的话看一下 谢谢
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#define BUFFLEN 1024
void InitCOM();
void OpenPort();
void ClosePort();
void interrupt far asyncint();
void interrupt (*asyncoldvect)();
unsigned char Buffer[BUFFLEN];
int buffin=0;
int buffout=0;
unsigned char ch;
void OpenPort()
{
unsigned char ucTemp;
InitCOM();
asyncoldvect=getvect(0x0c);
disable();
inportb(0x3f8);
inportb(0x3fe);
inportb(0x3fb);
inportb(0x3fa);
outportb(0x3fc,0x08|0x0b);
outportb(0x3f9,0x01);
ucTemp=inportb(0x21)&0xef;
outportb(0x21,ucTemp);
setvect(0x0c,asyncint);
enable();
}
void interrupt far asyncint()
{
unsigned char ch;
Buffer[buffin++]=inportb(0x3f8);
if(buffin>=BUFFLEN)
buffin=0;
outportb(0x20,0x20);
}
void ClosePort(void)
{
disable();
outportb(0x3f9,0x00);
outportb(0x3fc,0x00);
outportb(0x21,inportb(0x21)&0x10);
enable();
setvect(0x0c,asyncoldvect);
}
void InitCOM()
{
outportb(0x3fb,0x80);
outportb(0x3f8,0x06);
outportb(0x3f9,0x00);
outportb(0x3fb,0x03);
outportb(0x3f9,0x01);
}
unsigned char read_char(void)
{
int unch;
if(buffout!=buffin)
{
unch=Buffer[buffout];
buffout++;
if(buffout>=BUFFLEN)
buffout=0;
return(unch);
}
else
return(0xff);
}
void main()
{
unsigned char unChar,unchar;
short bExit_Flag=0;
int a=0;
char b[9];
char c[9]="01234567";
OpenPort();
fprintf(stdout,"\n\nReady to recrive data\n"
"press [ESC] to quite...\n\n");
while(!bExit_Flag)
{
if(kbhit())
{
unChar=getch();
switch(unChar)
{
case 0x1b: bExit_Flag=1;break;
}
}
unChar=read_char();
if(unChar!=0xff)
{
printf("%c",unChar); //从串口直接输出//
b[a]=unChar; //存到字符串//
a++;
}
if(a>=8)
{
printf("\n%s\n",b); //从字符串输出//次输出于直接输出不同,多些其他的码
a=0;
}
}
ClosePort();
}