/*
	MGSCAN1.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.
*/
	
main()
{
int inJP1;
int inJP2;
int inSW1;
int inSW2;
int outLED1;
int outLED2;
int outBZ1;
int indata; 
int outdata;
								// 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;
		inJP1  = indata & 0x10;
		inJP2  = indata & 0x20;
		inSW1  = indata & 0x40;
		inSW2  = indata & 0x80;


		outLED1 = (inJP1 << 1) & (inSW1>>1);      // LED1 is on if JP1 is installed
																// or SW1 is pressed.
		outLED2 = (inJP2 << 1) & (inSW1);         // LED2 is on if JP2 is installed
																// or SW1 is pressed.
		outBZ1  = inSW2 ;                         // Buzzer sounds if SW2 is pressed.

		
		outdata = outLED1 | outLED2 | outBZ1;
		outport(PIODA, outdata);                  // output all the bits together.
	}
}