

//温度湿度检测芯片AM2301 (DHT11), 处理器无关代码,需要加载底层驱动

unit AM2301
{
	public const uint16 ID = 0;
	
	public link unit DS {}
	
	public link bit DS_OUT = DS.D0_OUT;
	public link bit DS_IN = DS.D0_IN;
	public link bit DS_DIR = DS.D0_DIR;
	
	//[i] var_uint8 OS_time;
	public uint8 OS_time;
	
	int32 v_wendu;
	int32 v_shidu;
	bool NeedRefresh;
	
	uint8 tick;
	
	//---------------------------------------------------
	//[i] function_void OS_init;
	public void OS_init()
	{
		DS_DIR = 1;
		DS_OUT = 1;
		OS_time = 250;
		NeedRefresh = true;
	}
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		tick + 1;
		if( tick == 10 ) {
			tick = 0;
			if( NeedRefresh ) {
				NeedRefresh = false;
				uint32 d = read();
				uint32 u_wendu = d.8(uint8);
				uint32 u_shidu = d.24(uint8);
				
				#asm "cli"
				v_wendu = (int)u_wendu;
				v_shidu = (int)u_shidu;
				#asm "sei"
			}
		}
	}
	//---------------------------------------------------
	//[i] function_int32 wendu;
	public int32 wendu()
	{
		NeedRefresh = true;
		return v_wendu;
	}
	//---------------------------------------------------
	//[i] function_int32 shidu;
	public int32 shidu()
	{
		NeedRefresh = true;
		return v_shidu;
	}
	//=================================================================================
	
	#include "$run$.txt"
}














































