

	inter.INT_event = INT_event;
	const uint8 OS_channel_ID = CLK.INT_INDEX;
	inter.OS_channel_INT = OS_channel_ID;
	inter =
	#include "$chip$_interrupt.txt"
	
	
	//---------------------------------------------------
	void INT_event000()
	{
		#asm "push r31"
		#asm "push r30"
		
		#asm "push r20"
		#asm "push r21"
		#asm "push r22"
		#asm "push r23"
		#asm "push r24"
		#asm "push r25"
		
		#asm "clr r30"
		#asm "clr r31"
		#asm "sbic &CLK.D0_IN"
		#asm "ser r30"
		#asm "sbis &DT.D0_IN"
		#asm "ser r31"
		
		#asm "cp r30,r31"
		
		#asm "lds r31,&OS_EventFlag"
		#asm "breq @label1"
			#asm "ori r31,2"
			
			#asm "lds r20,&tick"
			#asm "lds r21,&tick+1"
			#asm "lds r22,&tick+2"
			#asm "lds r23,&tick+3"
			#asm "ldi r24,1"
			#asm "clr r25"
			#asm "add r20,r24"
			#asm "adc r21,r25"
			#asm "adc r22,r25"
			#asm "adc r23,r25"
			#asm "sts &tick,r20"
			#asm "sts &tick+1,r21"
			#asm "sts &tick+2,r22"
			#asm "sts &tick+3,r23"
		#asm "jmp @labele"
		#asm "@label1:"
			#asm "ori r31,1"
			
			#asm "lds r20,&tick"
			#asm "lds r21,&tick+1"
			#asm "lds r22,&tick+2"
			#asm "lds r23,&tick+3"
			#asm "subi r20,1"
			#asm "sbci r21,0"
			#asm "sbci r22,0"
			#asm "sbci r23,0"
			#asm "sts &tick,r20"
			#asm "sts &tick+1,r21"
			#asm "sts &tick+2,r22"
			#asm "sts &tick+3,r23"
		#asm "@labele:"
		
		#asm "sts &OS_EventFlag,r31"
		
		#asm "pop r25"
		#asm "pop r24"
		#asm "pop r23"
		#asm "pop r22"
		#asm "pop r21"
		#asm "pop r20"
		
		#asm "pop r30"
		#asm "pop r31"
	}
	void sim()
	{
		
	}
	
	//借鉴网上的资料, 通过状态锁实现了软件滤除硬件跳变干扰, 很稳定!!!
	bool second;
	bit d1;
	bit d2;
	void INT_event()
	{
		if( !second && CLK.D0_IN == 0 ) {
			d1 = DT.D0_IN;
			second = true;
			return;
		}
		if( second && CLK.D0_IN == 1 ) {
			d2 = DT.D0_IN;
			
			if( d1 == 1 && d2 == 0 ) {
				OS_EventFlag.0(bit) = 1;
				tick + 1;
			}
			if( d1 == 0 && d2 == 1 ) {
				OS_EventFlag.1(bit) = 1;
				tick - 1;
			}
			second = false;
		}
	}
	
	
	
	void INT_event111()
	{
		loop( 200 ) {}
		
		bool b = CLK.D0_IN == DT.D0_IN;
		
		if( b ) {
			OS_EventFlag.1(bit) = 1;
			tick - 1;
		}
		else {
			OS_EventFlag.0(bit) = 1;
			tick + 1;
		}
	}

