#include<stdio.h>
#include<conio.h>
#include"A821.h"

int Base=0x220;
int Irq=7;
int Buf[1000];

void main(void)
{ int err;
  int quit=0;
  int i;
  float rate=5.0/2048.0;
  int c1,c2;
  int NowCount;

  err=A821_Initialize(0,Base,Irq);
  if(err){
     if(err==CheckBoardError){
	printf("Address 0 Error!\n");
     }
     else if(err==CardNumError){
	printf("Card Number Error!(range:0-7)\n");
     }
     return;
  }
  printf("\nCard 0 [interrupt test]\n");
  A821_AD_SetChGainMode(0,A821_BI_1,INTERRUPT_MODE);
  A821_Delay(23*2);	/* delay the 23 uS settling time */
  c1=20;
  c2=20;
  while(!quit){
	A821_AD_INT_Start(Buf,1000,c1,c2);
	printf("\nPress ESC to stop");
	do {
	   NowCount=A821_AD_INT_Count();
	   if(kbhit()) {
	      getch();
	      A821_AD_INT_Stop( );
	      quit=1;
	      break;
	   }
	} while( NowCount<1000 );
	A821_AD_INT_Stop( );
	for(i=0;i<1000;i+=100){
	    printf("\n[%3d]:[%x]=%6.3f",i,Buf[i],rate*(Buf[i]-2048));
	}
  }
}
