
//¶ȼоƬDS18B20, ޹ش,Ҫصײ

unit ds18b20
{
	public const uint16 ID = 0;
	
	public link unit DS {}
	
	#include "$run$.txt"
	
	bool Integer_isOK;
	int8 Integer;
	
	bool Float_isOK;
	int8 Float;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		port_init();
		
		//䵼ϵͳ޷͵Կؼͬ(ֱ)
		//2014.1.9 22:53 ղʱȻ뵽Ϊʲô, Ϊڵײдִжκʹ...
		
		//һβ
		//start_sd();
		//к
		//write_byte( 0xcc );
		//¶ת
		//write_byte( 0x44 );
	}
	//---------------------------------------------------
	//[i] function_int32 get_integer;
	public int32 get_integer()
	{
		if( !Integer_isOK ) {
			Refresh();
		}
		Integer_isOK = false;
		return Integer;
	}
	//---------------------------------------------------
	//[i] function_int32 get_float;
	public int32 get_float()
	{
		if( !Float_isOK ) {
			Refresh();
		}
		Float_isOK = false;
		return Float;
	}
	//---------------------------------------------------
	//[i] function_int32 get_temperature;
	
	//...
	
	void Refresh()
	{
		int32 data = get_temperature();
		if( data < 0 ) {
			Integer = (int8)(int16)(data/16);
			Float = (int8)(int16) ((-data%16)*10/16);
		}
		else {
			Integer = (int8)(int16)(data/16);
			Float = (int8)(int16) ((data%16)*10/16);
		}
		Integer_isOK = true;
		Float_isOK = true;
	}
}























