void main()
{
	unsigned char display_temp[8];		//显示缓存

	jdq_1 = 1;
	jdq_2 = 1;							//为1时开启
	serial_int(enable, baud9600, disable); //串口初始化
	int_lcd1602( rightmove, cursornotdisplay); //1602初始化
	int_interrupt( 0, negative_jump);		   //外部中断0,下降沿触发
	int_interrupt( 1, negative_jump);
	main_timer(on,0);						//开启定时器
	timer_8_int(0,240,normal);				//定时器设置240个脉冲后溢出,并触发中断
	main_interrupt(on);						//开启总中断

	while(1)
	{
		/*显示控制阈值*/
		display_temp[0] = temp_set%100/10+0x30;	 //任何数字加0x30转换为可以显示的ASCII码
		display_temp[1] = temp_set%10+0x30;
		display_temp[2] = '\0';
		print1602( display_temp, 0,14);
		printchar1602(' ', 1, 15);


		/*读取温度传感器1并显示,当读取温度为85时为错误数据,不显示*/
		ds18b20_1_exist =int_18b20_1();	//判断传感器是否存在
		if( ds18b20_1_exist ==0 )		   //为0时存在
		{
			temperature1 = read_temper_1();	  //读取温度数据
			if(temperature1<85.0)			  //去除开机第一次显示的错误数据
			{
				translate( temperature1, display_temp);	//把float型数据转换为可以显示的数据并放到显示缓存
				print1602( display_temp, 0, 0);			//显示
			}
		}
		else											//若不存在
		{
			print1602( "Check 1", 0, 1);
			waitms(500);								 //清除显示的数据
			clear1602_10(0);
		}
		/*读取温度传感器2,当读取温度为85时为错误数据,不显示*/
		ds18b20_2_exist =int_18b20_2();
		if( ds18b20_2_exist ==0 )
		{
			temperature2 = read_temper_2();
			if(temperature2<85.0)
			{
				translate( temperature2, display_temp);
				print1602( display_temp, 1, 0);
			}
		}
		else
		{
			print1602( "Check 2", 1, 1);
			waitms(500);
			clear1602_10(1);
		}
		waitms(300);
	}
}
void main()
{
	unsigned char a[14];
	unsigned char b[18];
	unsigned int ii;

	int_lcd1602(rightmove, cursornotdisplay);
	serial_int(enable, baud9600, disable);

	while(1)
	{
		if(temp[0]=='T')
		{
			a[0] =temp[0];	
			a[1] =temp[1];
			a[2] =temp[2];
			a[3] =temp[3];
			a[4] =temp[4];
			a[5] =temp[5];
			a[6] =temp[6];
			a[7] =temp[7];
			a[8] =temp[8];
			a[9] =temp[9];
			a[10] =temp[10];
			a[11] =temp[11];
			a[12] ='\0';
			a[13] ='\0';
			for(ii=0;ii<16;ii++)
			{
				if(a[ii]=='c')
					a[ii+1]='\0';
			}
		}
		if(temp[0]=='S')
		{
			b[0] =temp[0];	
			b[1] =temp[1];
			b[2] =temp[2];
			b[3] =temp[3];
			b[4] =temp[4];
			b[5] =temp[5];
			b[6] =temp[6];
			b[7] =temp[7];
			b[8] =temp[8];
			b[9] =temp[9];
			b[10] =temp[10];
			b[11] =temp[11];
			b[12] =temp[12];
			b[13] =temp[13];	
			b[14] =temp[14];
			b[15] ='\0';
			b[16] ='\0';
			b[17] ='\0';
			for(ii=0;ii<=16;ii++)
			{
				if(b[ii]=='m')
				{	
					b[ii+1]=' ';
					b[ii+2]=' ';
					b[ii+3]=' ';
				}

			}

		}
		print1602(a,0,1);
		print1602(b,1,1);
	}
}
void main()
{
	bit  ds18b20_exit;	 			//存储ds18b20是否存在
	int time_temp;					//存储时间数据
	unsigned char temp;				//存储char型温度

	led_1 = 1;
	led_2 = 1;
	BEEP = 1;
	warning();
	serial_int(enable, baud9600, disable);
	int_lcd1602( rightmove, cursornotdisplay);

	setds1302(second,0);
	setds1302(minute,0);
	setds1302(hour,0);
	setds1302(year,14);
	setds1302(month,2);
	setds1302(day,7);
	setds1302(weekday,5);
	ele_mode(1);
	EA = 1;

	while(1)
	{
		/*显示温度阈值*/
		display_temp[0] = temp_set/10%10+0x30;
		display_temp[1] = temp_set%10+0x30;
		display_temp[2] = '\0';
		print1602( display_temp, 0,14);
		printchar1602(' ', 1, 15);

		/*开始测量温度*/
		ds18b20_exit =int_18b20();
		if( ds18b20_exit ==0 )
		{
			temperature = read_temper(); 
			if(temperature<=80.0)
			{
				translate( temperature, display_temp);
				print1602( display_temp, 0, 0);
			}
		}
		else
		{
			print1602( "Not Found", 0, 1);
			led_1 = 0;
			led_2 = 0;
			warning();
			waitms(500);
			clear1602_10(0);
		}
		
		/*设置温度阈值*/
		if(key_1==0)
			temp_set++;
		if(key_2==0)
			temp_set--;
		if(temp_set<10)
			temp_set = 10;
		if(temp_set>70)
			temp_set = 70;

		/*开始判断温度并指示升温降温*/
		temp = (unsigned char)temperature; 
		if(temp>temp_set)
		{
			
			if(temp-temp_set>1)
			{
				 led_1 = 1;
				 led_2 = 0;
				 warning();
			}
			else
			{
				 led_1 = 1;
				 led_2 = 1;
			}
		}
		else
		{
		   	if(temp_set-temp>1)
			{
				 led_1 = 0;
				 led_2 = 1;
				 warning();
			}
			else
			{
				 led_1 = 1;
				 led_2 = 1;
			}
		}

		/*开始显示时间*/
		time_temp =read1302(hour);
		if(time_temp<=23)
		{
			translate_print(time_temp,display_temp);
			print1602(display_temp,1,2);
		}
				    
		time_temp =read1302(minute);
		if(time_temp<=60)
		{
			translate_print(time_temp,display_temp);
			print1602(display_temp,1,5);
		}
			
		time_temp =read1302(second);
		time_temp =read1302(second);		//读取两次为了保证能够读取数据成功
		if(time_temp<=60)
		{
			translate_print(time_temp,display_temp);
			print1602(display_temp,1,8);


			/*设置冒号闪烁*/
			if(time_temp%2!=1)
			{
		    	print1602(" ",1,4);	
				print1602(" ",1,7);
			}
			else
			{
				print1602(":",1,4);
				print1602(":",1,7);	
			}
		}


	}
}
Beispiel #4
0
/*
功能:	程序开始时初始化各个模块,启动相关的线程,instruction线程用于处理具体指令,timing线程管理定时器
返回:	0——成功;-1——失败
*/
int global_init()
{
	int ret = -1;

	if(-1==dir_exist_ensure(WORKSPACE_SURFIX))
		return -1;
	
	setting_init();
	
	if(-1==dir_exist_ensure(FIFO_DIR))
		return -1;
	if(-1==socket_init()){
		DEBUG("socket module init failed\n");
		return -1;
	}
	if(-1==sqlite_init()){
		DEBUG("sqlite module init failed\n");
		return -1;
	}
	if(-1==timing_init()){
		DEBUG("timer module init failed\n");
		return -1;
	}
	if(-1==equipment_init()){
		DEBUG("equipment array init failed\n");
		return -1;
	}
	if(-1==instruction_init()){
		DEBUG("instruction module init failed\n");
		return -1;
	}
	if(-1==serial_int()){
		DEBUG("serial module init failed\n");
		return -1;
	}

// only for database testing
	//DEBUG("getGlobalPara(version)=%d\n", getGlobalPara("version"));
	
	//~~~~~~~~~~create  thread~~~~~~~~~~//
	typedef void*(*format)(void *);													///define function pointer of "void*(name)(void*)"
	pthread_t l_socketlinkthread;													/// the file description of thread
#if 0
	pthread_attr_t l_attrthread;													///the attribute of thread
	size_t l_stacksize=1048576*1;													///set thread stack size
	///start thread.
	pthread_attr_init(&l_attrthread);												///initialize attribute
	pthread_attr_setscope(&l_attrthread,PTHREAD_SCOPE_SYSTEM);						///set attribute binding
	pthread_attr_setdetachstate(&l_attrthread,PTHREAD_CREATE_DETACHED);				///set attribute detached
	pthread_attr_setstacksize(&l_attrthread,l_stacksize);
	ret=pthread_create(&l_socketlinkthread,&l_attrthread,(format)socketHandler,NULL);
#else	/* use default attr */
	ret = pthread_create(&l_socketlinkthread,NULL,(format)instruction_mainloop,NULL);
#endif
	if(0!=ret)
	{
		ERROROUT("thread instruction_mainloop create failed!");
		return -1;
	}

	pthread_t timing_thread_id;
	ret = pthread_create(&timing_thread_id, NULL, (void *)timing_mainloop, NULL);
	if(0!=ret){
		ERROROUT("thread timing_mainloop create failed\n");
	}
	
	return 0;
}