float LOW_VS[5] = { 0, 160.00, 160.00, 150.00, 150.00};
float LOW_VX[5] = { 0, 1170.00, 1160.00, 1160.00, 1130.00 };
int Rel = 1;//当前挡位
void Huandang(void) {
int wave_j;//换挡后的档位
int j = Rel;
for (j; j < 5; j = wave_j) {
MS5614_Output(2, 0x0140);//电压3.3V
ADC_Get_Average(3, 1000);//ADC采集
//给最低电压,并输出最低电压的R1_Vout
if (R1_Vout == 60) {
} //R1_Vout=0时
else {
if (R1_Vout < LOW_VS[j]) {
HAL_Delay(100);
jidianqi(0, j);
if (j == 6) {
jidianqi(1, j);
} else {
HAL_Delay(10);
jidianqi(1, j + 1);
wave_j = j + 1;
}
} else if (R1_Vout > LOW_VX[j]) {
HAL_Delay(100);
jidianqi(0, j);
if (j == 1) {
jidianqi(1, j);
} else {
HAL_Delay(10);
jidianqi(1, j - 1);
wave_j = j - 1;
}
} else {
HAL_Delay(10);
Rel = j;
OLED_Clear();
Menu_key_set();//菜单
// 记录当前的j值,在第几档
break;
}
}
}
}
void jidianqi(int status, int relayNumber) {
switch (relayNumber) {
case 1:
if (status==1) {
RELAYS1_ON();
R=1000;//挡位对应的电阻
} else {
RELAYS1_OFF();
}
break;
case 2:
if (status==1) {
RELAYS2_ON();
R=10000;
} else {
RELAYS2_OFF();
}
break;
case 3:
if (status==1) {
RELAYS3_ON();
R=100000;
} else {
RELAYS3_OFF();
}
break;
case 4:
if (status==1) {
RELAYS4_ON();
R=1000000;
} else {
RELAYS4_OFF();
}
break;
default:
// 处理未知的继电器编号
break;
}
}
换挡根据标定的电压值,若电压值取中间的数的会来回波动,两个继电器来回跳动,所以取阈值时要注意