/*

RTCPER.C:

This program demonstrates how to set up the RTC to generate
periodic interrupts. Compile the program and run with F9.
Then add the watch expression "count" to the watch list.
Type control-U repeatedly to see the value change. The
variable count should be incremented 256 times in a second.

*/

#use eziolp31.lib

unsigned count;

#JUMP_VEC RST38_VEC int0ISR

interrupt reti void int0ISR() {
	auto int flags;
	flags = rtcRdRegC();					//	reading register C clears the periodic
												//	interrupt flag (to release IRQ)
	if (flags & 0x40) {
		++count;								//	to indicate we've been here...
	}
}

main() {
	rtcInit();

	//	clear all interrupt enable
	rtcSwAIE(0);
	rtcSwKSE(0);
	rtcSwPIE(0);
	rtcSwUIE(0);
	rtcSwRIE(0);
	rtcSwWIE(0);

	//	clear all interrupt status flags
	rtcClrIRQ();

	rtcSetPIRate(0x01);			//	set up for 256Hz

	rtcIRQ(1);						//	enable INT0 to receive RTC IRQ

	rtcSwPIE(1);					//	now enable interrupt

	while (1) {
		runwatch();					//	update the "count" watch expression
		hitwd();
	}
}