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

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

void main(void)
{ int err;
  int quit=0;
  int i;
  float rate=10.0/32768.0;    // 16bits <--> +-10V
  int c1,c2;

  err=A826_Initialize(0,Base,Dma,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 [DMA test]\n");
  A826_AD_SetChGainMode(0,A826_BI_1,DMA_MODE);
  c1=6;
  c2=6;
  quit=0;
  while(!quit){
     A826_AD_DMA_Start(Buf,1000,c1,c2);
     while(A826_AD_DMA_Status()){
        if(kbhit() && getch()==27) {
           quit=1;
           break;
        }
     }
     A826_AD_DMA_Stop();
     if(kbhit() && getch()==27) break;
     for(i=0;i<1000;i+=100){
         cprintf("[%3d]%6.4f\n\r",i,rate*Buf[i]);
     }
  }
}
