

	basic.CLK = CLK;
	basic.DAT = DAT;
	basic.RST = RST;
	basic =
	#include "basic.txt"
	
	//以下变量存放时间信息,分配在ds1302中(虚拟变量)
	
	//[i] var_int32 year;
	public v_ds1302user int32 year =	#addr 0b1000_1100; 	//年
	//[i] var_int32 month;
	public v_ds1302user int32 month =	#addr 0b1000_1000;	//月份
	//[i] var_int32 day;
	public v_ds1302user int32 day =	#addr 0b1000_0110; 	//天
	//[i] var_int32 hour;
	public v_ds1302user int32 hour =	#addr 0b1000_0100; 	//小时
	//[i] var_int32 minute;
	public v_ds1302user int32 minute =	#addr 0b1000_0010;	//分
	//[i] var_int32 second;
	public v_ds1302user int32 second =	#addr 0b1000_0000; 	//秒
	//[i] var_int32 week;
	public v_ds1302user int32 week =	#addr 0b1000_1010; 	//星期
	
	public v_ds1302 uint8 byte_second =		#addr 0b1000_0000; 	//底层秒
	public v_ds1302 uint8 byte_control =	#addr 0b1000_1110; 	//控制
	public v_ds1302 uint8 byte_charge =		#addr 0b1001_0000; 	//涓流充电
	
	//---------------------------------------------------
	//初始化
	//[i] function_void OS_init;
	public void OS_init()
	{
		basic.OS_init();
		
		//初始化, 注意需要加上写保护开关
		byte_control = 0x00;
		byte_second = byte_second & 0B0111_1111;
		byte_charge = 0B1010_1011;
		byte_control = 0x80;
		
		OS_time = 50;
		last_time = 0;
		OS_EventFlag = 0;
		
		isSafe = true;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		if( !isSafe ) return;
		
		uint8 current_time = basic.get_uint8( 0b1000_0000 );
		if( last_time != current_time ) {
			OS_EventFlag.0(bit) = 1;
			last_time = current_time;
		}
	}
	
	//---------------------------------------------------
	void set_uint32( uint8 addr, uint32 data0 )
	{
		//这里通过取余运算连同年份的 20XX 前缀也消去了
		data0 % 100;
		
		uint8 data = (uint8)(uint16)data0;
		uint8 d = (data/10) << 4 + data%10;
		
		isSafe = false;
		byte_control = 0x00;
		basic.set_uint8( addr, d );
		byte_control = 0x80;
		isSafe = true;
	}
	uint32 get_uint32( uint8 addr )
	{
		isSafe = false;
		uint8 d = basic.get_uint8( addr );
		isSafe = true;
		
		d = (d>>4)*10 + d&0x0f;
		if( addr == 0b1000_1100 ) {
			return 2000 + d;
		} else {
			return d;
		}
	}
	//---------------------------------------------------
	//虚拟变量类型,用于在ds1302中定义变量,读写接口指向basic
	memory v_ds1302
	{
		target = basic;
		type = [ uint8 ] uint8;
	}
	//虚拟变量类型,用于在ds1302中定义整数变量,读写接口指向所在组件
	memory v_ds1302user
	{
		type = [ uint8 ] uint32;
	}



