这段代码用串口控件怎样改写?(100分)

  • 主题发起人 主题发起人 qxwzj
  • 开始时间 开始时间
Q

qxwzj

Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段代码是c写成的,我对c和dos中断不太了解,
谁愿意帮我把它改成用串口控件实现数据接受,万分感谢,
分少可以再加。
#include "stdio.h"
#include "process.h"
#include "math.h"
#include "dos.h"
char *ad ;
char tm=0;
int i,cport;
long l;
void interrupt far timeint()
{tm++;}
void interrupt far newintfun()
{enable();
*(ad+i)=inportb(cport);
tm=0;
i=i++&0x7fff;
l++;
outportb(0x20,0x20);
}
main(argc,argv)
int argc;char *argv[];
{
void (interrupt far *oldintfun)();
void (interrupt far *oldintfun1)();
void (interrupt far *timeold)();
void interrupt far newintfun();
int a,n;
char key;
long A,t=0;
unsigned char c;
unsigned char bu;
FILE *fp;
FILE *fpa;
FILE *fpln;
ad=malloc(0x8000);
oldintfun=getvect(0xc);
oldintfun1=getvect(0xb);
timeold=getvect(0x1c);
setvect(0x1c,timeint);
if((fpa=fopen("awa6218b.buf","wb+"))==NULL)
{ exit(0);}
cport=0x3f8;
if (argc>1){
switch(argv[1][0])
{ case '1':
/* default:*/
disable();
setvect(0xc,newintfun);
enable();
outportb(0x3fb,0x83);
outportb(0x3f8,0x0c);
outportb(0x3f9,0x00);
outportb(0x3fb,0x03);
outportb(0x3f9,0x00);
outportb(0x3fc,0x0b);
key =inportb(0x21);
key =key &0xef;
outportb(0x21,key );
outportb(0x20,0x20);
cport=0x3f8;
break;
case '2':
disable();
setvect(0xb,newintfun);
enable();
outportb(0x2fb,0x83);
outportb(0x2f8,0x0c);
outportb(0x2f9,0x00);
outportb(0x2fb,0x03);
outportb(0x2f9,0x00);
outportb(0x2fc,0x0B);
key =inportb(0x21);
key =key&0xf7;
outportb(0x21,key);
outportb(0x20,0x20);
cport=0x2f8;
break;
}
}
else exit(0);
t=0;
c=inport(cport);
while((inport(cport+5)&0x20)!=0x20)
{if(t>1000000) {
exit(0);}
else
t=t+1;
}
outportb(cport,0x1b);
while((inport(cport+5)&0x1f)==1)
c=inportb(cport);
tm=0;
while((inport(cport+5)&0x20)!=0x20)
{if(tm>10){
exit(0);}
}
for(t=0;t<100000;t++)
t=t;
outportb(cport,0x40);
tm=0;
while((inport(cport+5)&amp;0x20)!=0x20)
{if(tm>10){
exit(0);}
}
printf("/nwait%2d",tm);
while((inport(cport+5)&amp;0x1f)!=1)
{if (tm>10){
exit(0);}
}

c=inport(cport);
if(c!=0xaa)
{
exit(0);
}
tm=0;
i=0;
l=-2;
a=0;
outportb(cport+3,03);
outportb(cport+1,1);
outportb(cport,0x1a);
outportb(0x20,0x20);
while(i!=2)
{if(tm>25)
{
exit(0);}
}
A=(long)((int)ad[0]*128+(int)(ad[1]-16))*256;
while(l<A)
{
while(i!=a)
{
fputc(ad[a],fpa);
a=(a++)&amp;0x7fff;
}
printf("%2d/b/b",l*100/A);
if(tm>40)
{
setvect(0x1c,timeold);
setvect(0xb,oldintfun1);
setvect(0xc,oldintfun);
exit(0);
}

}
fputc('o',fpa);
fclose(fpa);
outport(cport+4,0x0);
if(cport==0x3f8)
setvect(0xc,oldintfun);
else
setvect(0xb,oldintfun1);
setvect(0x1c,timeold);

if((fp=fopen("awa6218b.txt","w+"))==NULL)
{exit(0);}
if((fpln=fopen("static.txt","w+"))==NULL)
{ exit(0);}
fpa=fopen("awa6218b.buf","rb+");
n=0;
a=0;
key=2;
fread(&amp;ad[n],2,1,fpa);
for(t=0;t<A;t=t+256)
{ n=0;
a++;
fread(ad,0x100,1,fpa);
switch(ad[0])
{
case 0x0:
case 0x1:
case 0x2:
if(key!=0)
{
fputs ("/n No. Leq L5 L10 L50 L90 L95 SD LAE Lmax Lmin E Tm DATE TIME MODE R W/n",fp);
fputs ("-------------------------------------------------------------------------------------------------------------/n",fp);
/* 000 130.0 130.0 130.0 130.0 130.0 130.0 99.9 130.0 130.0 130.0 0.130 00h00m00s 97-10-10 10:10:10 sta A F/n*/
key=0;
}
fprintf(fpln," No. %03d/n",a);
fprintf(fpln,"(dB) (%)/n");
for(i=0;i<101;i++)
{
fprintf(fpln,"%3d %5.1f/n",i+30,(float)ad[0x30+i]/2);
}
break;
case 0x3:
if(key!=1)
{
fputs ("/n No. 31.5 63Hz 125Hz 250Hz 500Hz 1kHz 2kHz 4kHz 8kHz AP LA DATE TIME MODE R W/n",fp);
fputs ("-------------------------------------------------------------------------------------------------------------/n",fp);
key=1;
}
break;
}

fprintf(fp,"%03d ",a);/*No.*/
fprintf(fp,"%2x%x.%x ",ad[0x12],abs(ad[0x13]/0xf),ad[0x13]&amp;0xf);/*leq 31.5*/
fprintf(fp,"%2x%x.%x ",ad[0x2c],abs(ad[0x2d]/0xf),ad[0x2d]&amp;0xf);/*l5 63*/
fprintf(fp,"%2x%x.%x ",ad[0x14],abs(ad[0x15]/0xf),ad[0x15]&amp;0xf);/*l10 125 */
fprintf(fp,"%2x%x.%x ",ad[0x16],abs(ad[0x17]/0xf),ad[0x17]&amp;0xf);/*l50 250*/
fprintf(fp,"%2x%x.%x ",ad[0x18],abs(ad[0x19]/0xf),ad[0x19]&amp;0xf);/*l90 500*/
fprintf(fp,"%2x%x.%x ",ad[0x2a],abs(ad[0x2b]/0xf),ad[0x2b]&amp;0xf);/*l95 1k*/
fprintf(fp,"%x%x.%x ",ad[0x1a],abs(ad[0x1b]/0xf),ad[0x1b]&amp;0xf);/*sd 2k*/
fprintf(fp,"%2x%d.%x ",ad[0x1c],abs(ad[0x1d]/0xf),ad[0x1d]&amp;0xf);/*lae 4k*/
fprintf(fp,"%2x%d.%x ",ad[0x1e],abs(ad[0x1f]/0xf),ad[0x1f]&amp;0xf);/*lmax 8k*/
fprintf(fp,"%2x%d.%x ",ad[0x20],abs(ad[0x21]/0xf),ad[0x21]&amp;0xf);/*lmin ap*/
switch(ad[0])
{
case 0x0:
fprintf(fp,"%2x.%x%x ",ad[0x22],ad[0x23]/0xf,ad[0x23]&amp;0xf);/*e*/
fprintf(fp,"%02xh%02xm%02xs ",ad[0x26],ad[0x25], ad[0x24]);/*tm*/
fprintf(fp,"%02x-%02x-%02x %02x:%02x:%02x ",ad[0x04],ad[0x05],ad[0x06],ad[0x07],ad[0x08],ad[0x09]);/*date*/
fprintf(fp,"STA ");
break;
case 0x1:
fprintf(fp,"%2x.%x%x ",ad[0x22],ad[0x23]/0xf,ad[0x23]&amp;0xf);/*e*/
fprintf(fp,"%02xh%02xm%02xs ",ad[0x26],ad[0x25], ad[0x24]);/*tm*/
fprintf(fp,"%02x-%02x-%02x %02x:%02x:%02x ",ad[0x04],ad[0x05],ad[0x06],ad[0x07],ad[0x08],ad[0x09]);/*date*/
fprintf(fp,"24h%2d",ad[0x27]);
break;
case 0x2:
fprintf(fp,"%2x.%x%x ",ad[0x22],ad[0x23]/0xf,ad[0x23]&amp;0xf);/*e*/
fprintf(fp,"%02xh%02xm%02xs ",ad[0x26],ad[0x25], ad[0x24]);/*tm*/
fprintf(fp,"%02x-%02x-%02x %02x:%02x:%02x ",ad[0x04],ad[0x05],ad[0x06],ad[0x07],ad[0x08],ad[0x09]);/*date*/
fprintf(fp,"IEC ");
break;
case 0x3:
fprintf(fp,"%2x%x.%x ",ad[0x22],ad[0x23]/0xf,ad[0x23]&amp;0xf);/*la*/
fprintf(fp," ");/*tm*/
fprintf(fp,"%02x-%02x-%02x %02x:%02x:%02x ",ad[0x04],ad[0x05],ad[0x06],ad[0x07],ad[0x08],ad[0x09]);/*date*/
fprintf(fp,"OCT ");
break;
default:
fprintf(fp," ");
break;
}
switch(ad[3])
{
case 0x00:
default:
fprintf(fp," F A ");
break;
case 0x01:
fprintf(fp," F C ");
break;
case 0x02:
fprintf(fp," F L ");
break;
case 0x03:
fprintf(fp," F E ");
break;
case 0x10:
fprintf(fp," S A ");
break;
case 0x11:
fprintf(fp," S C ");
break;
case 0x12:
fprintf(fp," S L ");
break;
case 0x13:
fprintf(fp," S E ");
break;
}
fprintf(fp,"/n");
}
fclose(fp);
fclose(fpln);
fclose(fpa);
exit(0);
}
 
难啊!关注
 
代码是否正确,正确的话改成C DLL再调用不好。。?
 
上面的代码就算改成C DLL,在WIN2K下也可能用不了。
 
已基本解决,谢谢各位!
 
后退
顶部