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

📄 ze015_1.c.bak

📁 一款完整的家用电器程序,具有控制商用机的功能,应用广泛,有一定的参考价值
💻 BAK
📖 第 1 页 / 共 3 页
字号:
		case 0x06:	//接收IDH
			{
			   rxd_state0=0x07;rxd_data0[rxd_len0]=n;
			   rxd_checksum0^=n;rxd_len0++;
				break;
			}
		case 0x07:	//接收IDL
			{
			   rxd_state0=0x08;rxd_data0[rxd_len0]=n;
			   rxd_checksum0^=n;rxd_len0++;
				break;
			}					
		case 0x08:	//接收命令字
			{
			if (n<=0x0f)
			   {rxd_state0=0x10;rxd_command0=n;rxd_data0[rxd_len0]=n;
			   rxd_checksum0^=n;rxd_len0++;}
			else 
				{if (n==0x7E) rxd_state0=0x01;	//接收到7EH为头码1
				else rxd_state0=0x00;	//出错时重新开始接收
				}
				break;
			}	
		
		case 0x10:	//接收数据
			{
			if (rxd_len0 <rxd_len0_ask)
				{rxd_data0[rxd_len0]=n;rxd_checksum0^=n;rxd_len0++;}
			else 
			   {
				if (rxd_checksum0==n) fun_rxdgood0();	//接收正确处理程序
				else	
				   {if (n==0x7E) rxd_state0=0x01;	//接收到7EH为头码1
					else rxd_state0=0x00;	//出错时重新开始接收
				   }
			    }	
			break;
			}	
		}
	}
}

void fun_rxdgood0(void )	//接收正确处理程序
   {
	unsigned    char   i ;
	rxd_nogood_time=0; //通讯故障连续时间=0
	 if (rxd_command0==0x01)  //ID号命令
	    {
	    	fun_txddata0_ID();	  //ID号命令
	    }
	 else  
	 {
	 	if ((mode & b_urgent)==0) 
		  {//在应急状态下,触摸屏或显示板的开关机及手动命令\设置参数无效
		 	if ((rxd_command0==0x02) &&(rxd_len0==26))fun_rxd_data0(); //接收主板点名
		  }
	 	fun_txd_data0();	//发送应答主板点名的数据
	  }
	  if ((fault_tongxun_times<6) &&((fault_state2 &b_fault_tongxun)!=0))	//通讯故障次数
	  {//
	  	if ((rxd_command0==0x02) &&(rxd_len0==26))
	  	{//三次内如正确接收到主模块板的点名,则清除故障
	  		fault_state2 &=~b_fault_tongxun;	
	  		}
	  }
   }    
    
 void fun_rxd_data0(void )	//存入显示板点名的数据 
    {
	unsigned    char   i ,temp;
	unsigned    char  *point_temp;
	point_temp = &rxd_data0[4];	//i=4;	//第1个有效数据
	int_THset= *point_temp++; //字节1设定温度整数
 	RHset=*point_temp++; //字节2设定湿度整数
 //字节3高4位为设定温度小数,低4位为湿度精度RHm2~10,出厂设置5
  	dig_THset =*point_temp>>4; 
  	rh_actual =*point_temp &0x0f;
  	point_temp++;
  	th_actual10=*point_temp++; //字节4温度精度Tm 0.5~5,出厂设置*10
  	i_cof_sensiadj10=*point_temp++;	//字节5灵敏度调节参数*10
  	i_adj_time=*point_temp++;	//字节6容调间隔时间秒
	mode_set_1=*point_temp++; //字节7模块组合参数
   	mint_comprun_set=*point_temp++;	//字节8压缩机最小运行时间1~6分钟
  	imax10_set=*point_temp++;	//字节9加湿器额定电流*10
  	t_outpai_set=*point_temp++;	//字节10加湿器定时排水时间5~120秒,出厂设置60秒
  	humid_ratio=*point_temp++;	//字节11加湿器量设定%
  	exghaust_TH_set=*point_temp++;	//字节12排气温度保护
  	mint_compstop_set=*point_temp++; //字节13压缩机最小停机时间1~6分钟
  	t_fan_ondelay_set=*point_temp++; //字节14送风机延时启动时间出厂设置5秒
  	temp=*point_temp++; //字节15压缩机延时启动时间 1分钟=3*20秒
  	t_comp_ondelay_set =temp+temp+temp;	//20080114将接收到的压缩机延时启动时间转成20秒
  	t_lppdelay_set=*point_temp++;	//字节16低压保护延时出厂设置20秒
  	rh_value_modify=*point_temp++;	//字节17回风湿度修正值负数
  	th_value_modify=*point_temp++;	//字节18回风温度修正值负数*10
  	act_ask_set=*point_temp++; //字节19动作请求
	manual_act_ask =act_ask_set;	//置手动设置
	mokuai_set=*point_temp++; //字节20模块模式 //字节21\22预留字节
	if (mokuai_set &b_fault_rst_onask)run_state2 |=b_fault_reset;	//故障复位命令
//	if ((mokuai_set &b_connect_onask) &&(mokuai_set &b_kaiji_ask)) mode |=b_kaiji;	//当模块连接及开机时为开机,断开时为关机
	if (mokuai_set &b_kaiji_ask) mode |=b_kaiji;	//20080107当模块开机时为开机,关机时为关机,
	else mode &=~b_kaiji;
	if (mokuai_set &b_manual_onask) mode |=b_manual_on;	//当模块手动时为手动
	else mode &=~b_manual_on;	//自动,备用先不管
	NOP();	//先不管显示板控制有效,都认故障复位命令 TEST
	humid_rated=*point_temp++;//字节21额定加湿量设定
	fault_yuliu=*point_temp;//字节2220071115数据11预留 主模块故障标志 B7
   }
   
