/************************************************
 * Universal Library Demo Program				*
 *                                              *
 * Christian Schmidt, 1/26/2004                 *
 * schmidt@ece.ucsb.edu                         *
 ************************************************/

/* Include files */
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include "cbw.h"

void wait(int ticks);

void wait(ticks)
{	clock_t t1;

	t1 = clock();
	while (clock() - t1 < ticks) ;
}

void main()
{	// Local Variables
	const int BoardNum = 0;
	float RevLevel = (float) CURRENTREVNUM;
	clock_t t1, t2;
    USHORT portA_val, portCL_val;
	int done;

	// I/O Board Initialization
	cbDeclareRevision(&RevLevel);
	cbErrHandling(PRINTALL, STOPALL);
	cbDConfigPort(BoardNum, FIRSTPORTA, DIGITALIN);
	cbDConfigPort(BoardNum, FIRSTPORTB, DIGITALOUT);

	//
	printf("cbDIn() and cbDOut() Demonstration\n");
	printf("Press any key to end program\n\n");


	// Run until some key hit
	while (!kbhit())
	{	// Port-wise I/O: read input from port A
		cbDIn(BoardNum, FIRSTPORTA, &portA_val);
		printf("Port A: %d\n", portA_val);

		// Wait for 1/5th second
		wait(CLOCKS_PER_SEC / 5);

		// Output current status to FPGA board
		cbDOut(BoardNum, FIRSTPORTB, portA_val);
	}
}
