⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j.c

📁 SD读卡器原理+代码 SD读卡器原理+代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	}

	wr_com(0x99);
	while( *line4!=0x00 )
	{
		wr_date(*line4);
		line4++;
	}
}

void display_main_menu2(void)
{
	line1 = "5.温度电流纠偏";
	line2 = "6.差压电流纠偏";
	line3 = "7.截面积输入";
	line4 = "8.EEPROM重置";
	wr_com(0x81);
	while( *line1!=0x00 )
	{
		wr_date(*line1);
		line1++;
	}

	wr_com(0x91);
	while( *line2!=0x00 )
	{
		wr_date(*line2);
		line2++;
	}

	wr_com(0x89);
	while( *line3!=0x00 )
	{
		wr_date(*line3);
		line3++;
	}

	wr_com(0x99);
	while( *line4!=0x00 )
	{
		wr_date(*line4);
		line4++;
	}
}


void display_main_menu3(void)
{
	line1 = " 9. 全压上限";
	line2 = "10. 全压下限";
	line3 = "              ";
	line4 = "              ";
	wr_com(0x81);
	while( *line1!=0x00 )
	{
		wr_date(*line1);
		line1++;
	}

	wr_com(0x91);
	while( *line2!=0x00 )
	{
		wr_date(*line2);
		line2++;
	}

	wr_com(0x89);
	while( *line3!=0x00 )
	{
		wr_date(*line3);
		line3++;
	}

	wr_com(0x99);
	while( *line4!=0x00 )
	{
		wr_date(*line4);
		line4++;
	}
}


//----------- 正常模式显示函数 START -----------------
void normal_model(void)
{
	uint  ad_value_hex,temp_ad;
	double tempeture,current,Q,quanya;
	line1 = "温度:";
	line2 = "全压:";
	line3 = "流量:";
	display();
	
	temp_ad = read_ad(0);
	ad_value_hex = lb( temp_ad );
	
	current = ( (ad_value_hex/1024.0)*16.0 ) + 4.0;	//	计算温度电流值
	
	current = current+tem_cur_jp;		//	温度电流纠偏
	if( current<4 )		current = 4;
	if( current>20 )	current = 20;
	
	tempeture =  ( (current-4.00)/16 ) * ( tem_up-tem_down );

	dtostrf( tempeture,6,2,var);
	display_variable(0x83,6);
	
	wr_com(0x87);			//	显示温度符号
	wr_date(0xa1);
	wr_date(0xe6);
	
	
	temp_ad = read_ad(1);
	ad_value_hex = lb( temp_ad );
	current = ( (ad_value_hex/1024.0)*16.0 ) + 4.0;	//	计算差压电流值
	
	current = current+chaya_cur_jp;		//	差压电流纠偏
	if( current<4 )		current = 4;
	if( current>20 )	current = 20;
	
	Q = 3600.00*0.7212* ( sqrt(273.00+tempeture) ) *  aera *  ( sqrt(current-4.00) );
	dtostrf( Q,9,1,var);
	display_variable(0x8b,9);
	
	
	
	temp_ad = read_ad(1);				//	显示全压  应该是 temp_ad = read_ad(2);	
	ad_value_hex = lb( temp_ad );
	quanya = (ad_value_hex/1024.0) * ( quanya_up - quanya_down );
	dtostrf( quanya,7,1,var);
	display_variable(0x93,7);
	
	wr_com(0x97);			//	显示压力“帕”
	wr_date(0xc5);
	wr_date(0xc1);
	
	asm("wdr");
}
//----------- 正常模式显示函数 END -----------------

