/*
	MGSCAN2.C
	
	BL14xx/MicroG or BL15xx/MicroG2

	Scan inputs pins of the MicroG Prototyping board and send the input
	state to corresponding output pins.

	The following wiring is used:

			PA5   to    TP1 or LED1
			PA6   to    TP8 or LED2
			PA7   to    TP4 or Buzzer BZ1

			PB4   to    TP2 or JP1
			PB5   to    TP7 or JP2
			PB6   to    TP3 or SW1
			PB7   to    TP6 or SW2.

	This example illustrates a different way of scanning the IO of the
	MicroG Prototyping board than mgscan1.c.
*/
	
main()
{
int indata; 
									// PIOA is initialized as inputs on power up
	resPIOCA(0xe0);         // upper 3 bits are output
	setPIODA(0xe0);         // Set all outputs to high
	
	while(1)
	{
		
		hitwd();
		runwatch();

		indata = inport(PIODB) & 0xf0;
			
		if((indata & 0x10) && (indata & 0x40))       // check whether JP1 or SW1 is low
			setPIODA(0x20);                           // not low, LED1 output is high, LED off.
		else
			resPIODA(0x20);                           // low, LED1 output is low, LED on.

		if((indata & 0x20) && (indata & 0x40))       // check whether JP2 or SW1 is low
			setPIODA(0x40);                           // not low, LED2 output is high, LED off.
		else
			resPIODA(0x40);                           // low, LED2 output is low, LED on.

		if((indata & 0x80))                          // check whether SW2 is low.
			setPIODA(0x80);                           // not low, BUZ output is high, BUZZER off.
		else
			resPIODA(0x80);                           // low, BUZ output is low, BUZZER on.
	}
}