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

📄 testprog.c

📁 电除尘行业中监控界面采用ACTIVE 控件的形式
💻 C
📖 第 1 页 / 共 5 页
字号:
// 	Copyright 2003 HaiYan HighVoltage-Switch Corporation
//	Write by whx1538@sina.com
// 	Version: YGK03HV-1.0     2003-11
//
//  07-13 modify mark it out
//--------------------------------------------
//  jp_code == 0x08		取消
//  jp_code == 0x09		设置
//	jp_code == 0x0b		启动/停机
//  jp_code == 0x0c		近控/远控
//  jp_code == 0x0d		确认
//
//--------------------------------------------
#include "def_pin.h"


void serio_isr( void) interrupt 4 	// 接收串行信息
{
	if(RI_0)
	{
		RI_0 = 0;
		ser_rec[m_r_in] = SBUF0;
		m_r_in ++;
	}
	TI_0 = 0;
}

//提供触发波形
void t0_isr( void) interrupt 1					//timer 0 interrupt
{
	m_t0_c++;
	if(m_t0_c == 1)	
	{											//first 270us timer constant
		if(m_tc < 1650) return;
		U_DRV   = CLEAR;	
		TH0 	= 0xfd;							//270us
		TL0 	= 0xe4;							//
	}	
	else if (m_t0_c >= m_total_t0||m_tc <2760)
	{
		U_DRV 	= SET;
		TR0 	= CLEAR;
		ET0 	= CLEAR;
	}
	else if( m_t0_c & 1 )						//奇数
	{
		U_DRV   = CLEAR;
		TH0 	= 0xff;							//90us  24MHz
		TL0 	= 0x4c;							//
	}
	else										//偶数
	{
		U_DRV 	= SET;
		TH0 	= 0xfc;							//450us  24MHz
		TL0 	= 0x7c;							//
	}
}