//----------- 测试模式显示函数 START -----------------
void test_model(void)
{
	uint ad_value_hex,ad_bcd,temp_ad;
	float vol,current;
	//	显示通道0   温度
	temp_ad = read_ad(0);
	ad_value_hex = lb( temp_ad );
	ad_bcd = IntHEXToIntBCD(ad_value_hex);
	var[0] = (ad_bcd >> 12) + 0x30 ;
	var[1] = ((ad_bcd >> 8) & 0x000f) + 0x30;
	var[2] = ((ad_bcd >> 4) & 0x000f) + 0x30;
	var[3] = (ad_bcd & 0x000f) + 0x30;		
	display_variable(0x80,4);						//	显示AD值

	vol = ( (ad_value_hex/1024.0)*5.0 );			//	显示电压值
	dtostrf( vol,4,2,var);
	display_variable(0x83,4);
		
	current = ( (ad_value_hex/1024.0)*16.0 ) + 4.0;	//	显示电流值
	
	current = current+tem_cur_jp;		//	温度电流纠偏
	if( current<4 )		current = 4;
	if( current>20 )	current = 20;
	
	dtostrf( current,5,2,var);
	display_variable(0x95,5);

	//	显示通道1   差压
	temp_ad = read_ad(1);
	ad_value_hex = lb( temp_ad );
	ad_bcd = IntHEXToIntBCD(ad_value_hex);
	var[0] = (ad_bcd >> 12) + 0x30 ;
	var[1] = ((ad_bcd >> 8) & 0x000f) + 0x30;
	var[2] = ((ad_bcd >> 4) & 0x000f) + 0x30;
	var[3] = (ad_bcd & 0x000f) + 0x30;		
	display_variable(0x88,4);						//	显示AD值
		
	vol = ( (ad_value_hex/1024.0)*5.0 );			//	显示电压值
	dtostrf( vol,4,2,var);
	display_variable(0x8B,4);
	
	current = ( (ad_value_hex/1024.0)*16.0 ) + 4.0;	//	显示电流值
	
	current = current+chaya_cur_jp;		//	差压电流纠偏
	if( current<4 )		current = 4;
	if( current>20 )	current = 20;
	
	dtostrf( current,5,2,var);
	display_variable(0x9D,5);
	
	asm("wdr");
}
//----------- 测试模式显示函数 END -----------------


//----------- 显示主菜单函数 START -----------------
void main_menu(void)
{
	if 		( cursor_posion<5 )
		display_main_menu1();
	else if	( cursor_posion<9 )
		display_main_menu2();
	else
		display_main_menu3();

	eeprom_read_block(&tem_cur_jp,  &ee_tem_cur_jp, sizeof(float)); 
	eeprom_read_block(&chaya_cur_jp,&ee_chaya_cur_jp, sizeof(float)); 
	eeprom_read_block(&tem_up, 		&ee_tem_up, sizeof(float)); 
	eeprom_read_block(&tem_down, 	&ee_tem_down, sizeof(float)); 
	eeprom_read_block(&chaya_up, 	&ee_chaya_up, sizeof(float)); 
	eeprom_read_block(&chaya_down, 	&ee_chaya_down, sizeof(float)); 
	eeprom_read_block(&aera, 		&ee_aera, sizeof(float));
	
	eeprom_read_block(&quanya_up, 	&ee_quanya_up, sizeof(float)); 
	eeprom_read_block(&quanya_down, &ee_quanya_down, sizeof(float)); 
}
//----------- 显示主菜单函数 END -----------------


void setup_menu_cursor(void)
{
	wr_com(0x80);wr_date(0x20);		wr_com(0x90);wr_date(0x20);		wr_com(0x88);wr_date(0x20);		wr_com(0x98);wr_date(0x20);

	if	   ( cursor_posion==1 || cursor_posion==5 || cursor_posion==9 )
	{
		wr_com(0x80);			//	设定光标的位置
		wr_date(0x10);
	}
	else if( cursor_posion==2 || cursor_posion==6 || cursor_posion==10 )
	{
		wr_com(0x90);			//	设定光标的位置
		wr_date(0x10);
	}
	else if( cursor_posion==3 ||  cursor_posion==7 )
	{
		wr_com(0x88);			//	设定光标的位置
		wr_date(0x10);
	}
	else if( cursor_posion==4 ||  cursor_posion==8 )
	{
		wr_com(0x98);			//	设定光标的位置
		wr_date(0x10);
	}
}


void judge_eeprom( float *var, float *ee_var)
{
	float temp;
	eeprom_read_block( &temp,  ee_var, sizeof(float)); 
	if( *var==temp )
	{
		line2 = "    保存成功   ";
		display();
		delay(800,8000);
	}
	else
	{
		line1 = "    保存失败   ";
		line2 = "请更换CPU";
		line3 = "重置EEPROM!";
		display();
		delay(8000,8000);
	}
}


