标题:
esp826601在while死循环中经常断掉,求指导
[打印本页]
作者:
zhczlzhang
时间:
2018-7-30 14:50
标题:
esp826601在while死循环中经常断掉,求指导
我买了ESP 8266 01做控制用,但是在主循环里面我用了while死循环,结果诡异的是在判断完SendDataFlage等于1,执行完这个If判段语句后,他的while死循环就执行不下去了,就在这里断掉了,最离谱的是我做的串口判断函数,在接收到666666601,1,之后执行完蜂鸣器响之后,也不执行向下语句了,我在memset函数那里做了蜂鸣器响的功能,结果却发现语句完全没有执行到这里。我最后单独运行串口中断接受函数或SendDataFlage函数,while循环语句就很顺畅的执行了,实在找不到那里出错了,求大家指点
#include <reg52.h>
#include <string.h>
#include <stdio.h>
#include <intrins.h>
#include <math.h>
#include <stdarg.h>
#include "usart.h"
#include "wifi.h"
sbit BUZZ = P2^3; //蜂鸣器控制引脚
sbit Pow = P1^0;
sbit Pow1 = P0^0;
unsigned char SendDataFlage = 0;
unsigned char i,d;
char Recive_table[20]=""; //接收缓冲,最大20个字节
//unsigned char data Recive_table[20];
char Recive_state = 0; //接收完成标志
int main (void)
{
/********************功能初始化***********************/
Uart_Init();//串口初始化,波特率为9600
Pow = 1;
ms_delay(1000) ;
ms_delay(1000) ;
//BUZZ=0;
ms_delay(1000) ;
ms_delay(1000) ;
ms_delay(1000) ;
//BUZZ=1;
ES = 0;
TI = 1;
// printf("AT+CIPSTART=\"TCP\",\"192.168.1.2\",8080\r\n");
BUZZ=0;
ms_delay(1000) ;
// printf("AT+CIPSTART=\"TCP\",\"192.168.1.2\",8080\r\n");
//BUZZ=1;
ms_delay(1000) ;
// printf("AT+CIPSTART=\"TCP\",\"192.168.1.2\",8080\r\n");
//BUZZ=0;
ms_delay(1000) ;
ms_delay(1000) ;
ms_delay(1000) ;
// printf("AT+CIPSTART=\"TCP\",\"192.168.1.2\",8080\r\n");
BUZZ=1;
ms_delay(1000) ;
ms_delay(1000) ;
ms_delay(1000) ;
printf("AT+CIPSTART=\"TCP\",\"192.168.1.2\",8080\r\n");
//BUZZ=0;
ms_delay(1000) ;
printf("AT+CIPSEND=12\r\n");
ms_delay(1000) ;
//BUZZ=1;
printf("666666601,ok\r\n");
//BUZZ=0;
while(!TI);
TI = 0;
Recive_state = 0;
//EA = 1;
ES = 1;
ms_delay(1000) ;
ms_delay(1000) ;
BUZZ=1;
SendDataFlage=1;
BUZZ=0;
ms_delay(1000) ;
BUZZ=1;
start1:
while(1)
{
ms_delay(100) ;
if(SendDataFlage==1)
{
SendDataFlage=0;
ES = 0;
TI = 1;
printf("AT+CIPSEND=12\r\n");
BUZZ=0;
ms_delay(1000) ;
printf("666666601,ok\r\n");
while(!TI);
TI = 0;
Recive_state = 0;
ES = 1;
PS = 1;
BUZZ=1;
ms_delay(1000) ;
ms_delay(1000) ;
}
if(Recive_state == 1)
{
if(strstr(Recive_table,"666666601,1"))
{
ES=0;
TI=1;
printf("AT+CIPSEND=15\r\n");
ms_delay(1000) ;
printf("%c\n666666601,on\r\n");
BUZZ =0;
Pow = 0;
Pow1 = 0;
for(d=0;d<=5;d++)
{
for(i=0;i<=30;i++)
{
ms_delay(1000) ;
}
}
Pow = 1;
Pow1 = 1;
printf("AT+CIPSEND=16\r\n");
ms_delay(1000) ;
printf("%c\n666666601,off\r\n");
//while(!TI)
TI=0;
Recive_state = 0;
ES=1;
SendDataFlage=1;
BUZZ =1;
goto start1;
}
else if(strstr(Recive_table,"666666601,ok"))
{
ES=0;
TI=1;
BUZZ =0;
ms_delay(1000) ;
BUZZ =1;
while(!TI)
TI=0;
Recive_state = 0;
ES=1;
SendDataFlage=1;
goto start1;
}
RI = 0;
ES = 0;
TI=0;
Recive_state = 0;
ES = 1;
SendDataFlage=1;
goto start1;
}
BUZZ=0;
memset(Recive_table,'\0',20);
//memset(Recive_table,0,20*sizeof(char));
Recive_state = 0;
TI=0;
ES=1; //打开接收标志位
PS = 1;
SendDataFlage=1;
ms_delay(1000) ;
BUZZ = 1;
goto start1;
}
}
/****************************************************/
/******************************************************************
函 数: void Uart_Interrupt() interrupt 4
功 能: 串口中断函数,将收到的字符存到Recive_table[]数组中
参 数: 无
返回值: 无
*******************************************************************/
void Uart_Interrupt() interrupt 4
{
static char i=0; //因为是一位一位接收,所以用static
if(RI==1)
{
ES = 0;
RI=0;
Recive_table[i]=SBUF;
i++;
if((Recive_table[i-1] == '\n'))
{
Recive_table[i]='\0';
i=0;
Recive_state = 1;
}
ES = 1;
}
if(TI)
{
TI = 0;
ES = 1;
}
}
复制代码
作者:
diy1997
时间:
2018-7-31 18:52
Non-OS里不能用while(1).
作者:
zhangzhoulzl
时间:
2018-7-31 19:29
好像没见过
作者:
多德
时间:
2018-8-1 11:27
不知道是不是你在uart中断里面,把TI = 0;了,然后你还继续使用printf();函数,你试试将
if(TI)
{
TI = 0;
ES = 1;
}
这几行注释掉看看。
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1