
//液晶屏元件,处理器无关代码

unit lcd1602
{
	public const int32 Addr = 0x27;
	
	public link unit SCL {}
	public link unit SDA {}
	
	uint8 DATA;
	link bit RS_OUT = DATA.0(bit);
	link bit RW_OUT = DATA.1(bit);
	link bit E_OUT = DATA.2(bit);
	link bit LIHGT_OUT = DATA.3(bit);
	link bit D_4_OUT = DATA.4(bit);
	link bit D_5_OUT = DATA.5(bit);
	link bit D_6_OUT = DATA.6(bit);
	link bit D_7_OUT = DATA.7(bit);
	
	PCF8574.SDA_DIR = SDA.D0_DIR;
	PCF8574.SDA_IN = SDA.D0_IN;
	PCF8574.SDA_OUT = SDA.D0_OUT;
	PCF8574.SCL_DIR = SCL.D0_DIR;
	PCF8574.SCL_OUT = SCL.D0_OUT;
	PCF8574 =
	#include <system\common\PCF8574.txt>
	
	PCF8574.Addr = Addr;
	
	public void port_init()
	{
		PCF8574.OS_init();
		LIHGT_OUT = 1;
		RS_OUT = 0;
		RW_OUT = 0;
		E_OUT = 0;
		D_4_OUT = 0;
		D_5_OUT = 0;
		D_6_OUT = 0;
		D_7_OUT = 0;
		PCF8574.set_data( DATA );
	}
	public void send_data( uint8 data )
	{
		RS_OUT = 1;
		RW_OUT = 0;
		send_byte( data );
	}
	public void send_command( uint8 com )
	{
		RS_OUT = 0;
		RW_OUT = 0;
		send_byte( com );
	}
	//更新数据
	public void send_default()
	{
		PCF8574.set_data( DATA );
	}
	//---------------------------------------------------
	void send_byte( uint8 b )
	{
		D_4_OUT = b.4(bit);
		D_5_OUT = b.5(bit);
		D_6_OUT = b.6(bit);
		D_7_OUT = b.7(bit);
		PCF8574.set_data( DATA );
		
		E_OUT = 1;
		PCF8574.set_data( DATA );
		E_OUT = 0;
		PCF8574.set_data( DATA );
		
		D_4_OUT = b.0(bit);
		D_5_OUT = b.1(bit);
		D_6_OUT = b.2(bit);
		D_7_OUT = b.3(bit);
		PCF8574.set_data( DATA );
		
		E_OUT = 1;
		PCF8574.set_data( DATA );
		E_OUT = 0;
		PCF8574.set_data( DATA );
	}
}