//电网参数的起点
void ex0_pulse_isr( void) interrupt 0			//ex0 interrupt 50hz*2 = 100hz signal
{
 		//------------------------------1000us   1 ms timer
		TR1 	= CLEAR;
		TH1 	= 0Xf8;
		TL1 	= 0X30;
		ET1 	= SET;
		TR1 	= SET;
		//---------------------------------------------
		TR0   	= CLEAR;						//关闭定时器0,
		ET0     = CLEAR;
		U_DRV 	= SET;
		//---------------------------------------------
		m_int_count ++;
		m_ms_count = 0;							//毫秒数清零

		m_int_count_rec+=1;
		
		if( m_int_count_rec > 250 )				//2 seconds without sparking 
		{
			m_int_count_rec =  250;
		}

		if(m_tc_max < m_tc) m_tc_max = m_tc;
	
		//对工作方式1的特殊照顾
		if(m_get_gzfs == 1 )					//对于间歇供电的处理
		{
			m_pulse_count ++;
			if(m_pulse_count > m_get_zkb) m_pulse_count = 1;
			if(m_pulse_count > 3) 
			{
				m_vol2_old_01 = 0;
				m_vol2_old_10 = 0;
			}
		}
		else if( m_get_gzfs == 4 )				//对于脉冲供电方式的处理
		{
			m_pulse_count ++;
			if(m_pulse_count > 4) m_pulse_count = 1;
		}

		if(m_br_fs) 	goto NTTT;

		m_vol2_new 		=  channel(167);//channel(4);				//首先检测二次电压

		if( m_get_gzfs == 4 && m_pulse_count == 2)			goto next_1555;
		if( m_get_gzfs == 4 && m_pulse_count == 4 )
		{
			if(m_dtj > 109 )
			{				//360 	       
				if(m_vol2_new + m_get_o36   <  m_vol2_old_10 )
				{
					goto next_155;	//340	
				}
			}
			else if(m_dtj > 72)
			{				//250		
				if( m_vol2_new + m_get_o36  <  m_vol2_old_10 )
				{
					goto next_155;		
				}
			}
			else
			{					//250                     
				if( m_vol2_new + m_get_o36  <  m_vol2_old_10 )
				{
					if(m_cur2 > m_cur2_div6)	//div4; 240	 &&	  m_cur2_new > m_vol2_new + 100 
					{	  	
next_155:				TR0         = CLEAR;		//关闭定时器0,
						ET0         = CLEAR;
						U_DRV   	= SET;			//因为火花,关闭进一步的脉冲
						m_br_fs 	= TRUE; 						
						m_vol2_old_10 	= m_vol2_new;
						return;
					}
				}
			}	
		}
		else
		{
			if(m_dtj > 109 )
			{				//360 	       
				if(m_vol2_new + m_get_o109 <  m_vol2_old_10 )
				{
					goto next_15;	//340	
				}
			}
			else if(m_dtj > 72)
			{				//250		
				if( m_vol2_new + m_get_o72 <  m_vol2_old_10 )
				{
					goto next_15;		
				}
			}
			else
			{					//250                     
				if( m_vol2_new + m_get_o36 <  m_vol2_old_10 )
				{
					if(m_cur2 > m_cur2_div6)	//div4; 240	 &&	  m_cur2_new > m_vol2_new + 100 
					{	  	
next_15:				TR0         = CLEAR;		//关闭定时器0,
						ET0         = CLEAR;
						U_DRV   	= SET;			//因为火花,关闭进一步的脉冲
						m_br_fs 	= TRUE; 						
						m_vol2_old_10 	= m_vol2_new;
						return;
					}
				}
			}	
		}

next_1555:
		m_vol2_old_10 	= m_vol2_new;	
	
		if(m_br_fs) 
		{
NTTT:		if(m_br_u2)
			{
				ET0 = CLEAR;
				ET1 = CLEAR;
				m_temp_data    = channel(231);//channel(5);		//暂时取得二次电流设定值
				m_temp_tempura = channel(135)/11;
				return;
			}
		
			U_DRV = SET;
		
			//-----------------------
			if(m_tc > 8900) m_tc = 8900;		//new adding
	
			if(m_get_gzfs == 1)
			{
				if(m_vol2 >8) 	m_br_over8= TRUE;
				m_cur2 			=  	0;			//<1>二次电流			
				//-----------------------------------------------
				if(m_pulse_count == m_get_zkb)			//zkb个脉冲(第四次脉冲)才需要准备各种标志
				{
					m_tc_max        =  m_tc;
					//0.70--0.76--0.82--0.88
					con_speed1      =  m_tc_max/50;
					m_tc            =  con_speed1 * 35;	//70%->76%->82%->88%
					con_speed1      =  con_speed1 * 3;	// 6%
					con_speed       =  3;
					m_br_fs 		= FALSE;
					m_int_count_rec = 0;
					m_hh_count ++;						// just for sparking rate
				}
				//-----------------------------------------------
				m_count_plc 	= 0;					//偏励磁次数清零
				m_vol2_old_10  	= 0;
				m_vol2_old_01   = 0;
				return;
			}

			if(m_vol2 >8) 	m_br_over8= TRUE;
			m_cur2 		=  	0;//<1>二次电流

			if((m_fsmc--) > 1) return;

			//-----------------------
			//取得第一次闪络时的导通角       
			if(m_int_count_rec >= 250)
			{
				m_tc_old 	= m_tc_max;
				m_tc 		= m_tc_max;
			}
			m_tc_max = m_tc;

			//本部分可以尝试关闭
			if(m_tc_old > 8900) m_tc_old = 8900;

			if( m_tc_old > m_tc_max + 800 )
			{
				m_tc_max 	= m_tc_old - 100;
			}
			else 
			{
				m_tc_old 	= m_tc_max;
			}

			if( m_int_count_rec < 16 )
			{
				m_count_intver++;
				if(m_tc_max > 2000)
				{
					if(m_count_intver > 3 )	//4
					{
						m_tc_old -= 1500;
						m_tc_max -= 1500;	//1500
					}
					if(m_count_intver > 2 )	//3
					{
						m_tc_max -= 300;	//1500
					}
					if(m_count_intver > 1 )	//2		//shut this part
					{

						m_tc_max -= 300;	//1500
					}
				}
			}
			else
			{
				m_count_intver  = 0;
			}

			//---------------------------------------------------------------------
			//0.56--0.83--0.90--0.93--0.96   CAN'T WORK NORMALLY
			//---------------------------------------------------------------------
			//  1    2     3      4     5            6
			//0.50--0.70--0.80--0.86--0.92-- low speed increase according spark-rate

			//---------------------------------------------------------------------0713adding
			if( m_get_gzfs == 4 )
			{
				m_fdb_tc        = (m_get_fdb-1)*277;		  //每个台阶为10度 
				m_left_fdb_tc   =  8900 - m_fdb_tc; 
				m_pulse_count = 0;
			}
			//---------------------------------------------------------------------0713adding

			con_speed1 =  m_tc_max / 50;
			con_speed2 =  con_speed1*4;		//  8%
			m_tc       =  con_speed1*15;	// 30%
			con_speed3 =  con_speed1*3;		//  6%
			con_speed4 =  con_speed1;       // 2%
			if(m_count_intver > 1)			//  8% for left period
				con_speed  = ( con_speed2 + 300 )/(m_set_interval - 11);		//计算慢上升
			else
				con_speed  =   con_speed2 /(m_set_interval - 11);	
			con_speed1 =  con_speed1 * 10;
			con_speed2 =  con_speed1 / 2;	// 10%

			if(m_get_gzfs == 3 || m_get_gzfs == 5)	
			{
				m_third_sec = 0;
				m_br_reach  = FALSE;
			}
			m_fsmc 			= m_get_mcfs -1 ;						//计算封锁脉冲个数
			
			//---------------------------------------------------------------------
			//ex0 position 0ms position
			m_cur1          = 0;
			m_cur2          = 0;
			m_count_plc 	= 0;				//偏励磁次数清零
			m_vol2_old_10  	= 0;
			m_vol2_old_01   = 0;
			m_br_fs 		= FALSE;
			m_int_count_rec = 0;
			m_hh_count ++;						// just for sparking rate
			return;
		}
	
		//===================================================================
		//注意:在下移的时候,要能终止
		if(m_br_zz== TRUE && m_tc > m_zz_time)
		{
			  m_tc += 0;				//终止状态
		}
		else if(m_br_xy)	//下移
		{
			if(m_tc >1600) m_tc -= 5;
		}
		else if(m_get_gzfs == 2 || m_get_gzfs == 6)
		{
			if(m_int_count_rec > 5)//6
			{
				m_tc += con_speed;
			}
			else if(m_int_count_rec < 3)
			{
				m_tc += con_speed1;
			}
			else if(m_int_count_rec ==3)
			{
				m_tc += con_speed2;
			}
			else 
			{
				m_tc += con_speed3;
			}
		}
		else if(m_get_gzfs == 3)
		{
			if(m_int_count_rec > 5)
			{
				if(m_br_reach == TRUE )
						m_tc += con_speed;
				else 	m_tc += 0;
			}
			else if(m_int_count_rec < 3)
			{
				m_tc += con_speed1;
			}
			else if(m_int_count_rec ==3)
			{
				m_tc += con_speed2;
			}
			else 
			{
				m_tc += con_speed3;
			}
		}
		else if(m_get_gzfs == 1)		//间歇供电
		{								//0.88->0.82->0.88->0.94
			if( (m_int_count_rec/m_get_zkb)< 5 && m_pulse_count == 1 )//4
			{
				m_tc += con_speed1;
			}
			else m_tc += 2*con_speed;
		}
		//-------------------------------------------------------------------20050713
		else if(m_get_gzfs == 4)		//脉冲供电
		{								//50--60--70--80--
			if(m_int_count_rec > 7)		//6
			{
				m_tc += con_speed;
			}
			else if(m_int_count_rec < 6)
			{
				m_tc += con_speed2;
			}
			else 
			{
				m_tc += con_speed3;
			}
		}
		else if(m_get_gzfs == 5)		//最高平均值
		{								//0.88->0.82->0.88->0.94
			if(m_int_count_rec > 6)
			{
				if(m_br_reach == TRUE )
						m_tc += con_speed;
				else 	m_tc += 0;
			}
			else if(m_int_count_rec < 3)
			{
				m_tc += con_speed1;
			}
			else if(m_int_count_rec ==3)
			{
				m_tc += con_speed2;
			}
			else if(m_int_count_rec ==6)
			{
				m_tc += con_speed4;
			}
			else 							//4,5	
			{
				m_tc += con_speed3;
			}
		}
		//工作方式6用不着列出,因为是上面5种工作方式之一
		//-------------------------------------------------------------------20050713

		if(m_tc > 2320)	m_total_t0 = (m_tc - 2050)/290 ;	
		else 			m_total_t0 = 1;
		m_t0_c = 0;
		
		if(m_tc < 1600)	return;
		
		if(m_get_gzfs ==1 )
		{
			if(m_tc > 8600)	m_tc = 8600;       
			if(m_pulse_count == 1)
			{
				silent  = 44000 + m_tc*2; 	//45536		   
			}
			else if(m_pulse_count == 2)
			{
				silent  = 44800 + m_tc*2; 	//45536		   
			}
			else	return;

			TH0 	= silent/256;
			TL0 	= silent%256;
			ET0 	= SET;
			TR0 	= SET;	
			return;
		}
		else if( m_get_gzfs == 4 )
		{
			if(m_tc > m_left_fdb_tc )	m_tc = m_left_fdb_tc;  		//第一步,     

			silent  = 44200 + m_tc*2; 					//44200	   
			//----------------------------------------------
			if(m_pulse_count == 3 ||m_pulse_count== 4)
			{
				silent  =  silent + m_fdb_tc*2; 	//44200	   
			}
			TH0 	= silent/256;
			TL0 	= silent%256;
			ET0 	= SET;
			TR0 	= SET;	
			return;
		}
		else
		{
			if(m_tc > 8900)	m_tc = 8900;       
			silent  = 44200 + m_tc*2; 	//44200	   
			TH0 	= silent/256;
			TL0 	= silent%256;
			ET0 	= SET;
			TR0 	= SET;	
			return;
		}
}

void t1_isr( void) interrupt 3					//timer 0 interrupt
{
	TH1 	= 0Xf8;
	TL1 	= 0X30;

	m_ms_count++;
	m_send_ref++;								//每个毫秒发送一个字节

	if(m_ms_count == 10)						//10  another half wave
	{
	 	TR0   	= CLEAR;						//关闭定时器0,
		ET0     = CLEAR;
		U_DRV 	= SET;

		m_int_count ++;
		m_int_count_rec ++;
		
		//对工作方式1的特殊照顾
		if(m_get_gzfs == 1 )					//对于间歇供电的处理
		{
			m_pulse_count ++;
			if(m_pulse_count > m_get_zkb) m_pulse_count = 1;
			if(m_pulse_count > 3) 
			{
				m_vol2_old_01 = 0;
				m_vol2_old_10 = 0;
			}
		}
		else if( m_get_gzfs == 4 )				//对于脉冲供电方式的处理
		{
			m_pulse_count ++;
			if(m_pulse_count > 4) m_pulse_count = 1;
		}

⌨️ 快捷键说明

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