本帖最后由 liude2006 于 2016-4-12 16:38 编辑
uint zheyang_time = 15; //2.5分钟
uint Flag_zheyang = 0;
void control_right_left()
{
if(Flag_zheyang_time >= zheyang_time && zheyang_zheng == 1)
{
Flag_zheyang_time = 0;
zheyang_zheng = 0;
RELAY_P2_0 = RELAY_OFF;
RELAY_P2_2 = RELAY_OFF;
}
if(Flag_zheyang_time >= zheyang_time && zheyang_fan == 1)
{
Flag_zheyang_time = 0;
zheyang_fan = 0;
RELAY_P2_1 = RELAY_OFF;
RELAY_P2_3 = RELAY_OFF;
}
}
void main(void)
{
Relay_Init(); //继电器初始化
Serial_Init(); //串口初始化
Delay(1000);
Receive_Flag = 0;
Flag_Rece_Uartbuf = 0;
F_Packet_Clear(&sPacket_Receive);
while(1)
{
if(Flag_Rece_Uartbuf == 1) //数据包接收完全正确 执行相应动作
{
case 0x30: RELAY_P2_0 = RELAY_ON; //P2_1 P2_3 电机正转开始
RELAY_P2_2 = RELAY_ON;
zheyang_zheng = 1;
Flag_zheyang_time = 0;
Flag_zheyang = 0;
break;
case 0x31: RELAY_P2_0 = RELAY_OFF; //P2_1 P2_3 正转停止
RELAY_P2_2 = RELAY_OFF;
break;
case 0x40: RELAY_P2_1 = RELAY_ON; //P2_2 P2_4 电机反转开始
RELAY_P2_3 = RELAY_ON;
zheyang_fan = 1;
Flag_zheyang_time = 0;
Flag_zheyang = 0;
break;
case 0x41: RELAY_P2_1 = RELAY_OFF; //P2_2 P2_4反转停止
RELAY_P2_3 = RELAY_OFF;
break;
default: break;
}
}
control_right_left();
}
//串口接收中断函数
void ver()interrupt 4
{
RI = 0;
Receive_Value = SBUF;
ParseData();//判断接收到的数据
}
void timer0() interrupt 1
{
TH0 = (65535-5000)/256; //定时5ms
TL0 = (65535-5000)%256;
Flag_zheyang++;
if(Flag_zheyang == 2000) // Flag_zheyang == 2000 定时10S,
{
Flag_zheyang = 0;
Flag_zheyang_time++;
}
}
此程序是控制电机正反转的,现在的问题是明明定时的是2.5分钟,,结果电机只动作了二十几秒就停止了,请高手看看问题出在哪里了?急急急 用的是52单片机,11.0592的晶振
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>