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

📄 070707.c

📁 单片机类程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	lcd_data_ok=1;//set the "lcd_data_ok" flag
	}
}

//get the accumulate of the sample value
void accumulate(void)
{
WDTC();
rc_times=0;
r_min_p=0;
r_max_p=5;
r_min_t=rc_temp[0];
r_max_t=rc_temp[5];	
do
	{//get the maxium and the minium value of the 6 sample time
	if(rc_temp[rc_times+1]<=r_min_t)
		{
		r_min_t=rc_temp[rc_times+1];
		r_min_p=rc_times+1;
		}
	if(rc_temp[4-rc_times]>=r_max_t)
		{
		r_max_t=rc_temp[4-rc_times];
		r_max_p=4-rc_times;
		}
	rc_times++;
	}	while(rc_times<5);
rc_times=0;
if(sensor==1)
	{//save the accumulate to sensor register
	rc_accumulate_sensor=0;
	do
		{//get the accumulate of the sensor sample value
		if((rc_times!=r_min_p)&&(rc_times!=r_max_p))
			{
			rc_accumulate_sensor=rc_accumulate_sensor+rc_temp[rc_times];
			}
		rc_times++;
		}	while(rc_times<6);
	rc_accumulate_sensor>>=2;//get the average value of the sample value
	}
else
	{//save the accumulate of the standard sample value
	rc_accumulate_stand=0;
	do
		{//get the accumulate of the sensor sample value
		if((rc_times!=r_min_p)&&(rc_times!=r_max_p))
			{
			rc_accumulate_stand=rc_accumulate_stand+rc_temp[rc_times];
			}
		rc_times++;
		}	while(rc_times<6);
	rc_accumulate_stand>>=2;//get the average value of the sample value	
	}
}	

//division manage,get the NUM1,NUM2,NUM3
void division(void)
{
WDTC();
if(heat_begin==0)//"heat_begin==0" 
	{//manage the set temprature
	difference=set_f;
	NUM4=0x84;
	}
else 
	{//"heat_begin==1"
	if((display_set_actual==1)||(key_same==1))//set the temprature during the heating
		{//manage the set temprature
		difference=set_f;
		NUM4=0x84;
		}
	else
		{//manage the actual temprature
		difference=actual_f;
		NUM4=0x0C;
		}
	}
NUM1=char_seg[difference/100];
NUM2=char_seg[(difference%100)/10];
NUM3=char_seg[(difference%100)%10];
}

//use the RC result to check the temprature table
void check_temp_table(void)
{
WDTC();
rc_data_manage();
if(sensor_value>=21000)
	{
	check_table_value=25;
	}
if(sensor_value<=381)
	{
	check_table_value=220;
	}
else if(sensor_value>=temp_table_1[19])
	{//temprature in the temp_table_1
	for(temp=0;temp<20;temp++)
		{
		if(sensor_value>=temp_table_1[temp])
			{
			check_table_value=20+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_2[0])&&(sensor_value>=temp_table_2[29]))
	{//temprature in the temp_table_2
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_2[temp])
			{
			check_table_value=40+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_3[0])&&(sensor_value>=temp_table_3[29]))
	{//temprature in the temp_table_3
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_3[temp])
			{
			check_table_value=70+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_4[0])&&(sensor_value>=temp_table_4[29]))
	{//temprature in the temp_table_3
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_4[temp])
			{
			check_table_value=100+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_5[0])&&(sensor_value>=temp_table_5[29]))
	{//temprature in the temp_table_3
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_5[temp])
			{
			check_table_value=130+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_6[0])&&(sensor_value>=temp_table_6[29]))
	{//temprature in the temp_table_3
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_6[temp])
			{
			check_table_value=160+temp;
			break;
			}
		}
	}
else if((sensor_value<=temp_table_7[0])&&(sensor_value>=temp_table_7[29]))
	{//temprature in the temp_table_7
	for(temp=0;temp<30;temp++)
		{
		if(sensor_value>=temp_table_7[temp])
			{
			check_table_value=190+temp;
			break;
			}
		}
	}
}

//key detect
void key_detect()
{
uchar temp6;
WDTC();
temp6=(P7&0x06);
if(temp6==0x06)
	{
	if(heat_key==1)
		{//"heat key" be pressed is valid
		if(heat_begin==1)
			{
			heat_begin=0;//clear "heat_begin" flag
			P7_5=0;//turn off the heater
			P7_3=0;
			P7_4=0;//turn off led
			heat_key=0;//clear the "heat_key" flag
			}
		else 
			{
			heat_begin=1;//set "heat_begin" flag
			P7_5=1;//turn on the heater
			heat_key=0;//clear the "heat_key" flag
			}
		stop_time=0;//initial the "stop_time" count register
		heat_time=0;//initial the "heat_time" count register
		display_time=0;//clear the "alternative display time" register			
		}
	else
		{//no key be pressed
		key_valid=0;//clear the "key_valid" flag
		key_same=0;
		key_time=0;
		key1_time=0;
		heat_key=0;
		}		
	}
else if(temp6==0)
	{
	if(heat_key==0)
		{//"heat key" be pressed,then to judge it is valid or not
		key_time++;	
		if(key_time==4)//	modify this place to change the key pressed time	
			{//have judged the pressed time is arrive 
			key_time=0;//initial register		
			heat_key=1;//set "heat key" be pressed flag
			}
		}
	else if(heat_key==1)
		{//the heat key be judged valid but the key not be pop
		key_time=0;
		}
	}
else 
	{//(temp6!=0x06)&&(temp6!=0x00),then equal to (temp6==0x04)||(temp6==0x02),"temp+/-" key be pressed
	if(key_valid==1)
		{//the "key_valid" flag is "1"
		if(heat_key==1)
			{
			key_same=0;
			}
		if(key_same==1)
			{//the "key_same" flag is "1"
			add_dec();
			}
		else 
			{//the "key_same" flag is "0"
			if(P7_2==0)
				{
				key_value=1;
				}
			else
				{
				key_value=2;
				}
			if(key_value_last==key_value)
				{
				key1_time++;	
				if(key1_time==50)
					{
					key1_time=0;//initial register
					key_same=1;//set the "key_same" flag
					add_dec();
					}
				}
			}
		}
	else
		{//the "key_valid" flag is "0",and +/-temp be pressed
		if(heat_key==0)
			{
			key_time++;	
			if(key_time==8)
				{//have judged the key is valid 
				key_time=0;//initial register
				add_dec();
				}		
			}
		}
	}
}

