/*****************************************************

	EXTINT_300O.C
	Z-World, 2002

	This program demonstrates how to use the external
	interrupt lines to trigger an interrupt
	service routine (ISR) in your code for the
	Rabbit 3000 CPU.  Unlike the Rabbit 2000 CPU, both
	external interrupts are available for use on the
	Rabbit 3000.
   
	Two input lines should be attached to parallel port
	E pins 0 and 1 for this example.  The program will
	separately count pulses on both input line until
	20 pulses are counted on one of them.
	
   The "interrupt" keyword is used to create an ISR in C code.

******************************************************/

char count0, count1;

void my_isr0();
void my_isr1();

main()
{
	count0 = 0;
	count1 = 0;
	
	WrPortI(PEDDR, &PEDDRShadow, 0x00);	// set port E as all inputs

	SetVectExtern3000(0, my_isr0);
	SetVectExtern3000(1, my_isr1);

	WrPortI(I0CR, &I0CRShadow, 0x09);		// enable external INT0 on PE0, rising edge, priority 1
	WrPortI(I1CR, &I1CRShadow, 0x09);		// enable external INT1 on PE1, rising edge, priority 1


	while ((count0 < 20) && (count1 < 20)) {

		// output the interrupt count every second
		costate {
			printf("counts = %3d  %3d\n", count0, count1);
			waitfor(DelaySec(1));
		}
	}

	WrPortI(I0CR, &I0CRShadow, 0x00);				// disable external interrupt 0
	WrPortI(I1CR, &I1CRShadow, 0x00);				// disable external interrupt 1

	// final counts
	printf("counts = %3d  %3d\n", count0, count1);
}


/****** interrupt routines  ******/

nodebug root interrupt void my_isr0()
{
	count0++;
}

nodebug root interrupt void my_isr1()
{
	count1++;
}
