#include<stdio.h>
#include<conio.h>
#include"A812.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=5.0/2048.0;
  int c1,c2;

  err=A812_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");
  A812_AD_SetChGainMode(0,A812_BI_1,DMA_MODE);
  A812_Delay(4*2);     /* delay the 4 uS settling time */
  c1=6;
  c2=6;
  quit=0;
  while(!quit){
     A812_AD_DMA_Start(Buf,1000,c1,c2);
     while(A812_AD_DMA_Status()){
	if(kbhit() && getch()==27) {
	   quit=1;
	   break;
	}
     };
     A812_AD_DMA_Stop();
     if(kbhit() && getch()==27) break;
     printf("\n----- press ESC to STOP -----\n");
     for(i=0;i<1000;i+=100){
	 Buf[i]&=0xfff;   /* in DMA mode must change bit 12 to 0 */
     printf("[%3d]:[%x]:%6.3f\n",i,Buf[i],rate*(Buf[i]-2048));
     }
     delay(1000);
  }
}