//key +/- management
void add_dec(void)
{
//the key is valid
WDTC();
if(P7_2==0)
	{//"temp+"
	set_f++;
	if(set_f>=400)
		{
		set_f=400;
		}
	key_value_last=1;
	}
else if(P7_1==0)
	{//"temp-"
	set_f--;
	if(set_f<=140)
		{
		set_f=140;
		}
	key_value_last=2;
	}
key_valid=1;//set "key_valid" flag
}

//rc_data manage
void rc_data_manage(void)
{
WDTC();
rc_accumulate_sensor=rc_accumulate_sensor*220;
rc_accumulate_sensor=rc_accumulate_sensor/rc_accumulate_stand;
sensor_value=rc_accumulate_sensor;
}

//Interrupt PROTECT 
void _intcall INTERRUPT_l(void) @ 0x01:low_int 0
{
  //backup ACC,R3,R4
_asm 
   {
     MOV %a_temp,A //save A to "a_temp(0x0F)"
     SWAPA 0x04 //save RSR to "r4_temp(0x2A)"
     BS 0x04,6
     BS 0x04,7
     MOV %r4_temp,A
     SWAPA 0x03 //save STATUS to "status_temp(0x0E)"
     MOV %status_temp,A 
   }  	
}

//Interrupt SERVIVE
void _intcall INTTERRUPT(void) @ int 0
{
//********************************************************
// Write your code (inline assembly or C) here
_asm
	{
		WDTC
		JBC 0x3F,0		//judge the TCCINT flag
		JMP TCC_INT
		JBS 0x3F,3		//judge the EXINT flag
		JMP INT_EXIT	//No INT interrupt and Exit
	EX_INT:
		BC 0x3F,3		//clear the EXINT flag
		MOV A,0x01		//save the TCC value to "tcc_present_value(0x0C)"
		MOV %tcc_present_value,A
		BC %flag2,3		//clear the "sample_error" flag
		MOV A,@0x06
		IOW 0x07
		BC 0x07,6		//discharge the C1 when the EXINT interrupt is most important
		BC 0x07,7		//
		BC 0x07,0		//release the charge of the C1
		BS %flag2,1		//set the "one_time_charge" flag
		BC %flag2,5		//clear the "rc_charging_now" flag
		CLRA
		IOW 0x0F		//disable all interrupt
		JMP INT_EXIT	
	TCC_INT:
		BC 0x3F,0		//clear the TCCINT flag		
		MOV A,@0x37
		MOV 0x01,A		//reset the initial value of TCC(0x01)
		INC %tcc_time_1 //increase the "tcc_time_1(0x26)"
		JBS 0x03,2		//judge the ZF flag
		JMP INT_EXIT
	SAMPLE_ERROR:
		JBS %flag2,3	
		JMP TCC_2
		BC %flag2,3
		BS %flag2,6		//set the "temprature_very_low" flag 
		BS %flag2,1		//set the "one_time_charge" flag
		BC %flag2,5		//clear the "rc_charging_now" flag
		MOV A,@0XFF
		MOV %tcc_time_1,A
		MOV A,@0x01
		MOV %tcc_time_2,A
/////////////////////////////////////////////
		MOV A,@0x06
		IOW 0x07
		BC 0x07,6		//discharge the C1 when the EXINT interrupt is most important
		BC 0x07,7		//
		BC 0x07,0		//release the charge of the C1
/////////////////////////////////////////////		
		CLRA
		IOW 0x0F		//disable all interrupt
		BC 0x07,0		//release the charge of the C1
		JMP INT_EXIT
	TCC_2:
		BS %flag2,3
		MOV A,@0x01
		MOV %tcc_time_2,A		
	INT_EXIT:  			//restore ACC,R3,R4
	    BS 0x4,6
     	BS 0x4,7
    	SWAPA %status_temp	//0x0E		
     	MOV 0x03,A		//restore the STATUS from the "status_temp(0x0E)"
		SWAPA %r4_temp	//	
    	MOV 0x04,A		//restore the RSR from the "r4_temp(0x2A)"
		SWAP %a_temp	//	
    	SWAPA %a_temp	//restore the A from the "a_temp(0x0F)"	
	}
}

⌨️ 快捷键说明

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