void fun_txd_data0(void)	//发送子模块板的运行数据
  {
	signed    char   temp ;//暂存值
	unsigned    char   temp_txd ;//发送数据
	unsigned    char   temp_checksum ;//校验
	unsigned    char  *point_txd;
	 point_txd = &txd_data0[0];
	 *point_txd++ =0x7E;
	 *point_txd++=0x7E;
	 *point_txd=0xFF;	//显示板接收方为FFH
	 temp_checksum=*point_txd++;	//异或校验
	 *point_txd =0x40;	//20080201 address;	//发送方地址
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=0x11;	//包号
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=26;	//长度26
	 temp_checksum ^=*point_txd++;	//异或校验	 
	 *point_txd=ID_l;	//IDH机组ID号
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=ID_h;	//IDl机组ID号
	 temp_checksum ^=*point_txd++;	//异或校验
	*point_txd=0x82;	//回复显示板点名机组命令82H
	 temp_checksum ^=*point_txd++;	//异或校验
	 temp=t_value10_20s>>8;	//数据1回风温度高8位
	 *point_txd=temp;
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=(unsigned char)(t_value10_20s);	//数据2回风温度的低8位
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=rh_value_20s;	//数据3回风湿度平均值
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=i_humid10;	//数据4加湿电流*10
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=exghaust_TH;	//数据5压缩机排气温度EXHAUST
	 temp_checksum ^=*point_txd++;	//异或校验
	*point_txd=act_state1;//数据6输出1
	 temp_checksum ^=*point_txd++;	//异或校验
	*point_txd=act_state2;//数据7输出2
	 temp_checksum ^=*point_txd++;	//异或校验
	 temp_txd =fault_comp_guozai_times;	//b1b0压缩机过载保护次数
	 temp=fault_lpp_times<<2;	//b3b2低压保护次数
	 temp_txd +=temp;
	 temp=fault_exh_times<<4;	//b5b4排气温度过高保护次数
	 temp_txd +=temp;
	 if ((PINB &cap_boma2)==0) temp_txd |=0x80;
	 if ((PINB &cap_boma1)==0) temp_txd |=0x40;
	 *point_txd=temp_txd;	//数据8 故障+容量拨码21
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=fault_state2;	//数据9 故障2
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=fault_state3;	//数据10 故障3
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=fault_state4;	//数据11 故障4
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=fault_state5;	//数据12 故障5
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=fault_state6;	//数据13 故障6
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=dangwei_ofan;	//数据14 室外风机档位预留
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=outroom_TH;//evin_TH;																		//outroom_TH;	//数据15 预留室外环境温度
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=0;	//数据16 预留电流A整数
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=0;	//数据17 预留电流B整数
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=0;	//数据18 预留电流C整数
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=0;		//数据19 预留高1位电流A +电流B +电流C
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=defrost_TH;	//数据20 预留管温值温度带负数
	 temp_checksum ^=*point_txd++;	//异或校验
	 	temp_stepnum = (unsigned int) (stepnum);
	 *point_txd=(unsigned char)(temp_stepnum>>8);//0;	//数据21 预留
	 temp_checksum ^=*point_txd++;	//异或校验
	 temp_stepnum = (unsigned int) (stepnum);
	 *point_txd=(unsigned char) ((stepnum<<8)>>8);	//数据22 预留
	 temp_checksum ^=*point_txd++;	//异或校验
	 *point_txd=temp_checksum;	//校验码
	 txd_len0_ask=32;  //ask len
	 txd_rxd_delaytime0=0;		//clear 
	 txd_state0 |=rxd_txdstart0;	//rxd_txdstart0=1
   }


#pragma interrupt_handler uart0_tx_isr:21
void uart0_tx_isr(void)
{
 //character has been transmitted
 if (txd_len0 >=txd_len0_ask)	//txd finished
 	{
 		txd_len0 =0;
 		PORTE &= ~b_con4850;	//pe2为uart0 485控制端=0接收
	   rxd_state0=0;
	   UCSR0B = 0x90;	// uart0_rxd_on允许接收完成中断及接收
	   PORTE |=0x02;	//发送完成后置发送端PE1 TXD=1	
 	}
else
	{UDR0=txd_data0[txd_len0];	//
 	txd_len0++;}	
}


//UART1 initialize禁止UART1
// desired baud rate:9600
// actual baud rate:9615 (0.2%)
void uart1_init(void)
{
 UCSR1B = 0x00; //disable while setting baud rate
 UCSR1A = 0x00;
 UCSR1C = 0x06;
 UBRR1L = 0x19; //set baud rate lo
 UBRR1H = 0x00; //set baud rate hi
}

//ADC initialize
// Conversion time: 26uS
void adc_init(void)
{
 ADCSRA = 0x00; //disable adc
 ADMUX = 0x00; //select adc input 0
 ACSR  = 0x80; //模拟比较器禁止
 ADCSRB = 0x00; //触发选择无用
 ADCSRA = 0x85;	//使能AD,但不启动AD转换,32分频
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 port_init();
 watchdog_init();
 timer0_init();	//10ms
 timer1_init();	//1s
 timer2_init();	//beep
 timer3_init();	//no use 
 uart0_init();
 uart1_init();
 adc_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EICRB = 0x00; //extended ext ints
 EIMSK = 0x00;
 TIMSK = 0x45; //timer interrupt sources
 ETIMSK = 0x04; //extended timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void main(void)
{
 init_devices();
 fun_1232_wdt();  //1232的看门狗翻转时钟脉冲
 valctlcount=0;
 ID_h =0x70;	//IDH机组ID号7002
 ID_l =0x02;	//IDl机组ID号
 t_comp_stop=0x00;	//压缩机最小停机时间
	t_comp_run=0x00;	//压缩机最小运行时间
	t_comp_ondelay=0x00;	//压缩机延时启动时间
	t_fan_ondelay=0x00;	//送风机延时启动时间
	t_lppdelay=0x00;	//低压保护延时
	t_outpai_turn=0x00;	//加湿器定时排水间隔时间
	t_outpai=0x00;	//加湿器定时排水时间
	t_fan_offdelay=0x00; //内风机关机延时计时
	t_ofan_offdelay=0x00; //冷凝风机关机延时计时
//设置上电时为自动关机,所有关,设置默认值	
	  mode=0x00;	//自动关机
	  manual_set=0x00;	//手动开机时模式off
 fun_set_default();  //初次上电开始初始化
 fun_beep(20);	//初始化定时器2,开始CTC模式
 NOP();
 NOP();
 if ((PINE &b_key_fast)==0)	//	PE5快测短路块
  {//上电时检测是否有短路,有则快测
 	mode |=b_fast_test;	//0x08	//1快测
 	exghaust_AD=43;	//排气温度=25
 	}
 
 while(1)
   {
 	 NOP();NOP();NOP();NOP();NOP();
 	 if (mode&b_fast_test)
 	   {//快测时计数时间按10ms
 		//t_1min_3s_std=300; //1min快测时时间	3秒 
 		//t_10min_10s_std=1000;	//10min快测时时间	10秒 
 		//t_180s_10s=1200; //180秒到快测10秒	
 		//t_10min_15s_std=1500; //10min快测时时间	15秒
 		//快测时计数时间按8ms
 		t_1min_3s_std=375; //1min快测时时间	3秒 
 		t_10min_10s_std=1250;	//10min快测时时间	10秒 

⌨️ 快捷键说明

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