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

	Generate interrupts on PIO port A.
		
	Set up bits 0 and 1 of PIOA to generate interrupts when a high to
	low transition is seen on either bits. PIOA-3 and PIOA-4 are configured
	outputs to the inputs PIOA-1 and PIOA-2.	Jumper H3, pins 2-4 and 3-5 to
	connect output to input. Outputs will toggle alternately.
*/

char jjj, kkk, state;

main()
{
int toggle;
	
	jjj = kkk = toggle = 0;

	printf("Jumper pins H3, 2-4 and 3-5 to\n");
	printf("generate interrupt on the PIOA port.\n"); 
	outport(ITC, inport(ITC) | 0x01);          // enable INT0

	outport(PIOCA, 0xcf);         // mode 3 for PIOA
	outport(PIOCA,'\B11110011');  // all bits are inputs, except bits 2 & 3
	outport(PIOCA, PIOA_VEC);     // set vector to PIOA
 
	outport(PIOCA,0x97);          // interrupts on, d7 = 1, (0) off
											// or data        d6 = 0, (1) and
											// active low     d5 = 0, (1) high
											// mask follows   d4 = 1, (0) not

	outport(PIOCA, '\B11111100'); // bit is masked out if 1
											// active bits should be zero

	outport(PIODA,0x0f);				// initialize inputs high
	
	while (1)
	{
		hitwd();
		runwatch();
		
		toggle = toggle?0:1;		
		outport(PIODA, toggle?0x07:0x0b);		//toggle PIOA-2 and PIOA-3
		
		if (jjj != kkk)         // test for interrupt  
		{
			printf("Interrupt generated by %s !!! >> %x\n",
					toggle?"PIOA-3":"PIOA-2", inport(PIODA));
			kkk = jjj;
		}
		outport(PIODA,0x0f);						// reset inputs
	}
}

#INT_VEC PIOA_VEC myint

interrupt reti myint()
{
	jjj++;                              // change jjj 
}





