
	uint16 data_back;
	
	link unit MCU {} = #.MCU;
	
	link uint8 OS_channel_IR = receive.OS_channel_IR;
	
	uint8 index;
	uint8 tick;
	
	//¼µ
	uint8 press_tick;
	
	//¼ݽյʱ䳤,жǷ񰴼ɿ
	uint8 no_data_tick;
	
	inter.INT_event = INT_event;
	inter.OS_channel_INT = OS_channel_IR;
	inter =
	#include "$chip$_interrupt.txt"
	
	timer.time_tick_event = time_tick_event;
	timer =
	#include "$chip$_timer1.txt"
	
	
	void RunInit()
	{
		inter.init();
		timer.init();
		index = 0;
		tick = 0;
		press_tick = 0;
		no_data_tick = 0;
	}
	
	void OS_run()
	{
		
	}
	
	//---------------------------------------------------
	void time_tick_event()
	{
		tick + 1;
		if( tick > 200 ) {
			tick = 0;
			no_data_tick + 1;
			if( no_data_tick >= 5 ) {
				timer.close_interrupt();
				index = 0;
				no_data_tick = 0;
				press_tick = 0;
				if( is_press ) {
					is_press = false;
					OS_EventFlag.1(bit) = 1;
					data = NONE;
				}
			}
		}
	}
	//---------------------------------------------------
	void INT_event()
	{
		no_data_tick = 0;
		
		uint8 t = tick;
		tick = 0;
		index + 1;
		if( index == 1 ) {
			timer.open_interrupt();
			return;
		}
//		if( index == 2 ) {
//			//Ϊ,ý,¼
//			if( t < 125 ) { //115 - 135
//				index = 0;
//				no_data_tick = 0;
//				press_tick + 1;
//				if( press_tick >= 5 ) {
//					if( is_press ) OS_EventFlag.1(bit) = 1;
//					press_tick = 0;
//				}
//			}
//			return;
//		}
		data_back >> 1;
		if( t < 16 ) { // 11 - 22
			data_back.15(bit) = 0;
		} else {
			data_back.15(bit) = 1;
		}
		if( index >= 34 ) {
			//uint8 data_swap = data_back.8(uint8);
			uint8 data_source = data_back.0(uint8);
			int8 temp = switch_code( data_source );
			
			index = 0;
			no_data_tick = 0;
			press_tick = 0;
			if( temp != -1 ) {
				SetFlag( temp );
			}
		}
	}
	//---------------------------------------------------
	//ת
	int8 switch_code( uint8 d )
	{
		for( int8 i = 0; i < KEY_NUMBER; i + 1 ) {
			if( KEY_CODE[i] == d ) return i;
		}
		return -1;
	}

	//ת,ͨתԭʼתΪ淶ֵ,ֵּΪֱ
	const int8 KEY_NUMBER = 21;
	[#.code uint8*KEY_NUMBER] KEY_CODE =
	[
	//ּ 0 - 9
	// 0    1    2    3    4    5    6    7    8    9
	0x16,0x0C,0x18,0x5E,0x08,0x1C,0x5A,0x42,0x52,0x4A,
	
	//ܼ
	//10   11   12   13   14   15   16   17   18   19   20
	0x45,0x46,0x47,0x44,0x40,0x43,0x07,0x15,0x09,0x19,0x0D,
	];


