- 注册时间
- 2008-2-22
- 最后登录
- 1970-1-1
- 阅读权限
- 50
- 金币
- 元
- 记录
- 相册
- 性别
- 保密
|
发表于 2009-6-13 14:33:35
|
显示全部楼层
本帖最后由 Alex_rcpilot 于 2009-6-13 14:35 编辑
复制一下会死啊~
我复制了你的,她复制了我的~!
哇咔咔,中国是山寨大国!
barry9146 发表于 2009-6-13 13:28
爱抄是吧,给你一堆代码,抄去吧。:y26:
//*******************************************************
//Function Name: void Tmp_routine( void )
//Description: Temprature sample process
//Parameter: none
//Return: none
//Subroutines called: none
//Called from: main_timerC( void ) @ local
//*******************************************************
//Thresholds:
#define THD_ADC_1 ((UINT) 594 ) //Multi-segment curve >594
#define THD_ADC_2 ((UINT) 361 ) //Multi-segment curve 361~593
#define THD_ADC_3 ((UINT) 214 ) //Multi-segment curve 214~360
#define THD_ADC_4 ((UINT) 170 ) //Multi-segment curve 170~213
#define THD_ADC_5 ((UINT) 126 ) //Multi-segment curve 126~169
//Temperature coefficient:
#define TPC_COT_1 ((float) 0.0947 )
#define TPC_COT_2 ((float) 0.08584 )
#define TPC_COT_3 ((float) 0.13605 )
#define TPC_COT_4 ((float) 0.17045 )
#define TPC_COT_5 ((float) 0.2273 )
//Temperature offset:
#define TPC_OFS_1 ((float) 71.25 )
#define TPC_OFS_2 ((float) 65.987 )
#define TPC_OFS_3 ((float) 84.116 )
#define TPC_OFS_4 ((float) 91.477 )
#define TPC_OFS_5 ((float) 101.136 )
//Software offset
#define TOF_SW ( -1.5 ) //Original calculation + software offset = final system parameter 1.5
#define SW_LIMIT ( 40.5 ) //Software top temperature limitation
void Tmp_routine( void )
{
float Tp_Calc; //Temperature calculation variable
UINT Tp_calc_buf; //Temperature calculation buffer
if( 1 == Sys.Flag.Tmp_update )
{
if( 0 == IRR2.BIT.IRRAD ) //No ADC completion
{
if( 0 == AD.ADSR.BIT.ADSF ) //ADC hasn't been started either
{
RTEN = 0; //Pull down resistor ladder
RTEN_DIR = 1; //Pull down port output
if( 0 == Sys.Cnt.Temp_Stabilize )
{
Sys.Cnt.Temp_Stabilize = 2; //Start delay
}
else if( 1 == Sys.Cnt.Temp_Stabilize )
{
AD.ADSR.BIT.ADSF = 1; //Set flag to start AD conversion
}
}
else
{
; //AD conversion in process, do nothing
}
}
else //Multi-segment curvature correction
{
AD_result = ( AD.ADRRL >> 6 ) + ( AD.ADRRH << 2 ); //ADC result in reg. is LEFT justified, regulate 10-bit result
//Multi-segment curvature correction (float point calculation output)
if( AD_result >= THD_ADC_1 )
{
Tp_Calc = TPC_OFS_1 - ( TPC_COT_1 * AD_result );
}
else if( AD_result >= THD_ADC_2 )
{
Tp_Calc = TPC_OFS_2 - ( TPC_COT_2 * AD_result );
}
else if( AD_result >= THD_ADC_3 )
{
Tp_Calc = TPC_OFS_3 - ( TPC_COT_3 * AD_result );
}
else if( AD_result >= THD_ADC_4 )
{
Tp_Calc = TPC_OFS_4 - ( TPC_COT_4 * AD_result );
}
else if( AD_result >= THD_ADC_4 )
{
Tp_Calc = TPC_OFS_5 - ( TPC_COT_5 * AD_result );
}
else
{
;//Over temperature error handle
}
Tp_Calc += TOF_SW; //OFFSET Software tunning
//Calculate raw temperature data both in Celsius and Fahrenheit scales
if( Tp_Calc > 0 )
{
if( Tp_Calc > SW_LIMIT )
{
Tp_Calc = SW_LIMIT; //Confine display temperature within software limitation
}
Sys.Para.Temp_Measure_C = (UINT)(Tp_Calc * 4); //Magnify to allow for 0.25 degree precision
Sys.Para.Temp_Measure_F = (UINT)((Tp_Calc * 1.8 + 32) * 4);//Calculate Fahrenheit temperature
}
else
{
;//Negative temperature error handle
}
//Calibrate both raw values with the SAME T-factor from profile
if( 0x08 == ( Profile.Para.T_Factor & 0x08 ) ) //Negative calibration
{
//Fahrenheit Calibration:
Sys.Para.Temp_Calib_F = Sys.Para.Temp_Measure_F - ( ( Profile.Para.T_Factor & 0x07 ) * 4 ); //Subtraction
//Celsius Calibration:
if( Sys.Para.Temp_Measure_C >= ( ( Profile.Para.T_Factor & 0x07 ) * 4 ) ) //Prevent negative result
{
Sys.Para.Temp_Calib_C = Sys.Para.Temp_Measure_C - ( ( Profile.Para.T_Factor & 0x07 ) * 4 ); //Subtraction
}
else
{
Sys.Para.Temp_Calib_C = 0; //Minimum value limitation
}
}
else
{
//Fahrenheit Calibration:
Sys.Para.Temp_Calib_F = Sys.Para.Temp_Measure_F + ( ( Profile.Para.T_Factor & 0x07 ) * 4 ); //Calibrate positive Fahrenheit temperature
//Celsius Calibration:
Sys.Para.Temp_Calib_C = Sys.Para.Temp_Measure_C + ( ( Profile.Para.T_Factor & 0x07 ) * 4 ); //Calibrate positive Celsius temperature
}
IRR2.BIT.IRRAD = 0; //Clear ADC interrupt flag
Sys.Flag.Tmp_update = 0; //Clear initiation flag
Sys.Flag.Ctrl_update = 1; //Update control output
Sys.Cnt.Relay_stage = RLY_ASSERT; //Command main loop to assert relay coil
Sys.Flag.Disp_update = 1; //Update display
RTEN_DIR = 0; //Pull down port input
}
}
else
{
; //ADC operation not initiated, skip
}
} |
|