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

	INT0DEMO.C
	Z-World, 2000

	This program demonstrates how to use the Jackrabbit 
	external interrupt lines to trigger an interrupt service 
	routine (ISR) in your code.  Due to a bug in the Rabbit
	2000 interrupt handling (see technical note TN301 on
	the Rabbit Semiconductor web page for more information),
	both external interrupts are used to ensure that no
	interrupts are missed.
   
	An input line should be attached to parallel port E
	pins 4 and 5 for this example.  The program will count
	pulses on that input line until 20 pulses are counted.

   The "interrupt" keyword is used to create an ISR in C code.

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

char count;

void my_isr();

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

	// Note that this function call has changed with version 6.19
	// of Dynamic C.  The first parameter is now the priority level
	// of the external interrupt, and the second is the ISR itself.
	SetVectExtern2000(1, my_isr);

	WrPortI(I0CR, NULL, 0x2B);		// enable external INT0 on PE4, rising edge
	WrPortI(I1CR, NULL, 0x2B);	// enable external INT1 on PE5, rising edge


	while (count < 20) {

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

	WrPortI(I0CR, NULL, 0x00);				// disable external interrupt 0
}


/****** interrupt routine for external interrupt 0 ******/

nodebug root interrupt void my_isr()
{
	count++;
}