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

int Base=0x220;
int Irq=15;
int Buf[1000];
int wCardMode;

void main(void)
{ int err;
  int quit=0;
  int i;
  float rate=5.0/2048.0;
  int c1,c2;
  int NowCount;
  wCardMode=A822_SetCardModel(A8112_Mode);
  err=A822_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;
  }
  printf("\nCard 0 [interrupt test]\n");

  /*Warring:A8112 only support Single-End*/
  A822_AD_SetChGainMode(0,A822_BI_1,INTERRUPT_MODE);
  c1=20;
  c2=20;
  while(!quit){
        A822_AD_INT_Start(Buf,1000,c1,c2);
        do {
           NowCount=A822_AD_INT_Count();
           if(kbhit() && getch()==27) {
              quit=1;
              break;
           }
        } while( NowCount<1000 );
        A822_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));
        }
  }
}
