

	//加载芯片底层代码
	#include "$chip$.txt"
	
	public void OS_run()
	{
		//...
	}
	
	//=================================================================================
	
	//发送一个数字
	[int8*11] number_buffer;
	public void print_number( int32 data0 )
	{
		//计算正负数
		bool isNeg;
		uint32 data;
		if( data0 >= 0 ) {
			data = (uint)data0;
			isNeg = false;
		}
		else {
			data = (uint)-data0;
			isNeg = true;
		}
		//解析数字到缓冲区中
		int16 i = 0;
		forever {
			int8 ch = '0' + (int)(uint8)(uint16)(data % 10);
			number_buffer[i] = ch;
			i + 1;
			data / 10;
			if( data == 0 ) {
				if( isNeg ) {
					number_buffer[i] = '-';
					i + 1;
				}
				break;
			}
		}
		do {
			i - 1;
			print_byte( number_buffer[i] );
		}
		while( i != 0 );
	}
	
	void print_string( [int8*?] s )
	{
		uint8 i = 0;
		while( s[i] != 0 ) {
			print_byte( s[i] );
			i + 1;
		}
	}
	
	//发送一个字节
	void print_byte( int8 data )
	{
		WAIT_SEND_OK();
		UDR = (uint)data;
	}
	
	//数据接收中断
	uint8 Number;
	INTERRUPT_UART
	void RXC()
	{
		//必须在中断程序中读取 UDR,否则在退出后会重新进入中断
		uint8 d = UDR;
		buffer[length] = d;
		length + 1;
		length % max_length;
		
		if( length == 1 ) {
			if( d != '+' ) {
				length = 0;
			}
			return;
		}
		if( length == 5 ) {
			if( buffer[0] != '+' || buffer[1] != 'I' || buffer[2] != 'P' || buffer[3] != 'D' || buffer[4] != ',' ) {
				length = 0;
			}
			return;
		}
		if( length == 8 ) {
			Number = buffer[7] - '0';
			return;
		}
		if( length <= 9 ) {
			return;
		}
		if( length - 9 == Number ) {
			Data = (int)buffer[9];
			length = 0;
			OS_EventFlag.0(bit) = 1;
		}
	}
	
	

