/*
	MGPLCDAC.C

	Send a sawtooth waveform to a XP8600/DAC2 PLCBus expansion board from a
	BL14xx/MicroG and BL15xx/MicroG2.
		
	Uses PIODA on the BL14xx/MicroG and BL15xx/MicroG2 to read/write any 4 bit
	PLCBUS device.

	The following wiring is used:

		PA0      STRB on the PLCBUS
		PA1      D0
		PA2      D1
		PA3      D2
		PA4      D3
		PA5      A1
		PA6      A2
		PA7      A3

		Vcc      Vcc
		Gnd      Gnd.

	The 24v (if needed) to the PLCBUS device should be brought in directly
	to the PLCBUS device.

	In this sample program, 0 to 4095 is repeatedly sent out to the first
	EXP-DAC2 board found on the PLCBUS. 

	You may optionally use the MicroG-to-PLCBus/LCD adapter instead of
	performing the above wiring.
*/

main()  
{
int found_addr, i;
  
	mgreset_pbus();

	found_addr = -1;
	for(i=0;i<64;i++)
	{
		if( mgplc_poll_node(mgplcdac_board(i)))
		{
			found_addr = mgplcdac_board(i);     // found this DAC board
			break;
		}
	}     

	if(found_addr == -1)
	{
		printf("No PLCBUS expansion dac board is found.\n");
	}
	else
	{
		printf("Found DAC Board with board address >> 0x%x.\n", found_addr);
		mgset12adr(found_addr);    // set the address of the DAC board 
		mginit_dac();              // initialize the dac
		mgdac_on();                // turn on the LT1188 if available
		for(;;)
		{
			for (i=0;i<4096;i++)
			{
				hitwd();
				runwatch();
				mgset_dac1(i);
				mgset_dac2(i);
			}
		}
	}
}                    
