/*
	BL12DIO.C

	Use with BL1700 boards.
	
	This sample program shows how to access on-board digital inputs and
	outputs by turning 16 outputs on/off and reading and displaying the
	status of the 16 inputs.  LED will flash.
	
	Instructions:

	Bank A are set-up for inputs and Bank B are set-up as outputs. If
	necessary, change the definitions for BANK_A and BANK_B.
	Connect Bank B outputs to LEDs or some device to get a visual.
	Install jumpers on J2, pins 1-3, 2-4 and 7-9 for pulled-up inputs.
	Compile and run this program.
	As the on-board LED flashes, outputs will turn on and off and inputs
	will read high.
*/

#use vdriver.lib
#use eziobl17.lib

#define INS 1
#define OUTS 0
#define BANK_A INS		//bank A inputs
#define BANK_B OUTS		//bank B outputs
#define TURNON 1
#define TURNOFF 0

void FlashLED(void);

main()
{
auto int ionum;
auto int j;

VdInit();			// hits the watchdog periodically
eioBrdInit(0);		// initialize board

if (BANK_A == INS)
	{
	// turn Bank B outputs on and off
	for (ionum=0; ionum<=15; ionum++)
		{
		printf("Turn on Bank B output %d\n", ionum);
		eioBrdDO(BankB(ionum), TURNON);
		for (j=0;j<=5000;j++);
		printf("Turn off\n");
		eioBrdDO(BankB(ionum), TURNOFF);
		FlashLED();
		}
	// read Bank A inputs
	for (ionum=0; ionum<=15; ionum++)
		{
		printf("Status of Bank A input %d is ", ionum);
		printf("%d\n", eioBrdDI(BankA(ionum)));
		FlashLED();
		}
	}
else	// Bank_B == INS
	{
	// turn Bank A outputs on and off
	for (ionum=0; ionum<=15; ionum++)
		{
		printf("Turn on Bank A output %d\n", ionum);
		eioBrdDO(BankA(ionum), TURNON);
		for (j=0;j<=5000;j++);
		printf("Turn off\n");
		eioBrdDO(BankA(ionum), TURNOFF);
		FlashLED();
		}
	// read Bank B inputs
	for (ionum=0; ionum<=15; ionum++)
		{
		printf("Status of Bank B input %d is ", ionum);
		printf("%d\n", eioBrdDI(BankB(ionum)));
		FlashLED();
		}
	}
}

void FlashLED(void)
{
auto int i;
switchLED(TURNON);
for (i=0;i<=5000;i++);
switchLED(TURNOFF);
for (i=0;i<=5000;i++);
}

