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

int Base=0x220;
int Irq=15;
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=A812_Initialize(0,Base,-1,Irq);
  if(err){
     if(err==CheckBoardError){
	printf("Address 0 Error!\n");
     }
     else if(err==CardNumError){
	printf("Card Number Error!(range:0-7)\n");
     }
     return;
  }

  A812_AD_SetChGainMode(0,A812_BI_1,INTERRUPT_MODE);
  A812_Delay(4*2); /* delay 4 uS settling time */
  c1=20;
  c2=20;

  while(!quit){
  printf("\nCard 0 [interrupt test]\n");
	A812_AD_INT_Start(Buf,1000,c1,c2);
	do {
	   NowCount=A812_AD_INT_Count();
	   if(kbhit() && getch()==27) {
	      quit=1;
	      break;
	   }
	} while( NowCount<1000 );
	A812_AD_INT_Stop( );
	if(kbhit() && getch()==27) break;
	for(i=0;i<1000;i+=100){
	    printf("[%3d]%6.3f\n",i,rate*(Buf[i]-2048));
	}
  }
}