//----------- 按键处理函数 START -----------------
void key_process(void)
{
	uchar i;
	switch( screen_status )
	{
		case	1:											//	屏幕正常模式时只检测“设置/退出”及“2、3同按”
			if( key_value==1 )                              //  是否按下“设置/退出”?                        
			{                                                                                                 
				clear_all();                                                                                      
				screen_status=3;                        	//  进入主菜单模式                                        
				cursor_posion = 1;                                                                                
				setup_menu_cursor();                                                                              
			}                                                                                                 
			if( key_value==5 )                              //  是否中间两个按键同时按下?                     
			{                                                                                                 
				clear_all();                                                                                      
				screen_status=2;                                                  
			}   
		break;
		
		case	2:											//	屏幕测试模式时只检测“2、3同按”
			if( key_value==5 )                              //  是否中间两个按键同时按下?                     
			{                                                                                                 
				clear_all();                                                                                      
				screen_status=1;                                                  
			}  
		break;
		
		case	3:											//	主菜单		屏幕在主菜单模式时只检测“设置/退出”“右移/向下”“确认/保存”键
			if( key_value==1 )								//	是否“设置/退出”
			{
				clear_all();
				screen_status = 1;							//	按下退出键,回到正常显示状态
				cursor_posion = 1;
			}
			if( key_value==2 )								//	是否“+/向上”
			{
				cursor_posion--;
				if( cursor_posion==0 )	{cursor_posion=10;clear_all();}
				if( cursor_posion==4 )	clear_all();
				if( cursor_posion==8 )	clear_all();
				setup_menu_cursor();
			}
			if( key_value==3 )								//	是否“右移/向下”
			{
				cursor_posion++;
				if( cursor_posion==5 )	clear_all();
				if( cursor_posion==9 )	clear_all();
				if( cursor_posion==11 )	{cursor_posion=1;clear_all();}
				setup_menu_cursor();
			}
			if( key_value==4 )								//	是否“确认/保存”
			{
				clear_all();
				if		( cursor_posion==1 )				//		按下确认键,状态进入“温度上限”选项
				{
					screen_status = 4;	
	
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( tem_up,6,2,var_change );		//	把温度上限的值放入var_change数组
					for( i=0;i<7;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==2 )				//		按下确认键,状态进入“温度下限”选项		
				{
					screen_status = 5;						
	
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( tem_down,6,2,var_change );		//	把温度下限的值放入var_change数组
					for( i=0;i<7;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==3 )				//		按下确认键,状态进入“差压上限”选项
				{
					screen_status = 6;	
	
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( chaya_up,7,2,var_change );		//	把差压上限的值放入var_change数组
					for( i=0;i<7;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==4 )				//		按下确认键,状态进入“差压下限”选项
				{
					screen_status = 7;	
	
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( chaya_down,7,2,var_change );	//	把差压下限的值放入var_change数组
					for( i=0;i<7;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==5 )				//	按下确认键,状态进入“温度电流纠偏”选项
				{
					screen_status = 8;	
					
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( tem_cur_jp,5,2,var_change );	//	把温度电流纠偏的值放入var_change数组
					for( i=0;i<5;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x2b;	//	强行添零
					}
				}
				else if ( cursor_posion==6 )				//	按下确认键,状态进入“差压电流纠偏”选项
				{
					screen_status = 9;	
					
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( chaya_cur_jp,5,2,var_change );	//	把差压电流纠偏的值放入var_change数组
					for( i=0;i<5;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x2b;	//	强行添零
					}
				}
				else if ( cursor_posion==7 )				//	按下确认键,状态进入“截面积输入”选项
				{
					screen_status = 10;	
	
					par_cursor_addres = 0x99;				//	光标初始位置
					wr_com(0x99);		
					wr_date(0x18);
	
					change_posion = 0;
	
					dtostrf( aera,5,2,var_change );			//	把截面积的值放入var_change数组
					for( i=0;i<5;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==8 )				//	按下确认键,状态进入“EEPROM重置”选项
				{
					screen_status = 11;	
					
					par_cursor_addres = 0x9a;				//	光标初始位置
					wr_com(0x9a);
					wr_date(0x18);
				}
				else if ( cursor_posion==9 )				//	按下确认键,状态进入“全压上限”选项
				{
					screen_status = 12;	
					
					par_cursor_addres = 0x98;				//	光标初始位置
					wr_com(0x98);
					wr_date(0x18);
					
					change_posion = 0;
	
					dtostrf( quanya_up,8,2,var_change );		//	把压力钌舷薜闹捣湃雟ar_change数组
					for( i=0;i<8;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
				else if ( cursor_posion==10 )				//	按下确认键,状态进入“全压下限”选项
				{
					screen_status = 13;	
					
					par_cursor_addres = 0x98;				//	光标初始位置
					wr_com(0x98);
					wr_date(0x18);
					
					change_posion = 0;
	
					dtostrf( quanya_down,8,2,var_change );		//	把全压下限的值放入var_change数组
					for( i=0;i<8;i++ )
					{
						if( var_change[i]==0x20 )	var_change[i] = 0x30;	//	强行添零
					}
				}
			}
		break;
		
		case	4:						//	温度上限,	屏幕在“温度上限”选项时只检测“设置/退出”"加1"“右移/向下”“确认/保存”键
			if( key_value==1 )								//	是否“设置/退出”
			{
				clear_all();
				screen_status=3;							//	回到主菜单模式
				main_menu();
				setup_menu_cursor();
			}
			if( key_value==2 )								//	是否“加1”
			{
				var_change[change_posion]++;
				if( var_change[change_posion]==0x3a )	var_change[change_posion] = 0x30;
			}
			if( key_value==3 )								//	是否“右移/向下”
			{
				line4 = "                ";
				display();
				par_cursor_addres++;
				change_posion++;
				if( par_cursor_addres==0x9c )	par_cursor_addres = 0x9d;	//	跳过小数点
				if( par_cursor_addres==0x9f )	par_cursor_addres = 0x99;	//	回头
				if( change_posion==3 )			change_posion = 4;			//	跳过小数点
				if( change_posion==6 )			change_posion = 0;			//	回头
				wr_com(par_cursor_addres);
				wr_date(0x18);
			}
			if( key_value==4 )								//	是否“确认/保存”
			{
				clear_all();
				screen_status=3;							//	回到主菜单模式
				//在此处把修改好的参数存入EEPROM
				asm("wdr");
				tem_up =	(var_change[0]-0x30)*100.00 + (var_change[1]-0x30)*10.00 + 	
							(var_change[2]-0x30)*1.0    +
							(var_change[4]-0x30)*0.1	+ (var_change[5]-0x30)*0.01   ;
				eeprom_write_block(&tem_up, &ee_tem_up, sizeof(double)); 
				delay(10,8000);
				judge_eeprom( &tem_up,&ee_tem_up);
				
				clear_all();
				main_menu();
				setup_menu_cursor();
			}	
		break;
		
		case	5:						//	温度下限,	屏幕在“温度下限”选项时只检测“设置/退出”"加1"“右移/向下”“确认/保存”键
			if( key_value==1 )								//	是否“设置/退出”
			{
				clear_all();
				screen_status=3;							//	回到主菜单模式
				main_menu();
				setup_menu_cursor();
			}
			if( key_value==2 )								//	是否“加1”
			{
				var_change[change_posion]++;
				if( var_change[change_posion]==0x3a )	var_change[change_posion] = 0x30;
			}
			if( key_value==3 )								//	是否“右移/向下”
			{
				line4 = "                ";
				display();
				par_cursor_addres++;
				change_posion++;
				if( par_cursor_addres==0x9c )	par_cursor_addres = 0x9d;	//	跳过小数点
				if( par_cursor_addres==0x9f )	par_cursor_addres = 0x99;	//	回头
				if( change_posion==3 )			change_posion = 4;			//	跳过小数点
				if( change_posion==6 )			change_posion = 0;			//	回头
				wr_com(par_cursor_addres);
				wr_date(0x18);
			}
			if( key_value==4 )								//	是否“确认/保存”
			{
				clear_all();
				screen_status=3;							//	回到主菜单模式
				//在此处把修改好的参数存入EEPROM
				asm("wdr");
				tem_down =	(var_change[0]-0x30)*100.00 + (var_change[1]-0x30)*10.00 + 	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -