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

📄 t_shuanglong.c

📁 PIC16F 系列制作的空调控制器 全部资料 软件硬件
💻 C
📖 第 1 页 / 共 3 页
字号:
#include"pic.h"
__CONFIG(0x3fea);

#define bitset(var, bitno) ((var) |=  (1<<(bitno)))
#define bitclr(var, bitno) ((var) &= ~(1<<(bitno)))
#define CLK  			 RC3
#define DATA 			 RC5
#define STB  			 RD4
//------------------------	
#define P4021_0	bitclr(PORTD,6)
#define P4021_1	bitset(PORTD,6)
#define C4021_0	bitclr(PORTD,5)
#define C4021_1	bitset(PORTD,5)
#define DD4021	RD7
/////
#define MODE_P			 RC0
#define MODE_N 			 RC1
#define RF_P   			 RD0
#define RF_N   		     RD1
#define MIX_P   		 RD2
#define MIX_N  			 RD3

#define main_motor_relay RC7 //relay sw of main motor

//AD channel define
#define AD0  0b01000001
#define AD1  0b01001001
#define AD2  0b01010001
#define AD3  0b01011001
#define AD4  0b01100001
#define AD5  0b01101001
#define AD6  0b01110001
#define AD7  0b01111001
#define AD8  0b01000011
#define AD9  0b01001011
#define AD10 0b01010011
#define ad11 0b01011011
#define ad12 0b01100011
#define ad13 0b01101011
/*
		data_temp=ad_sampling(AD0);//主风扇电流
		
		data_temp=ad_sampling(AD1);//模式电机电流
		
		data_temp=ad_sampling(AD2);//温度电机电流
		
		data_temp=ad_sampling(AD3);//新风电机电流
		
		data_temp=ad_sampling(AD4);//主风扇工作电压经过继电器后的工作电压
		
		data_temp=ad_sampling(AD5);//主风扇反馈电压 
			
		data_temp=ad_sampling(AD6);//模式电机位置反馈电压
		
		data_temp=ad_sampling(AD7);//新风电机位置反馈电压
		
		data_temp=ad_sampling(AD8);//温度电机位置反馈电压
		
		data_temp=ad_sampling(AD9);//温度传感器
		
		data_temp=ad_sampling(AD10);//蒸发器温度传感器 
		
		//data_temp=ad_sampling(ad11);//空闲未用通道
		
		//data_temp=ad_sampling(ad12);//空闲未用通道
		
		//data_temp=ad_sampling(ad13);//空闲未用通道
		*/
//led position define
#define MODE_MOTOR_OPEN_LED_AT3      	0b10000000
#define mode_motor_close_led_at3     	0b01000000
#define mode_motor_testing_led_at3   	0b00100000
#define mode_motor_test_fail_led_at3 	0b00010000
#define xinfeng_motor_open_led_at3 	 	0b00001000
#define xinfeng_motor_close_led_at3 	0b00000100 
#define xinfeng_motor_testing_led_at3   0b00000010
#define xinfeng_motor_test_fail_led_at3 0b00000001
//------------------------------------------------
#define wendu_motor_open_led_at2      	0b10000000
#define wendu_motor_close_led_at2     	0b01000000
#define wendu_motor_testing_led_at2   	0b00100000
#define wendu_motor_test_fail_led_at2 	0b00010000
#define main_fan_motor_1_led_at2 	 	0b00001000
#define main_fan_motor_2_led_at2 		0b00000100 
#define main_fan_motor_3_led_at2   		0b00000010
#define main_fan_motor_4_led_at2 		0b00000001
//------------------------------------------------
#define main_fan_motor_5_led_at1        		0b10000000
#define main_fan_motor_6_led_at1     			0b01000000
#define main_fan_motor_testing_led_at1  		0b00100000
#define main_fan_motor_test_fail_led_at1 		0b00010000
#define main_fan_motor_current_over_led_at1 	0b00001000
#define main_fan_motor_current_sound_led_at1 	0b00000100 
#define main_fan_motor_wendu_sense_led_at1   	0b00000010
#define main_fan_motor_zhengfa_sense_led_at1 	0b00000001
//------------------------------------------------
#define auto_test_status_led_at0        		0b10000000
#define auto_test_led_at0     					0b01000000
#define auto_test_pass_led_at0  				0b00100000
#define auto_test_test_fail_led_at0 			0b00010000
#define auto_test_pass_sound_led_at0_at0 		0b00001000
#define auto_test_fail_sound_led_at0_at0 		0b00000100 
#define nc1_led_at0   							0b00000010
#define nc2_led_at0 							0b00000001
//---------------------------------------------------------
//current_value_define
//---------------------------------------------------------
#define motor_100mA 360
#define motor_150mA 500
#define motor_30A 700
//---------------------------------------------------------
#define max_open_mode_moter_position     700//690
#define max_close_mode_moter_position    260//260
#define max_open_wendu_moter_position    700//700
#define max_close_wendu_moter_position   300
#define max_close_xinfeng_moter_position 270
#define max_open_xinfeng_moter_position  700
#define mid_motor_value                  400
//---------------------------------------------------------
#define test_mode_motor_channel 		0
#define test_wendu_motor_channel 		1
#define test_xinfeng_motor_channel 		2
#define test_main_fan_motor_channel 	3
#define test_all_channel				4
//constant value declaration
const unsigned char PWM[7]={0X33,0X66,0X99,0XCC,0Xdd,0xee,0Xfe};
//var declaration	
unsigned char led[4]={0x00,0x00,0x00,0x00};//light buffer
unsigned char blo_step_counter=0x00;//主电机测试步数计数器
unsigned char mode_motor_test_step=0x00,wendu_motor_test_step=0x00,xinfeng_motor_test_step=0x00;
//bit hand_test_start_or_stop=0;
unsigned char dingshiqi=0x00;
unsigned int   dingshiqi2=0x00;
bit togle_1=0,togle_2=0,dingshi_qi_bit=0,curent_bit=0;
union var
{
	unsigned char byte; 
	struct
	{
    	unsigned bit0: 1;
    	unsigned bit1: 1;
    	unsigned bit2: 1;
    	unsigned bit3: 1;
    	unsigned bit4: 1;
    	unsigned bit5: 1;
    	unsigned bit6: 1;
    	unsigned bit7: 1;
	}bits;
};
//用于存放A/D、D/A的结果
union ad_re
{
int Y1;
unsigned char ad[2];
}adresult;
//------------------------------------------------------
union var KEY_VALUE=0x00;//kay_flag_val
//--------------------------------------
//union KEY_VALUE.bits.bit0  is hand auto sel key
//union KEY_VALUE.bits.bit1  is hand_mode_motor_test_key
//union KEY_VALUE.bits.bit2  is hand_xinfeng_motor_test_key
//union KEY_VALUE.bits.bit3  is hand_wendu_motor_test_key
//union KEY_VALUE.bits.bit4  is hand_main_fan_motor_test_key
//union KEY_VALUE.bits.bit5  is hand_start_test_key
//--------------------------------------------

//*****************************
//delay N_ms function
//*****************************
void delay(unsigned char t)
{
	unsigned int i;
    for(;t>0;t--)
    	for(i=1000;i>0;i--)
        	NOP();
}
//*****************************
//delay N_s function
//*****************************
void delay_500mS(unsigned char second)//半秒延时涵数已经调好了
{
	unsigned int i,t;
	for(;second>0;second--)
	{
		for(t=0x00;t<0xff;t++)
		{
			for(i=0xff;i>0;i--)
        	NOP();
		}	
	}
    
}
//*****************************
//key_sweep_in function
//*****************************
void key_input(void)
{
	unsigned char j;
	unsigned char V;
    P4021_1;
	NOP();
	C4021_1;
	NOP();
	P4021_0;
   	KEY_VALUE.byte=0x00;
	V=0x80;
    for(j=8;j>0;j--)	//4021输入
    {
		C4021_0;
    	if(DD4021)KEY_VALUE.byte|=V;
		V=V>>1;
        C4021_1;
    }
    C4021_0;
	NOP();
    P4021_1;
}
//*****************************
//display refrush function
//*****************************
void refrush_led(void)
{
	unsigned char i,j,temp;
	STB=0;
    for(i=0;i<4;i++)
	{	
		temp=led[i];
		for(j=0;j<8;j++)
		{
		  	CLK=0;
			NOP();			
			DATA=temp&0x01;
			NOP();
   			CLK=1;
           	temp>>=1;
		}
	}
	STB=1;
}
//**************************
//AD_convert_function
//**************************
unsigned int ad_sampling(unsigned char channel)
{
	//unsigned short int temp[10];
	//unsigned short int ad[2];
	INTCON=0X00;
	ADCS2=0;
	ADCON0=channel;
	ADIF=0;       //清除A/D转换标志
	ADIE=0;
	PEIE=0;
	GODONE=1;	//启动A/D转换
	while(GODONE==1);
	adresult.ad[0]=ADRESL;
	adresult.ad[1]=ADRESH;
	
	return adresult.Y1;
}
//*****************************
//measure function
//*****************************
bit  measure_function(unsigned char channel_sel)//channel_sel mean to whitch part well be test
{	
	unsigned int current_data_temp=0x00;				//return success bit 0 means fail 1 mean success
	unsigned int position_data_temp=0x00;
	//unsigned int data_temp;
	unsigned int time_counter=0x00;
	static	bit success=0;
	success=0;
	switch(channel_sel)
	{
		case test_mode_motor_channel://mode motor tester item
		{	
			static	bit flag_bit=0;
			flag_bit=1;
			while(flag_bit)
			{		
					delay_500mS(1);
					current_data_temp=ad_sampling(AD1);//模式电机电流
					delay_500mS(1);
					position_data_temp=ad_sampling(AD6);//模式电机位置反馈电压
					time_counter++;
					if((position_data_temp<max_close_mode_moter_position)|(position_data_temp>max_open_mode_moter_position))//(current_data_temp<motor_100mA)&
					{
						flag_bit=0;
						time_counter=0x00;
						success=1;//cheng gong le
					}	
					else if(time_counter>10)
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//shi bai le
					}
					else if(curent_bit)
					{
					if(current_data_temp>motor_100mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}	
					}
					else if(current_data_temp>motor_150mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}					
			}	
		}break;
		case test_wendu_motor_channel:
		{	
			static	bit flag_bit=0;
			flag_bit=1;
			while(flag_bit)
			{		
					delay_500mS(2);
					current_data_temp=ad_sampling(AD3);//温度电机电流
					position_data_temp=ad_sampling(AD8);//温度电机位置反馈电压
					time_counter++;
					if((position_data_temp>max_open_wendu_moter_position)|(position_data_temp<max_close_wendu_moter_position))//(current_data_temp<motor_100mA)&
					{
						flag_bit=0;
						time_counter=0x00;
						success=1;//cheng gong le
					}
					else if(time_counter>10)
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//shi bai le
					}
					else if(curent_bit)
					{
					if(current_data_temp>motor_100mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}	
					}
					else if(current_data_temp>motor_150mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}
					
			}	
		}break;
		case test_xinfeng_motor_channel:
		{	
			static	bit flag_bit=0;
			flag_bit=1;
			while(flag_bit)
			{		
					delay_500mS(1);
					current_data_temp=ad_sampling(AD2);//新风电机电流
					position_data_temp=ad_sampling(AD7);//新风电机位置反馈电压
					time_counter++;
					if((position_data_temp>max_open_xinfeng_moter_position)|(position_data_temp<max_close_xinfeng_moter_position))//(current_data_temp<motor_100mA)&
					{
						flag_bit=0;
						time_counter=0x00;
						success=1;//cheng gong le
					}
					else if(time_counter>10)
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//shi bai le
					}
					else if(curent_bit)
					{
					if(current_data_temp>motor_100mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}	
					}
					else if(current_data_temp>motor_150mA)//motor_100mA==180
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//guo liu le
					}
			}	
		}break;
		case test_main_fan_motor_channel://this portion need modify in future
		{	
			static	bit flag_bit=0;
			flag_bit=1;
			while(flag_bit)
			{		
					delay_500mS(1);
					current_data_temp=ad_sampling(AD0);//主风扇电流
					position_data_temp=ad_sampling(AD5);//主风扇反馈电压 
					if(blo_step_counter==0x00)
					{
						if((position_data_temp>500)&(position_data_temp<600))//val are 573
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					else if(blo_step_counter==0x01)
					{
						if((position_data_temp>390)&(position_data_temp<500))//val are 432
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					else if(blo_step_counter==0x02)
					{
						if((position_data_temp>250)&(position_data_temp<400))////val are 302
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					else if(blo_step_counter==0x03)
					{
						if((position_data_temp>100)&(position_data_temp<200))//val are 194
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					else if(blo_step_counter==0x04)
					{
						if((position_data_temp>70)&(position_data_temp<180))//val are 102
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					else if(blo_step_counter==0x05)
					{
						if((position_data_temp>50)&(position_data_temp<160))//val are 102
						{
							flag_bit=0;
							time_counter=0x00;
							success=1;//cheng gong le
						}
					}
					time_counter++;
					if(time_counter>10)
					{
						flag_bit=0;
						time_counter=0x00;
						success=0;//shi bai le
					}
						if(current_data_temp>motor_30A)//motor_100mA==180
					{
						led[1]|=main_fan_motor_current_over_led_at1;
						flag_bit=0;
						time_counter=0x00;
						main_motor_relay=0;//turn OFF power of main fan
						success=0;//guo liu le
					}
			}	
		}break;
		default:break;
	}

	return success;
}
//(position_data_temp<max_close_mode_moter_position)|(position_data_temp>max_open_mode_moter_position)
//*****************************
//Auto_test_function
//*****************************
void auto_test_process(void)
{
	unsigned int time_counter_mode_motor=0x00,time_counter_wendu_motor=0x00,time_counter_xinfeng_motor=0x00,time_counter_main_fan_motor=0x00;
	unsigned char step_wendu=0x00,step_xinfeng=0x00,step_main_fan=0x00,step_mode=0x00,error_counter=0x00;
	static bit lock_bit=0,mode_motor_bit=0,xinfeng_motor_bit=0,main_fan_motor_bit=0,wendu_motor_bit=0,wendu_senser_bit=0,zhengfa_senser_bit=0;
	static bit mode_motor_testing_bit=0,xinfeng_motor_testing_bit=0,main_fan_motor_testing_bit=0,wendu_motor_testing_bit=0;
	lock_bit=1;
	led[0]=0;
	led[1]=0;
	led[2]=0;
	led[3]=0;
	led[1]|=main_fan_motor_current_sound_led_at1;
		//-------------------wendu senser section
		if((wendu_senser_bit==0)|(zhengfa_senser_bit==0))
		{
			unsigned data_temp;
			data_temp=ad_sampling(AD9);//温度传感器
			if((data_temp>100)&(data_temp<250))
			{
				wendu_senser_bit=1;
				led[1]|=main_fan_motor_wendu_sense_led_at1;
			}
			else
			{
				led[1]&=~main_fan_motor_wendu_sense_led_at1;
				error_counter++;
			}
			data_temp=ad_sampling(AD10);//蒸发器温度传感器
			if((data_temp>100)&(data_temp<250))
			{
				zhengfa_senser_bit=1;

⌨️ 快捷键说明

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