欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
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.raoushi.com/bbs/)
Powered by Discuz! X3.1