|
请大家指正
uint8_t en_tnSRHCharge = 0;
uint8_t cnt_charge = 0;
uint16_t tn_discharge = 0;//s
uint32_t tn_charge = 0;
uint16_t tn_srhwait = 0;
float res_hr;
uint32_t time_high = 0;
uint32_t time_test = 0;
//uint32_t com_res = 0;
uint32_t tn_refcharge = 0;
uint32_t tn_hrcharge = 0;
void Humidity_tntest(void)
{
//放电
Set_SRH_Charge(0);
Set_SRH_R_Charge(0);
Set_SRH_IOtest(0);//output
GPIO_ResetBits(SRH_Charge);//
GPIO_ResetBits(SRH_R_Charge);//
Set_SRH_IOtest(0);//output
GPIO_ResetBits(SRH_IOtest);
tn_discharge = 40;//延时10ms
while(tn_discharge);
//标准电阻充电
Set_SRH_Charge(1);
Set_SRH_R_Charge(0);
Set_SRH_IOtest(1);//比较器口
en_tnSRHCharge = 1; //使能PWM,充电
GPIO_SetBits(SRH_R_Charge);
cnt_charge = 0;
time_high = 0;
tn_charge = 0;
TIM_SetCounter(TIM1,0);
while( !COMP_GetOutputLevel(COMP_Selection_COMP1));
tn_charge = TIM_GetCounter(TIM1);
en_tnSRHCharge = 0;
tn_refcharge = tn_charge;
tn_charge = 0;
//放电
Set_SRH_Charge(0);
Set_SRH_R_Charge(0);
Set_SRH_IOtest(0);//output
GPIO_ResetBits(SRH_Charge);//
GPIO_ResetBits(SRH_R_Charge);//
Set_SRH_IOtest(0);//output
GPIO_ResetBits(SRH_IOtest);
tn_discharge = 40;//延时10ms
while(tn_discharge);
//hr202l充电
Set_SRH_Charge(0);
Set_SRH_R_Charge(1);
Set_SRH_IOtest(1);//比较器口
en_tnSRHCharge = 1; //使能PWM,充电
GPIO_SetBits(SRH_Charge);
cnt_charge = 0x80;
time_high = 0;
tn_charge = 0;
TIM_SetCounter(TIM1,0);
while( !COMP_GetOutputLevel(COMP_Selection_COMP1)) ;
tn_charge = TIM_GetCounter(TIM1);
en_tnSRHCharge = 0;
tn_hrcharge = tn_charge;
tn_charge = 0;
//计算电阻,10K电阻
res_hr = 10 * 1000 * (float)tn_hrcharge / tn_refcharge;
if(res_hr>99000)
res_hr = 0.803*res_hr+5.298 ;
res2humidity(res_hr);
}
void TIM2_IRQHandler(void)
{
if(TIM_GetFlagStatus(TIM2, TIM_IT_Update))
{
TIM_ClearFlag(TIM2, TIM_IT_Update);
if(en_tnSRHCharge)
{
cnt_charge++;
if(cnt_charge & 0x80)
{
if(cnt_charge >= 0x86) //0x84
{
GPIO_ResetBits(SRH_Charge);
cnt_charge = 0x80;
}
else if(cnt_charge >= 0x81)
{
GPIO_SetBits(SRH_Charge);
}
}
else
{
if(cnt_charge == 0x01)
{
GPIO_SetBits(SRH_R_Charge);
}
else if(cnt_charge == 0x06) //4
{
GPIO_ResetBits(SRH_R_Charge);
cnt_charge = 0x00;
}
}
if(tn_discharge)tn_discharge--;
}
}
|
|