问题已解决,myint8函数中中断结束指令应该放在最后
但又有新问题
是关于字符输入函数的
#include <dos.h>
#include <stdio.h>
FILE *p;
int a=256;
void interrupt
myint81(void);
void interrupt
myint82(void);
void interrupt
myint83(void);
void
main(void)
{
int i;
char ch;
void interrupt(*oldint)();
Ag: printf("Choose your programm\n");
ch=getchar();
oldint=getvect(0x08);/* 保存旧的中断向量 */
disable();
outportb(0x43,0x36);/* 计数器初始化 */
outportb(0x40,0xef);/* 设置中断间隔 */
outportb(0x40,0x37);
switch(ch)
{
case '1':p=fopen("rice1.dat","w");
setvect(0x08,myint81);
break;
case '2':
p=fopen("rice2.dat","w");
setvect(0x08,myint82);
break;
case '3':
p=fopen("rice3.dat","w");
setvect(0x08,myint83);
break;
default: exit(0);
}
enable();
while(a>0);
setvect(0x08,oldint);
fclose(p);
printf("Continue?\n");
/* scanf("%c\n",&ch); */
ch=getch();/这个地方不管是用getchar,getche还是scanf都没法实现跳转功能,有的还不提醒输入,直接过去了/
if(ch=='y'||ch=='Y')
{
goto Ag;
}
getch();
}
void
interrupt myint81(void)
{
int
dbyte ;
float
ua;
a--;
outportb(0x280,0x00);
do
;
while(!(inportb(0x285)&0x80));/* 采集数据 */
dbyte=inportb(0x281)|((inportb(0x282)&0x0f)<<8);
outportb(0x283,((dbyte)&0x00ff));
outportb(0x284,(((dbyte)>>8)&0x0f));
ua=(dbyte-2047.0)/2048*5;
printf("%d
%.3f\n",dbyte,ua);
fprintf(p,"dbyte=%d
ua=%.3f\r\n",dbyte,ua);
outportb(0x20,0x20);
}
void
interrupt myint82(void)
{
int
dbyte ;
float
ua;
a--;
outportb(0x280,0x00);
do
;
while(!(inportb(0x285)&0x80));/* 采集数据 */
dbyte=inportb(0x281)|((inportb(0x282)&0x0f)<<8);
if(dbyte<2047)
dbyte=4095-dbyte;
outportb(0x283,(dbyte&0x00ff));
outportb(0x284,((dbyte>>8)&0x0f));
ua=(dbyte-2047.0)/2048*5;
printf("%d
%.3f\n",dbyte,ua);
fprintf(p,"dbyte=%d
ua=%.3f\r\n",dbyte,ua);
outportb(0x20,0x20);
}
void
interrupt myint83(void)
{
int
dbyte ;
float
ua;
a--;
outportb(0x280,0x00);
do
;
while(!(inportb(0x285)&0x80));/* 采集数据 */
dbyte=inportb(0x281)|((inportb(0x282)&0x0f)<<8);
if(dbyte>2047)
dbyte=4095-dbyte;
outportb(0x283,(dbyte&0x00ff));
outportb(0x284,((dbyte>>8)&0x0f));
ua=(dbyte-2047.0)/2048*5;
printf("%d
%.3f\n",dbyte,ua);
fprintf(p,"dbyte=%d
ua=%.3f\r\n",dbyte,ua);
outportb(0x20,0x20);
}