请大哥们帮看看,我做的是蓝牙温控风扇,下面代码是一个蓝牙串口通信,发送0x05相当于是个自动模式的指令,但是这个自动模式不能实时实现功能,当温度、设置的最大值Thigh和最小值TLow发生改变时要重新发送指令才能实现发生变化,如果自动模式这个代码不放在串口通信里面放到main主函数里面又会产生冲突。问一下代码要怎么修改或者提供下思路,谢谢!!!
void UART_Routine() interrupt 4 {
if (RI) {
RI = 0;
x = SBUF;
switch (x) {
case 0x01: Compare = 0, Speed=0; break;
case 0x02: Compare = 50, Speed=1; break;
case 0x03: Compare = 75, Speed=2; break;
case 0x04: Compare = 100, Speed=3; break;
case 0x05: if (T > THigh) {
Compare = 100;
Speed = 3;
}
else if (T <= THigh && T >= (THigh + TLow) / 2) {
Compare = 75;
Speed = 2;
}
else if (T <= (THigh + TLow) / 2 && T > TLow) {
Compare = 50;
Speed = 1;
}
else {
Compare = 0;
Speed = 0;
}
break;
}
}
}
|