
unit H595
{
	public link unit D {}
	public link unit L {}
	public link unit C {}
	
	//[i] function_void OS_init;
	public void OS_init()
	{
		D.D0_DIR = 1;
		D.D0_OUT = 0;
		
		L.D0_DIR = 1;
		L.D0_OUT = 0;
		
		C.D0_DIR = 1;
		C.D0_OUT = 0;
	}
	
	void send_byte( uint8 data )
	{
		loop( 8 ) {
			D.D0_OUT = data.7(bit);
			data << 1;
			C.D0_OUT = 1;
			C.D0_OUT = 0;
		}
	}
	
	//---------------------------------------------
	void set_uint8( uint8 addr, uint8 b )
	{
		uint16 shift = 1;
		if( b != 0 ) {
			back_data | ( shift << addr );
		}
		else {
			back_data & ~( shift << addr );
		}
		send_byte( back_data.8(uint8) );
		send_byte( back_data.0(uint8) );
		
		L.D0_OUT = 1;
		L.D0_OUT = 0;
	}
	
	//---------------------------------------------
	uint8 get_uint8( uint8 addr )
	{
		uint16 shift = 1;
		if( back_data & ( shift << addr ) != 0 ) {
			return 1;
		}
		else {
			return 0;
		}
	}
	
	//---------------------------------------------
	memory my_bit { type = [ uint8 0, 255 ] uint8; }
	//memory my_uint8 {}
	
	//端口缓冲区数据
	uint16 back_data;
}

	//---------------------------------------------
	void set_uint8( uint8 addr, uint8 data )
	{
		if( addr == 0 ) {
			driver.back_data.0(uint8) = data;
		}
		else {
			driver.back_data.8(uint8) = data;
		}
		driver.send_byte( driver.back_data.8(uint8) );
		driver.send_byte( driver.back_data.0(uint8) );
		driver.L.D0_OUT = 1;
		driver.L.D0_OUT = 0;
	}
	
	//---------------------------------------------
	uint8 get_uint8( uint8 addr )
	{
		if( addr == 0 ) {
			return driver.back_data.0(uint8);
		}
		else {
			return driver.back_data.8(uint8);
		}
	}

//空端口
uint8 NULL_uint8;
bit NULL_bit;

public memory my_uint8 {}

//图形化配置端口
public my_uint8 uint8 D0_OUT = #addr 0; public link uint8 D0_IN = D0_OUT; public link uint8 D0_DIR = NULL_uint8;
public my_uint8 uint8 D1_OUT = #addr 1; public link uint8 D1_IN = D1_OUT; public link uint8 D1_DIR = NULL_uint8;

D_0.my_bit = driver.my_bit;
D_0.NULL_bit = NULL_bit;
public unit D_0
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 0; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}
D_1.my_bit = driver.my_bit;
D_1.NULL_bit = NULL_bit;
public unit D_1
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 1; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}
D_2.my_bit = driver.my_bit;
D_2.NULL_bit = NULL_bit;
public unit D_2
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 2; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

D_3.my_bit = driver.my_bit;
D_3.NULL_bit = NULL_bit;
public unit D_3
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 3; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

D_4.my_bit = driver.my_bit;
D_4.NULL_bit = NULL_bit;
public unit D_4
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 4; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

D_5.my_bit = driver.my_bit;
D_5.NULL_bit = NULL_bit;
public unit D_5
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 5; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

D_6.my_bit = driver.my_bit;
D_6.NULL_bit = NULL_bit;
public unit D_6
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 6; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

D_7.my_bit = driver.my_bit;
D_7.NULL_bit = NULL_bit;
public unit D_7
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 7; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_0.my_bit = driver.my_bit;
DD_0.NULL_bit = NULL_bit;
public unit DD_0
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 8; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}
DD_1.my_bit = driver.my_bit;
DD_1.NULL_bit = NULL_bit;
public unit DD_1
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 9; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}
DD_2.my_bit = driver.my_bit;
DD_2.NULL_bit = NULL_bit;
public unit DD_2
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 10; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_3.my_bit = driver.my_bit;
DD_3.NULL_bit = NULL_bit;
public unit DD_3
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 11; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_4.my_bit = driver.my_bit;
DD_4.NULL_bit = NULL_bit;
public unit DD_4
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 12; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_5.my_bit = driver.my_bit;
DD_5.NULL_bit = NULL_bit;
public unit DD_5
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 13; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_6.my_bit = driver.my_bit;
DD_6.NULL_bit = NULL_bit;
public unit DD_6
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 14; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}

DD_7.my_bit = driver.my_bit;
DD_7.NULL_bit = NULL_bit;
public unit DD_7
{
	public link memory my_bit {}
	public link bit NULL_bit;
	public my_bit bit D0_OUT = #addr 15; public link bit D0_IN = D0_OUT; public link bit D0_DIR = NULL_bit;
	public void OutputMode() {}
	public const uint8 TYPE = 10;
}


